Advertisement
a53

tombola

a53
May 3rd, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define MOD 1000000000000000031LL
  4.  
  5. using namespace std;
  6.  
  7. long long calc (long long val)
  8. {
  9. long long sum = 0LL;
  10. while (val > 0LL)
  11. {
  12. sum += val;
  13. val /= 10LL;
  14. }
  15.  
  16. return sum;
  17. }
  18.  
  19. int main ()
  20. {
  21. ifstream cin ("tombola.in");
  22. ofstream cout ("tombola.out");
  23.  
  24. int n, cer;
  25. long long x, a, b, c, d;
  26. cin >> cer >> n >> x >> a >> b >> c >> d;
  27.  
  28. long long rez = 0LL;
  29. for (int i = 1; i <= n; ++i)
  30. {
  31. if (i > 1) x = (x % a * b + c) % d;
  32.  
  33. long long cx = x - 1LL, nr = 0LL;
  34. if (cer == 2) cx = x;
  35.  
  36. while (cx > 0LL)
  37. {
  38. nr = nr * 10LL + 1LL;
  39. cx /= 10LL;
  40. }
  41.  
  42. cx = x - 1LL;
  43. if (cer == 2) cx = x;
  44.  
  45. bool OK = false;
  46. long long sol = 0LL;
  47.  
  48. while (nr > 0LL)
  49. {
  50. long long c = cx / nr;
  51.  
  52. if (OK) c = 9LL;
  53. if (c > 9LL) c = 9LL, OK = true;
  54. sol = sol * 10LL + c;
  55. if (c > 0LL) cx -= c * nr;
  56.  
  57. nr /= 10LL;
  58. }
  59.  
  60. if (cer == 1) rez += calc (sol);
  61. else rez += x - sol;
  62.  
  63. rez %= MOD;
  64. }
  65.  
  66. cout << rez << '\n';
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement