-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP266.java
43 lines (36 loc) · 1.32 KB
/
P266.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.LinkedList;
import java.math.BigInteger;
public class P266 {
public static void main(String[] args) {
StdOut.println("Enter N: "); //enter 190
int N = StdIn.readInt();
int[] primes = new int[N];
for (int i = 2; i < N; i++) {
primes[i-2]=i;
}
for (int i = 2; i < N; i++) {
for (int j = 0; j < N; j++) {
if (primes[j] % i == 0 && primes[j] != i) primes[j] = 0;
}
}
BigInteger product = new BigInteger("1");
for (int i = 0; i < N; i++) {
BigInteger j = new BigInteger(Integer.toString(primes[i]));
if (primes[i] != 0) product = product.multiply(j);
}
BigInteger psr = new BigInteger(product.toString());
while (psr.pow(2).compareTo(product) == 1) {
psr = psr.divide(new BigInteger("2"));
}
while (psr.pow(2).compareTo(product) == -1) {
psr = psr.add(new BigInteger("1"));
}
while (true) {
if (product.mod(psr).intValue() == 0) {
break;
}
psr = psr.subtract(new BigInteger("1"));
}
StdOut.println(psr.mod(new BigInteger("10000000000000000")));
}
}