-
Notifications
You must be signed in to change notification settings - Fork 0
/
n-digit-fibonacci-number.cpp
55 lines (51 loc) · 1.07 KB
/
n-digit-fibonacci-number.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
52
53
54
//https://www.hackerrank.com/contests/projecteuler/challenges/euler025/problem
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
vector < int > x(5001 , 0);
vector < int > y(5001 , 0);
vector < int > z(5001 , 0);
x[0] = 1;
y[0] = 1;
int m2 = 1;
vector < int > ans(5001);
ans[1] = 1;
int count = 2;
while( m2 < 5000)
{
int temp = 0;
for(int i = 0; i < m2 ; i++)
{
int x1 = x[i] + y[i] + temp;
z[i] = x1 % 10;
temp = x1 / 10;
}
int f = 1;
while(temp > 0)
{
f = 0;
z[m2] = temp % 10;
temp /=10;
m2 ++;
}
count ++;
if(!f)
{
ans[m2] = count;
}
x = y;
y = z;
}
//cout << ans[1000] << endl;
ll t;
cin >> t;
while( t-- )
{
ll n;
cin >> n;
cout << ans[n] << endl;
}
return 0;
}