-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fibonacci.java
50 lines (38 loc) · 928 Bytes
/
Fibonacci.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
/**
*Se calculeaza al n termen fibonacci %9973
*Termenul este in prealabil setat prin proces.set(X)
*Valoarea calculata este pastrata in value
*/
public class Fibonacci extends Proces {
public Fibonacci(int weight, String type) {
super(weight, type);
}
@Override
public void compute() {
int a = 0;
int b = 1;
int aux;
if (this.x < 0) {
this.value = -1;
return;
}
if (this.x == 0) {
this.value = a;
return;
}
if (this.x == 1) {
this.value = b;
return;
}
for(int i = 2; i <= this.x; i++ ) {
aux = b;
b += a;
a = aux;
if( a > 9973) {
a = a % 9973;
}
}
this.value = b % 9973;
return;
}
}