fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main()
  5. {
  6. unsigned long long n = 0, m = 0;
  7. std::cin >> n >> m;
  8. std::vector<unsigned long> mod;
  9. mod.push_back(0);
  10. mod.push_back(1);
  11. unsigned long k = 0;
  12. for (unsigned long i = 2; i <= n; ++i)
  13. {
  14. ++k;
  15. mod.push_back((mod[i - 1] + mod[i - 2]) % m);
  16. if (mod[i - 1] == 0 && mod[i] == 1)
  17. break;
  18. }
  19. std::cout << mod[(n%k)] << std::endl;
  20. return 0;
  21. }
Success #stdin #stdout 0s 3460KB
stdin
7279414000335723 50694
stdout
23462