-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfib.cs
More file actions
32 lines (31 loc) · 753 Bytes
/
fib.cs
File metadata and controls
32 lines (31 loc) · 753 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
32
using System;
public class fib{
private static int calcFib(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 += calcFib((acc+1)%50);
}
return acc;
}
public static void Main(string[] args){
long start= DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
System.Console.WriteLine(doWork(Convert.ToInt32(args[0])));
long duration = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - start;
System.Console.WriteLine("LANGUAGE C# "+ duration);
}
}