fork(1) download
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. long long a;
  6. int b;
  7. int d[3][3];
  8. int c[3][3];
  9. cin >> a >>b;
  10. d[1][1] = 1;
  11. d[1][2] = 1;
  12. d[2][1] = 1;
  13. d[2][2] = 0;
  14. c[1][1] = 1;
  15. c[2][1] = 0;
  16. for(int i = 0; i < a; i++)
  17. {
  18. int r = c[1][1];
  19. c[1][1] = d[1][1] * c[1][1] % b + d[1][2] * c[2][1] % b;
  20. c[2][1] = r;
  21.  
  22. }
  23. cout << c[2][1];
  24.  
  25. }
  26.  
Success #stdin #stdout 0s 3300KB
stdin
115 26673
stdout
34727