Advertisement
Dmaxiya

类斐波那契循环数 参考代码

Mar 31st, 2025
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 100 + 100;
  6. LL sum[maxn];
  7.  
  8. bool judge(LL x) {
  9.     int n = 0;
  10.     LL tmp = x;
  11.     while (tmp != 0) {
  12.         sum[n++] = tmp % 10;
  13.         tmp /= 10;
  14.     }
  15.     sum[n] = 0;
  16.     reverse(sum, sum + n + 1);
  17.     for (int i = 1; i <= n; ++i) {
  18.         sum[i] += sum[i - 1];
  19.     }
  20.     for (int i = n + 1; i <= 50; ++i) {
  21.         tmp = sum[i - 1] - sum[i - n - 1];
  22.         if (tmp == x) {
  23.             return true;
  24.         }
  25.         sum[i] = tmp + sum[i - 1];
  26.     }
  27.     return false;
  28. }
  29.  
  30. int main() {
  31. #ifdef ExRoc
  32.     freopen("test.txt", "r", stdin);
  33. #endif // ExRoc
  34.     ios::sync_with_stdio(false);
  35.  
  36.     for (int i = 1; i <= 10000000; ++i) {
  37.         if (judge(i)) {
  38.             cout << i << endl;
  39.         }
  40.     }
  41.     cout << 7913837 << endl;
  42.  
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement