-2

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.

  • Use a big number arithmetic library? – datenwolf Nov 04 '13 at 17:03
  • 1
    Read 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
  • 1
    Many, 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 Answers1

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...

Community
  • 1
  • 1
Jimbo
  • 4,352
  • 3
  • 27
  • 44