forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP25.cpp
More file actions
53 lines (53 loc) · 1.05 KB
/
Copy pathP25.cpp
File metadata and controls
53 lines (53 loc) · 1.05 KB
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
#include<iostream>
#include<fstream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#define MAXN 1000000
#define LL long long
#define eps 1e-6
#define inf 0x3f3f3f3f
using namespace std;
int add(int *small,int *large)
{
int carryin = 0, temp, i;
for(i=1;large[i]!=-1||carryin!=0;i++)
{
if(-1 == small[i])
small[i] = 0;
if(-1 == large[i])
large[i] = 0;
temp = small[i] + large[i] + carryin;
small[i] = temp % 10;
carryin = temp / 10;
}
return i-1;
}
int main()
{
int a[1010],b[1010];
memset(a,-1,sizeof(a));
memset(b,-1,sizeof(b));
a[1]=b[1] = 1;
int i,top = 1,term = 2;
for(i=1;top<1000;i++)
{
if(i%2)
top = add(a,b);
else top = add(b,a);
term++;
}
printf("%d\n",term);
return 0;
}