-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfib.java
More file actions
31 lines (31 loc) · 713 Bytes
/
fib.java
File metadata and controls
31 lines (31 loc) · 713 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
26
27
28
29
30
31
//I'm changing something, wooooo!
public class fib{
private static int fib(int x){
if(x < 2){
return x;
}else{
int qianVal = 0;
int zuoVal = 1;
int res = 0;
for(int i = 1; i < x; i++){
res = qianVal+zuoVal;
qianVal = zuoVal;
zuoVal = res;
}
return res;
}
}
private static int doWork(int rem){
int acc = 0;
for(int i = 0; i < rem; i++){
acc += fib((acc+1)%50);
}
return acc;
}
public static void main(String[] args){
long start = System.currentTimeMillis();
System.out.printf("%d\n", doWork(Integer.parseInt(args[0])));
long duration = System.currentTimeMillis() - start;
System.out.println("LANGUAGE Java "+ duration);
}
}