So Fast Solution

How can i solve this problem with time < 1s?? My result is 1.8 s. Could anybody answer me??

Re: So Fast Solution

The same question. I got AC in 1.7 sec, how to make it faster?

*Edited by author 01.07.2008 18:46*

Re: So Fast Solution

You should minimize the number of mod operations. for example when I use mod each iteration i got 0.9 sec. But when I minimized the number of mod operations I got 0.56 sec. You should use long f(java) and calculate (f mod p) when f > 10^14, but not each time you calculate your f.