fork download
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6.  
  7. #define ll long long
  8. const long long mod = 1e9+7;
  9.  
  10. using namespace std;
  11.  
  12. bool fibo1(ll n) {
  13. if(n == 0 || n == 1) {
  14. return true;
  15. }
  16. ll fn1=1, fn2=0;
  17. for(int i=2; i<=92; i++) {
  18. ll fn = fn1 + fn2;
  19. if(fn == n) {
  20. return true;
  21. }
  22. fn2 = fn1;
  23. fn1 = fn;
  24. }
  25. return false;
  26. }
  27.  
  28. bool fibo2(ll n) {
  29. ll f[100];
  30. f[0] = 0;
  31. f[1] = 1;
  32. for(int i=2; i<=92; i++) {
  33. f[i] = f[i-1] + f[i-2];
  34. }
  35. for(int i=2; i<=92; i++) {
  36. if(f[i] == n) {
  37. return true;
  38. }
  39. }
  40. return false;
  41. }
  42. int main(){
  43. int n; cin >> n;
  44. if(fibo2(n)) {
  45. cout << "YES" << endl;
  46. }
  47. else {
  48. cout << "NO" << endl;
  49. }
  50. }
Success #stdin #stdout 0s 5304KB
stdin
5
stdout
YES