nguyenthieukhang

11155 UVA

Sep 13th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <cstring>
  6. #include <queue>
  7. #include <assert.h>
  8. #include <cmath>
  9. #include <stack>
  10. #include <deque>
  11. #include <set>
  12. #include <unordered_map>
  13. #include <complex>
  14. #include <fstream>
  15. #include <map>
  16. #include <numeric>
  17. #include <functional>
  18. using namespace std;
  19. const int mxn = 10100;
  20. int X[mxn], table[mxn];
  21.  
  22. int main() {
  23.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  24.  
  25.     int tc; cin>>tc;
  26.     for(int cnt =1; cnt<=tc; cnt++) {
  27.         int A, B, C, M, N;
  28.         cin>>A>>B>>C>>M>>N;
  29.         X[0] = A; for(int i=1; i<N; i++) X[i] = (X[i-1]*B+C)%M+1;
  30.  
  31.         for(int i=0; i<M; i++) table[i] = 0;
  32.  
  33.         long long sum = 0, ans = 0;
  34.         for(int i=0; i<N; i++) {
  35.             sum+=X[i];
  36.             sum%=M; if(sum==0) ans++;
  37.             ans+=table[sum];
  38.             table[sum]++;
  39.         }
  40.  
  41.         cout <<"Case " << cnt << ": " <<ans << '\n';
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment