氧气中毒
查看原帖
氧气中毒
778898
wangxiaowei0310楼主2023/4/19 21:15

不开o2tle 开o2re

#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

const int N = 50010;

int T;
ll n;
int cnt;
int primes[100];
bool st[N];

ll get(ll prod)
{
    if (prod >= n) return 0;
    int res = 0;
    for (int i = 1; i < 1 << cnt; i ++) 
    {
        int k = 0;
        ll x = 1;
        for (int j = 0; j < cnt; j ++)
        {
            if (i >> j & 1)
            {
                x *= primes[j];
                k ++;
            }
        }
        if (k & 1) res -= n / x - get(x * prod);
        else res += n / x - get(x * prod);
    }
    return res;
}

int main()
{
    for (int i = 2; i < N; i ++)
        if (!st[i])
        {
            primes[cnt ++] = i;
            for (int j = i + i; j < N; j += i) st[j] = true;   
        }

    cin >> T;
    while (T --)
    {
        cin >> n;
        cout << n - 1 - get(1) << endl;
    }

    return 0;
}
2023/4/19 21:15
加载中...