Advertisement
_ash__

Untitled

Aug 22nd, 2020
9,754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5.  
  6. const LL mod = 1000009;
  7.  
  8. LL brute(LL n) {
  9.     LL X = 0;
  10.     for(LL i = 1; i <= n; i++) {
  11.         X += i * (n/i) % mod;
  12.         X %= mod;
  13.     }
  14.     X -= (n-1);
  15.     X %= mod;
  16.     if(X < 0) X += mod;
  17.     LL sub = n*(n+1)/2;
  18.     sub %= mod;
  19.     X -= sub;
  20.     X %= mod;
  21.     if(X < 0) X += mod;
  22.  
  23.     if(X == 0) return 0;
  24.     LL res = 0;
  25.     for(LL i = 2; i * i <= X; i++) {
  26.         while(X % i == 0) {
  27.             X /= i;
  28.             res += i;
  29.             res %= mod;
  30.         }
  31.     }
  32.     if(X > 1) res += X;
  33.     res %= mod;
  34.     return res;
  35. }
  36.  
  37.  
  38. LL SUM(LL l, LL r) {
  39.     LL n = r-l+1, t = (l+r);
  40.     if(n%2 == 0) n /= 2;
  41.     else t /= 2;
  42.     return ((n%mod)*(t%mod))%mod;
  43. }
  44.  
  45. int main() {
  46. //    freopen("in.txt", "r", stdin);
  47.     ios::sync_with_stdio(0);
  48.     cin.tie(0);
  49.  
  50.     int tc = 1000;
  51. //    cin >> tc;
  52.     int caseno = 1;
  53.     while(tc--) {
  54.         LL n = 2000000000000;
  55. //        cin >> n;
  56.         if(n == 0) {
  57.             LL res = 0;
  58.             cout << "Case " << caseno++ << ": " << res << endl;
  59.         }
  60.         else {
  61.  
  62.             LL l, r;
  63.             LL X = 0;
  64.             for(LL i = 1; i <= n; i = r + 1) {
  65.                 l = i, r = n / (n / i);
  66.                 LL c = n/i-1;
  67.                 c %= mod;
  68.                 X += c*SUM(l, r)%mod;
  69.                 X %= mod;
  70.             }
  71.  
  72.             X -= (n-1)%mod;
  73.             X %= mod;
  74.             if(X < 0) X += mod;
  75.             LL res = 0;
  76. //            assert(X < mod && X >= 0);
  77.             if(X > 1) {
  78.                 assert(X < mod && X > 1);
  79.                 for(LL i = 2; i * i <= X; i++) {
  80.                     while(X % i == 0) {
  81.                         res += i;
  82.                         res %= mod;
  83.                         X /= i;
  84.                     }
  85.                 }
  86.                 if(X > 1) res += X;
  87.                 res %= mod;
  88.             }
  89.             assert(res >= 0);
  90. //            assert(brute(n) == res);
  91.             cout << "Case " << caseno++ << ": " << res << endl;
  92.         }
  93.     }
  94. }
  95.  
  96.  
  97.  
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement