fork download
  1. /// *** --- ||| In the name of ALLAH ||| --- *** ///
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  7. #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
  8. #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  9.  
  10. #define endl '\n'
  11. #define ll long long
  12. #define int long long
  13. #define all(a) (a).begin(),(a).end()
  14. #define rall(a) (a).rbegin(),(a).rend()
  15. #define sz(x) (int)x.size()
  16. #define mem(a,b) memset(a, b, sizeof(a) )
  17. #define sq(a) ((a) * (a))
  18.  
  19. const double PI = acos(-1);
  20. const double eps = 1e-9;
  21. const int inf = 2000000000;
  22. const int MX = 2e5+123;
  23. const ll infLL = 9000000000000000000;
  24. const int MOD = 1e9+7;
  25.  
  26. int a, b, m;
  27. pair<int, int> fib (int n) {
  28. if (n == a)
  29. return {a, b};
  30.  
  31. auto p = fib(n >> 1);
  32. int c = p.first * (2 * p.second - p.first);
  33. int d = p.first * p.first + p.second * p.second;
  34. if (n & 1)
  35. return {d, c + d};
  36. else
  37. return {c, d};
  38. }
  39.  
  40. void solve (int testCase)
  41. {
  42. cout << "Case " << testCase << ": ";
  43. int n;
  44. cin >> a >> b >> n >> m;
  45.  
  46. auto ans = fib (n);
  47. string mod = "1";
  48. for (int i = 0; i < m; i++) mod += '0';
  49.  
  50. m = stoi (mod);
  51. cout << ans.first % m << endl;
  52. }
  53.  
  54.  
  55. int32_t main()
  56. {
  57. fastio();
  58. // srand(time(NULL));
  59.  
  60. int testcases = 1;
  61. cin >> testcases;
  62. for (int tt = 1; tt <= testcases; tt++)
  63. {
  64. solve (tt);
  65. }
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Case 1: 0