fork download
  1. #include <stdio.h>
  2. #include <vector>
  3. #include <map>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. #define long long long
  9. const long M = 1000000007; // modulo
  10.  
  11. map<long, long> F;
  12. vector<long> T[1234];
  13.  
  14. long f(long n, int Depth) {
  15. T[Depth].push_back(n);
  16. if (F.count(n)) return F[n];
  17. long k=n/2;
  18. if (n%2==0) { // n=2*k
  19. return F[n] = (f(k, Depth+1)*f(k, Depth+1) + f(k-1, Depth+1)*f(k-1, Depth+1)) % M;
  20. } else { // n=2*k+1
  21. return F[n] = (f(k, Depth+1)*f(k+1, Depth+1) + f(k-1, Depth+1)*f(k, Depth+1)) % M;
  22. }
  23. }
  24.  
  25. main(){
  26. long n;
  27. F[0]=F[1]=1;
  28. if (cin >> n) {
  29. if (n==0)
  30. cout << 0 << endl;
  31. else
  32. cout << f(n-1, 0) << endl;
  33. }
  34.  
  35. }
Success #stdin #stdout 0s 3476KB
stdin
300
stdout
644264086