Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #define LENGTH 46 //46是關鍵,太大會爆掉
- // (n*n-m*n-m*m)*(n*n-m*n-m*m)=1 的整數解是費氏數列的連續項
- using namespace std;
- int main()
- {
- int F[LENGTH] = {1,1};
- for(int i=2; i<LENGTH; i++)
- {
- F[i] = F[i-2] + F[i-1];
- }
- int input;
- while(cin >> input)
- {
- for(int i=LENGTH-1; i>=0; i--)
- {
- if(F[i]<=input)
- {
- cout << F[i-1] << ' '<< F[i] << endl;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement