2

I know a bit of c++ and I have started taking part in some competitive programming contests. Many a times we are said to show the output modulo 109+7. However, I don't understand what's so special about this number. I have observed that this is used when the answer becomes large to handle. I want to know why this specific number only and not something else?

Edit: Sample question : https://www.codechef.com/FEB12/problems/WCOUNT

ANSWER : The number is a large prime number. Taking modulo takes care of the fact that the answer can be stored so that it stays within the limits of the size of the variable type

brainst
  • 291
  • 1
  • 4
  • 15
  • 1
    it's just an easy way to push the answer back into a reasonable length without too much collisions (well it should not be too easy to come to the right answer by happenstance ;) ) - btw: it's not the number it's the function that is interesting – Random Dev Feb 14 '16 at 09:12
  • @Carsten I haven't come across this number/function before. Looks interesting though. Can you share a link to an example where it is being used?... – TheCodeArtist Feb 14 '16 at 09:15
  • How is the `^` symbol used - literally for C++, or in its more common meaning? i.e. are they asking you to modulo by 10 XOR 16? if so, why the XOR? or are they wanting you to modulo by 10 to the power of 9 then add 7? If so, why the addition? Either way, can you cite an exact example of this request? – underscore_d Feb 14 '16 at 09:16
  • 1
    @underscore_d I meant the power function .. %pow(10,9)+7 – brainst Feb 14 '16 at 09:41
  • 1
    @brainst: Why are you putting a percent sign in front? It's not there in your linked example. – Cheers and hth. - Alf Feb 14 '16 at 09:52
  • @Cheersandhth.-Alf To denote modulo... Seems like it isn't used in all languages. Thanks for the Edit! – brainst Feb 14 '16 at 09:53
  • Duplicate indeed, but I learned an interesting fact from the original via it! – underscore_d Feb 14 '16 at 10:48

0 Answers0