fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. int consistency(int n){
  31. int x = n;
  32. unordered_map<int,int> mp;
  33.  
  34. while(n%2 == 0){
  35. mp[2]++;
  36. n /= 2;
  37. }
  38.  
  39. for(int i=3; i*i<=n; i+=2){
  40. while(n%i==0){
  41. mp[i]++;
  42. n /= i;
  43. }
  44. }
  45.  
  46. if(n>2){
  47. mp[n]++;
  48. }
  49.  
  50. int ans = 1;
  51. for(auto& it : mp){
  52. int p = it.first;
  53. int e = it.second;
  54.  
  55. int nmr = power(p, e+1, M) - 1;
  56. int dnr = (p-1+M)%M;
  57.  
  58. dnr = power(dnr, M-2);
  59.  
  60. int val = ( nmr * dnr ) % M;
  61.  
  62. ans = (ans * val)%M;
  63.  
  64. }
  65.  
  66. ans -= x;
  67.  
  68. return ans;
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. int practice(int n){
  82.  
  83.  
  84. return 0;
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91. void solve() {
  92.  
  93. int n;
  94. cin>> n;
  95.  
  96. cout << consistency(n) << endl;
  97.  
  98.  
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105. int32_t main() {
  106. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  107.  
  108. int t = 1;
  109. cin >> t;
  110. while (t--) {
  111. solve();
  112. }
  113.  
  114. return 0;
  115. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
2
10
20
stdout
1
8
22