Advertisement
willy108

CF 915 G WA

Feb 22nd, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cmath>
  7. #include <cassert>
  8. #include <algorithm>
  9. #include <vector>
  10.  
  11. #define max_v 2100000
  12. #define int_max 0x3f3f3f3f
  13. #define cont continue
  14. #define pow_2(n) (1 << (n))
  15. #define ll long long
  16. #define pii pair<int, int>
  17. #define pb push_back
  18. #define mp make_pair
  19. #define lsb(n) ((n)&(-(n)))
  20. #define LC(n) (((n) << 1) + 1)
  21. #define RC(n) (((n) << 1) + 2)
  22. #define add(a, b) (((a)%mod + (b)%mod)%mod)
  23. #define mul(a, b) (((a)%mod * (b)%mod)%mod)
  24. #define init(arr, val) memset(arr, val, sizeof(arr))
  25.  
  26. const ll mod = 1e9 + 7;
  27.  
  28. using namespace std;
  29.  
  30. void setIO(const string& file_name){
  31.     freopen((file_name+".in").c_str(), "r", stdin);
  32.     freopen((file_name+".out").c_str(), "w+", stdout);
  33. }
  34. int m[max_v], low[max_v], vis[max_v];
  35. ll freq[max_v], p[max_v], n, k, ans[max_v], contr[max_v];
  36. //this'll hurt my brain for sure
  37. //mew(1) is 1
  38. //mew(2) is -1
  39. //mew(3) is -1
  40. //mew(4) is 0
  41. //mew(5) is -1
  42. //mew(6) is 1
  43. //hopefully this'll work for my brick of a brain
  44.  
  45. ll bin_pow(ll a, ll b){
  46.   ll ans = 1ll;
  47.   for(int i = 0; pow_2(i) <= b; i++){
  48.     if(b&pow_2(i)){
  49.       ans = mul(ans, a);
  50.     }
  51.     a = mul(a, a);
  52.   }
  53.   return ans;
  54. }
  55.  
  56. int main(){
  57.     cin.tie(0) -> sync_with_stdio(0);
  58.   low[1] = mod; //1 -> 0 for a better progression
  59.   m[1] = 1;
  60.   //seive for primes, low[i] is the smallest prime that divides i
  61.   for(int i = 2; i<=2e6; i++){
  62.     if(vis[i]) cont;
  63.     for(int j = i; j<=2e6; j += i){
  64.       if(!vis[j]) low[j] = i;
  65.       vis[j] = 1;
  66.     }
  67.   }
  68.   //compute m, or mobius's function
  69.   for(int i = 2; i <=2e6; i++){
  70.     if(low[i] == i) m[i] = -1;
  71.     else if((i/low[i])%low[i] == 0) m[i] = 0;
  72.     else m[i] = m[i/low[i]] * -1;
  73.   }
  74.  
  75.   cin >> n >> k;
  76.   //compute each i^n
  77.   for(int i = 1; i<=k; i++){
  78.     p[i] = bin_pow(i, n);
  79.   }
  80.   ll tot = 0ll;
  81.  
  82.   for(int i = 1; i<=k; i++){
  83.     ans[i] = ans[i - 1]; //the current answer is similar to the prior one
  84.     for(int j = i; j; j /= low[j]){
  85.       ans[i] = add(ans[i], mod - contr[j]); //the only differences are the numbers
  86.       contr[j] = mul(mod + m[j], p[i/j]);   //that evenly divide i
  87.       ans[i] = add(ans[i], contr[j]);       //thats what this is for
  88.     }
  89.    
  90.     //cout << ans[i] << ' ' << (int)(ans[i]^(ll)i) << endl;
  91.     tot = add(tot, ans[i] ^ (ll)i);
  92.   }
  93.  
  94.   cout << tot << '\n'; //WHY IS IT WA. WHY WHY WHY
  95.   return 0;
  96. }
  97.  
  98.  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement