Can anyone tell me how to find (2^101100111000)%1000000007 in C? There is a problem in which we have to convert a number into binary(1<=N<=600000) and find 2^(binary representation of N)modulo1000000007.
Asked
Active
Viewed 160 times
-2
-
Use a big number arithmetic library? – datenwolf Nov 04 '13 at 17:03
-
1Read http://en.wikipedia.org/wiki/Modular_exponentiation. Binary is merely a representation, so it doesn't affect anything. – Zong Nov 04 '13 at 17:06
-
1Many, many duplicates, e.g. [What is the fastest way to compute large power of 2 modulo a number](http://stackoverflow.com/questions/11289495/what-is-the-fastest-way-to-compute-large-power-of-2-modulo-a-number) – Paul R Nov 04 '13 at 17:06
1 Answers
1
The values you are talking about will not fit into a standard long on any architecture, so you will have to use an arbitrary precision maths library such as GMP.
Hmm, just read Zong's answer... he's pointing to a more efficient method... haven't finished reading through the article but it looks like the better way to go...
-
2No, this is the wrong approach. You don't need to actually calculate such large values. – Zong Nov 04 '13 at 17:07
-
1
-
1