Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- int main()
- {
- ios_base::sync_with_stdio(NULL);
- cin.tie(0);
- cout.tie(0);
- int t;
- cin >> t;
- ll a,b,c,m,n;
- for(int ti = 1; ti <= t; ti++) {
- cin >> a >> b >> c >> m >> n;
- ll arr[10001],pre[10001];
- arr[0] = a%m;
- for(int i = 1; i < n; i++) {
- arr[i] = (((arr[i-1]*(b%m))%m + c%m)%m + 1)%m;
- }
- for(int i = 0; i < n; i++) {
- pre[i] = (arr[i] + (i > 0 ? pre[i-1]:0))%m;
- }
- ll ans = 0;
- map<ll,ll> mp;
- for(int i = n-1; i >= 0; i--) {
- mp[pre[i]]++;
- ll prv = (i > 0 ? pre[i-1]:0);
- ans += mp[prv];
- }
- cout << "Case " << ti << ": " << ans << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement