Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //
- #define ll long long
- #define ull unsigned long long
- #define mx 100010
- #define mod 1000000007
- #define endl '\n'
- #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- //
- vector<ll> primes, res(10000001), fact(10000001);
- vector<bool> isPrime(10000001, 1);
- void sieve(ll n) {
- for (ll i = 3; i * i <= n; i += 2) {
- if (isPrime[i]) {
- for (ll j = i * i; j <= n; j += i + i) {
- if (isPrime[j]) fact[j] = i;
- isPrime[j] = false;
- }
- }
- }
- }
- void calc() {
- res[0] = res[1] = 0;
- for (ll i = 2; i <= 10000000; i++) {
- ll fac = 2;
- if (i % 2) {
- if (isPrime[i]) fac = i;
- else fac = fact[i];
- }
- res[i] = res[i - 1] + fac;
- }
- }
- int main() {
- fastio;
- sieve(10000000);
- calc();
- ll t;
- cin >> t;
- while (t--) {
- ll n;
- cin >> n;
- cout << (ll)res[n] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement