forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP97.java
More file actions
25 lines (24 loc) · 687 Bytes
/
P97.java
File metadata and controls
25 lines (24 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.math.*;
public class P97
{
public static void main( String[] args )
{
long start = System.currentTimeMillis();
BigInteger a = new BigInteger("28433");
int n = 7830457;
BigInteger one = new BigInteger("1");
BigInteger x = new BigInteger("2");
BigInteger Module = new BigInteger("10000000000");
BigInteger res = one;
while(n != 0)
{
if(1 == (n & 1))
res = res.multiply(x).mod(Module);
x = x.multiply(x);
n >>= 1;
}
res = a.multiply(res).add(one).mod(Module);
System.out.println(res);
System.out.println("time cost: " + (System.currentTimeMillis() - start) + "ms");
}
}