-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprod.cpp
More file actions
35 lines (29 loc) · 744 Bytes
/
prod.cpp
File metadata and controls
35 lines (29 loc) · 744 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
33
34
35
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long; //TO HANDLE LARGE FIBBONACCI NUMBER
//WORKS WITH ONLY POSITIVE NUMBERS
class ProdFib{
public:
static vector <ull> productFib(ull prod)
{
ull a=0,b=1;//These will represent consecutive Fibonacci numbers F(n) and F(n+1)
//MAIN LOOP
while(a*b<prod)
{
ull next=a+b;
a=b;
b=next;
}
return{a,b,a*b==prod?1ULL:0ULL};
/*1ULL (true equivalent) if product matches exactly
0ULL (false equivalent) if product exceeds target*/
}
};
int main()
{
ull prod;
cin>>prod;
vector <ull> v=ProdFib::productFib(prod);
cout<<v[0]<<" "<<v[1]<<" "<<v[2];
return 0;
}