Advertisement
fahad005

Untitled

Apr 17th, 2022
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //
  4. #define ll long long
  5. #define ull unsigned long long
  6. #define mx 100010
  7. #define mod 1000000007
  8. #define endl '\n'
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  10. //
  11. vector<ll> primes, res(10000001), fact(10000001);
  12. vector<bool> isPrime(10000001, 1);
  13.  
  14. void sieve(ll n) {
  15.     for (ll i = 3; i * i <= n; i += 2) {
  16.         if (isPrime[i]) {
  17.             for (ll j = i * i; j <= n; j += i + i) {
  18.                 if (isPrime[j]) fact[j] = i;
  19.                 isPrime[j] = false;
  20.             }
  21.         }
  22.     }
  23. }
  24. void calc() {
  25.     res[0] = res[1] = 0;
  26.     for (ll i = 2; i <= 10000000; i++) {
  27.         ll fac = 2;
  28.         if (i % 2) {
  29.             if (isPrime[i]) fac = i;
  30.             else fac = fact[i];
  31.         }
  32.         res[i] = res[i - 1] + fac;
  33.     }
  34. }
  35. int main() {
  36.     fastio;
  37.     sieve(10000000);
  38.     calc();
  39.  
  40.     ll t;
  41.     cin >> t;
  42.     while (t--) {
  43.         ll n;
  44.         cin >> n;
  45.         cout << (ll)res[n] << endl;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement