-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProb12.java
57 lines (47 loc) · 1.42 KB
/
Prob12.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gevaexs.PE;
import java.math.BigInteger;
/**
*
* @author Home
*/
public class Prob12 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BigInteger i = new BigInteger("1");
BigInteger count = new BigInteger("1");
for(; divNum(i) < 500; i = i.add(count)) {
count = count.add(new BigInteger("1"));
}
System.out.println("Num is:" + i);
}
// number of divisiors
public static int divNum(BigInteger num) {
int count = 0;
for(BigInteger i = new BigInteger("1"); i.compareTo(sqrtBig(num)) <= 0; i = i.add(new BigInteger("1"))) {
if(num.mod(i).equals(new BigInteger("0"))){
count++;
}
}
return 2 * count;
}
public static BigInteger sqrtBig(BigInteger n) {
BigInteger a = BigInteger.ONE;
BigInteger b = n.shiftRight(5).add(BigInteger.valueOf(8));
while (b.compareTo(a) >= 0) {
BigInteger mid = a.add(b).shiftRight(1);
if (mid.multiply(mid).compareTo(n) > 0) {
b = mid.subtract(BigInteger.ONE);
} else {
a = mid.add(BigInteger.ONE);
}
}
return a.subtract(BigInteger.ONE);
}
}