-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
51 lines (50 loc) · 812 Bytes
/
Source.cpp
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
#include<iostream>
#define length 1000
using namespace std;
void walkThrow(int a[length], int b[length]);
void logArray(int a[]);
int main() {
int a[length], b[length], carry = 0;
for (int i = 0; i < length; i++) {
a[i] = 0;
b[i] = 0;
}
b [0] = 1;
int x = 1;
while (1) {
walkThrow(a, b);
x++;
if (a[length-1] > 0) {
logArray(a);
break;
}
walkThrow(b, a);
x++;
if (b[length-1] > 0) {
logArray(b);
break;
}
}
cout << "F" << x;
return 0;
}
void walkThrow(int a[length], int b[length]) {
int carry = 0;
for (int i = 0; i < length; i++) {
int val = a[i] + b[i] + carry;
if (val >= 10) {
carry = 1;
val -= 10;
}
else {
carry = 0;
}
a[i] = val;
}
}
void logArray(int a[]) {
for (int i = length-1; i >= 0; i--) {
cout << a[i];
}
cout << endl;
}