Hi guys , I want to know how to solve this type of problem. Suppose my result is going out of bound of integer and double then how to change my answer to Answer % 100000007. Ex  (factorial(500)) % 1000000007 Most of the programming contest has this type of problem but I don't know the concept :( Please help. asked 19 Nov '14, 15:07

Preface: All such solution are based on few simple rules:
With negative numbers there is a problem  http://ideone.com/LmWJva according to wikipedia this is 3, not 2, so before doing minus operation it is recommended to add n (which is removed after mod operation),
What most of contestants are confused about is:
and while c is lower than MOD and a nad b are ints, it seems ok to use ints, but it is not... Overflow occurs for Example  http://ideone.com/OUBGvs notice the result is negative. There are few tricks how to overcome this
Disadvantage of 1.) is, that you have to identify all places where you need to apply this. And also you one have to know very well what is he doing  see http://ideone.com/IuyPDt It may seem like there is problem with multiply only and addition is ok, there is a catch also:
the above is fine for a,b <= 10^{9} which it typical in problem statements... But there is a problem if one tries to do
You may be interested also in this answer. Few problems I searched quickly: Note: see the 1000_000, this is valid 10^{6} in Java >= 7 and I love it, for more examples see SO, it is also possible to write binary numbers as answered 19 Nov '14, 15:15
Thanks @betlista but i am talking about (factorial(100)) % 100000007 where the result can't be store even in double.
(19 Nov '14, 15:24)
while factorial
(19 Nov '14, 15:26)
are u trying to say that 7%7 ==2%7 +5%7 I mean in some place if there is addition or other type of expression like power operator than can we apply this technique please help..
(19 Nov '14, 15:32)
Yes, power is the very the same as factorial
(19 Nov '14, 15:38)
Thanks @betlista . One more thing what about (n!/m!)%c =? and n and m >100
(20 Nov '14, 10:20)
this is more difficult, if you are interested in combinations (n!/(r! * (nr)!), then there is excellent article about the topic, otherwise there is another article
(20 Nov '14, 12:27)
showing 5 of 6
show all

You can refer this blog by abhinav92003 on handling operators with mod. Also few concepts involving modular operations are well explained there. Also @betlista has made a point where many contestants tend make a mistake. answered 19 Nov '14, 15:25

Probably you meant 10^{9}+7...