fork download
  1. /* Wasiful Haque */
  2. #pragma GCC optimize("O3,unroll-loops")
  3.  
  4. #include<bits/stdc++.h>
  5. #include<ext/pb_ds/assoc_container.hpp>
  6. #include<ext/pb_ds/tree_policy.hpp>
  7.  
  8. using namespace std;
  9. using namespace chrono;
  10. using namespace __gnu_pbds;
  11.  
  12. #define fastIO() ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  13. #define MOD 1000000007
  14. #define INF 1e18
  15. #define PI 3.141592653589793238462
  16. #define nl '\n'
  17. #define pb push_back
  18. #define ppb pop_back
  19. #define forI(i, s, n) for(int i=s; i<n; i++)
  20. #define forI_R(i, n, s) for(int i=n; i>=s; i--)
  21. #define inputArr(n, arr) for(int i=0; i<n; i++){cin >> arr[i];}
  22. #define forI_list(it, l) for(auto it=l.begin(); it != l.end(); it++)
  23. #define vi vector<int>
  24. #define vll vector<long long>
  25. #define vvi vector<vector<int>>
  26. #define vvll vector<vector<long long>>
  27. #define u_mii unordered_map<int,int>
  28. #define mii map<int,int>
  29. #define mic map<int,char>
  30. #define msi map<string,int>
  31. #define pii pair<int,int>
  32. #define pq_max priority_queue<int>
  33. #define pq_min priority_queue<int, vector<int>, greater<int>>
  34. #define yes cout << "YES\n"
  35. #define no cout << "NO\n"
  36.  
  37.  
  38. typedef long long ll;
  39. typedef unsigned long long ull;
  40. typedef long double lld;
  41. typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
  42.  
  43.  
  44. /* Error Debugging (Start) */
  45.  
  46. #ifndef ONLINE_JUDGE
  47. #define debug(x) cerr << #x << " "; _print(x); cerr << endl;
  48. #else
  49. #define debug(x)
  50. #endif
  51.  
  52. void _print(long long x) {cerr << x;}
  53. void _print(int x) {cerr << x;}
  54. void _print(string x) {cerr << x;}
  55. void _print(char x) {cerr << x;}
  56. void _print(long double x) {cerr << x;}
  57. void _print(double x) {cerr << x;}
  58. void _print(unsigned long long x) {cerr << x;}
  59.  
  60.  
  61. template <class T, class V> void _print(pair <T, V> x);
  62. template <class T> void _print(vector <T> x);
  63. template <class T> void _print(set <T> x);
  64. template <class T> void _print(multiset <T> x);
  65. template <class T, class V> void _print(map <T, V> x);
  66.  
  67. template<class T, class V> void _print(pair<T, V> x){cerr << "{"; _print(x.first); cerr << ","; _print(x.second); cerr << "}";}
  68. template<class T> void _print(vector<T> x){cerr << "[ "; for(auto i : x) {_print(i); cerr << " ";} cerr << "]";}
  69. template<class T> void _print(set<T> x){cerr << "[ "; for(auto i : x) {_print(i); cerr << " ";} cerr << "]";}
  70. template<class T> void _print(multiset<T> x){cerr << "[ "; for(auto i : x) {_print(i); cerr << " ";} cerr << "]";}
  71. template<class T, class V> void _print(map<T, V> x){cerr << "[ "; for(auto i : x) {_print(i); cerr << " ";} cerr << "]";}
  72.  
  73. /* Error Debugging (End) */
  74.  
  75.  
  76.  
  77. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  78.  
  79.  
  80.  
  81. /* Algorithms (Start) */
  82.  
  83. const int N = 1000000;
  84. vll primes;
  85. vector<bool> is_prime(N + 1, true);
  86.  
  87. void sieve() {
  88. is_prime[0] = is_prime[1] = false;
  89.  
  90. for (ll i = 2; i <= N; i++) {
  91. if (is_prime[i]) {
  92. primes.push_back(i);
  93.  
  94. if (i * i <= N) {
  95. for (ll j = i * i; j <= N; j += i) {
  96. is_prime[j] = false;
  97. }
  98. }
  99. }
  100. }
  101. }
  102.  
  103.  
  104. /* Algorithms (End) */
  105.  
  106.  
  107.  
  108. /* Code (Start) */
  109.  
  110.  
  111. void solve(){
  112. ll n; cin >> n;
  113.  
  114. if(n == 0) {
  115. cout << 0 << endl;
  116. return;
  117. }
  118.  
  119. map<ll, ll> freq;
  120. freq[1]++;
  121.  
  122. if(n != 2){
  123. forI(i, 2, sqrt(n)+1){
  124. int x = n;
  125. while(x > 0){
  126. if( (x % i) == 0){
  127. freq[i]++;
  128. freq[x/i]++;
  129.  
  130. x/=i;
  131. }
  132. else break;
  133. }
  134. }
  135. }
  136.  
  137.  
  138. ll ans=0;
  139. for(auto &val : freq){
  140. ans += val.first;
  141. }
  142.  
  143. cout << ans << endl;
  144.  
  145.  
  146.  
  147. }
  148.  
  149.  
  150. int main(){
  151. #ifndef ONLINE_JUDGE
  152. freopen("error.txt", "w", stderr);
  153. // freopen("input.txt", "r", stdin);
  154. // freopen("output.txt", "w", stdout);
  155. #endif
  156.  
  157. fastIO();
  158. auto start1 = high_resolution_clock::now();
  159.  
  160. int t; cin >> t;
  161. while(t--){
  162. solve();
  163. }
  164.  
  165. auto stop1 = high_resolution_clock::now();
  166. auto duration = duration_cast<milliseconds>(stop1 - start1);
  167.  
  168. #ifndef ONLINE_JUDGE
  169. cerr << "Time: " << duration.count() << " ms" << endl;
  170. #endif
  171.  
  172. return 0;
  173. }
Success #stdin #stdout 0.01s 5320KB
stdin
1
100
stdout
117