Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define MOD 1000000000000000031LL
- using namespace std;
- long long calc (long long val)
- {
- long long sum = 0LL;
- while (val > 0LL)
- {
- sum += val;
- val /= 10LL;
- }
- return sum;
- }
- int main ()
- {
- ifstream cin ("tombola.in");
- ofstream cout ("tombola.out");
- int n, cer;
- long long x, a, b, c, d;
- cin >> cer >> n >> x >> a >> b >> c >> d;
- long long rez = 0LL;
- for (int i = 1; i <= n; ++i)
- {
- if (i > 1) x = (x % a * b + c) % d;
- long long cx = x - 1LL, nr = 0LL;
- if (cer == 2) cx = x;
- while (cx > 0LL)
- {
- nr = nr * 10LL + 1LL;
- cx /= 10LL;
- }
- cx = x - 1LL;
- if (cer == 2) cx = x;
- bool OK = false;
- long long sol = 0LL;
- while (nr > 0LL)
- {
- long long c = cx / nr;
- if (OK) c = 9LL;
- if (c > 9LL) c = 9LL, OK = true;
- sol = sol * 10LL + c;
- if (c > 0LL) cx -= c * nr;
- nr /= 10LL;
- }
- if (cer == 1) rez += calc (sol);
- else rez += x - sol;
- rez %= MOD;
- }
- cout << rez << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement