-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathp012.java
56 lines (44 loc) · 936 Bytes
/
p012.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
import java.util.*;
/**
*
* @author gouravrusiya
*
*/
public class p012 {
public static void main(String[] args) {
long startTime = System.currentTimeMillis();
int series = 0;
int s1 = 0;
int div = 0;
for(int i=1;;i++){
series = i;
s1=0;
while(series>0){
s1 += series;
series--;
}
div = divisors(s1);
if(div>500){
System.out.println(s1);
break;
}
}
long endTime = System.currentTimeMillis();
System.out.println("Time = "+(endTime-startTime)+" ms");
}
// Algo to find divisors of any number
static int divisors(int x) {
int limit = x;
int numberOfDivisors = 0;
for (int i = 1; i < limit; ++i) {
if (x % i == 0) {
limit = x / i;
if (limit != i) {
numberOfDivisors++;
}
numberOfDivisors++;
}
}
return numberOfDivisors;
}
}