How to find the remainder of a large number of divisions in C ++?

I have a question regarding a module in C ++. What I was trying to do shared a very large number, say, for example, M% 2, where M = 54,302,495,302,423. However, when I turn to compilation, this suggests that the number is "long" for int. Then, when I switch it to double, it repeats the same error message. Is there a way I can do this in which I get the remainder of this very large number, or perhaps even a larger number? Thank you for your help, very grateful.

+3
source share
4 answers

For large arithmetic in C ++, use the GMP library . In particular, the function mpz_modwill do this.

++- mpz_class , .

+2

" " (64- ), , 32- , / , / 2 .

bignum

- , 2, . 255, ( char) . 65535, 16 ( ) .

+3
0

. . . ,

1 12233445566778899001122 => 11223344 55667788 99001122

. , .

:)

Edit:

112233445566778899001122/6 =>  11223344 55667788 99001122/6


 11223344/6 =>2

 2*100000000 + 55667788 = 255667788
 255667788/6 => 0
 0*100000000 + 99001122 = 99001122
 99001122/6=>0

 So the reminder is 0.

Remember that a separate block after manipulation should be under the maximum range that int can support.

0
source

Source: https://habr.com/ru/post/1736829/


All Articles