Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string.h>
- #include <algorithm>
- #include <cstring>
- #include <queue>
- #include <assert.h>
- #include <cmath>
- #include <stack>
- #include <deque>
- #include <set>
- #include <unordered_map>
- #include <complex>
- #include <fstream>
- #include <map>
- #include <numeric>
- #include <functional>
- using namespace std;
- const int mxn = 10100;
- int X[mxn], table[mxn];
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int tc; cin>>tc;
- for(int cnt =1; cnt<=tc; cnt++) {
- int A, B, C, M, N;
- cin>>A>>B>>C>>M>>N;
- X[0] = A; for(int i=1; i<N; i++) X[i] = (X[i-1]*B+C)%M+1;
- for(int i=0; i<M; i++) table[i] = 0;
- long long sum = 0, ans = 0;
- for(int i=0; i<N; i++) {
- sum+=X[i];
- sum%=M; if(sum==0) ans++;
- ans+=table[sum];
- table[sum]++;
- }
- cout <<"Case " << cnt << ": " <<ans << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment