fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long n;
  6. int mod;
  7.  
  8. int main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11. cout.tie(0);
  12.  
  13. freopen("LISFIBO.inp", "r", stdin);
  14. freopen("LISFIBO.out", "w", stdout);
  15.  
  16. cin >> n >> mod;
  17.  
  18. if (mod == 1) {
  19. if (n <= 3) {
  20. cout << min(n, 2LL);
  21. } else {
  22. cout << n - 2;
  23. }
  24. } else if (mod == 2) {
  25. cout << (n / 3) * 2 + (n % 3);
  26. } else {
  27. int siz = 8;
  28. int period[siz] = {1, 1, 2, 0, 2, 2, 1, 0};
  29. long long num = n / siz;
  30. int rem = n % siz;
  31. long long res = num * 3;
  32. if (num > 0 && rem <= 2) {
  33. res += 2;
  34. } else {
  35. for (int i = 0, cur = 1; i < rem; ++i) {
  36. res += cur <= period[i];
  37. cur = max(cur, period[i]);
  38. }
  39. }
  40. cout << res;
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty