pascal - How to calculate with a number this big? -


I am learning Pascal on my own for a month and I have come to a problem that I can not solve . Basically I have 2 numbers, N and m , where N is less than 10 100 000 and M is less than 10 8 and both are greater than 0. I need to calculate N mod M I

I do not understand how to do it, even Not even with QWord . I tried it with the string but I do not know very well it is always very complicated for me because I use the function function where I The final number is obtained from the string N and then subtracting M with the I two if function (where n The last digit of the last or the last digit of the same is m , and this is less). Basically this simple problem makes me feel very complicated for that. There are packages running around some bignum, for example the open source MPArith package included

With the Demo calculator, you can easily beat your time range:

  D: \ Xtools \ MPArith> T_calc.exe using T_CALC MPArith V1.26.05 (31/32 bit) [mp_calc] (c) W.Ehrhardt 2006-2013 Karatsuba cutoffs: mul / sqr = 16/32, Toom -3 cutoffs: mul / sqr = 32 / 64 Burnikel / Ziegler div cutoff = 32, MaxBit = 520,093,696, MaxFact = 22623931 type "? & Lt; enter & gt;" To get some information about the command, finish "q" or "finish" [d]: = & gt; 10 ^ 100000 Mod (10 ^ 8-1) Results = 1 [D]: = & gt; . Time = 20.128 ms [d]: = & gt; 10 ^ 100000; Result = [& gt; 0, 332,193 bits, chksum = $ CE01C341, time = 46.994 ms] but depending on your needs and examples, you can also  get  without your results  If you want to calculate  a ^ b mod n , then  do not count   a ^ b  and then  mod n Reduce . In a second step, but you lower each product in the loop and you should use fast binary exponent, e.g. In the description and pseudo-code, order 10 ^ 8 of module n you need to reduce one product of two 31/32 bit integers and therefore you need  int64  or so you have the products for the Pascal version (Which should not be a problem, for depositing in which  QWord  is). I think this kind of program will be very fast with the MPArithe Bignam code with 20 milliseconds. 


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -