Advertisement
_rashed

UVA 11155

Jul 26th, 2022
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(NULL);
  13.     cin.tie(0);
  14.     cout.tie(0);
  15.     int t;
  16.     cin >> t;
  17.     ll a,b,c,m,n;
  18.     for(int ti = 1; ti <= t; ti++) {
  19.         cin >> a >> b >> c >> m >> n;
  20.         ll arr[10001],pre[10001];
  21.         arr[0] = a%m;
  22.         for(int i = 1; i < n; i++) {
  23.             arr[i] = (((arr[i-1]*(b%m))%m + c%m)%m + 1)%m;
  24.         }
  25.         for(int i = 0; i < n; i++) {
  26.             pre[i] = (arr[i] + (i > 0 ? pre[i-1]:0))%m;
  27.         }
  28.         ll ans = 0;
  29.         map<ll,ll> mp;
  30.         for(int i = n-1; i >= 0; i--) {
  31.             mp[pre[i]]++;
  32.             ll prv = (i > 0 ? pre[i-1]:0);
  33.             ans += mp[prv];
  34.         }
  35.         cout << "Case " << ti << ": " << ans << "\n";
  36.  
  37.  
  38.     }
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement