标签:c代码 cst include const can pen oid phi open
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 1.1e6 + 10;
bool no_prime[maxn];
int prime[maxn], phi[maxn];
int shai(int n)
{
int cnt = 0;
no_prime[1] = 1;
for (int i = 2; i <= n; i++)
{
if (!no_prime[i])
prime[++cnt] = i, phi[i] = i - 1;
for (int j = 1; j <= cnt && prime[j] * i <= n; j++)
{
no_prime[prime[j] * i] = 1;
phi[prime[j] * i] = i % prime[j] == 0 ? phi[i] * prime[j] : phi[i] * (prime[j] - 1);
if (i % prime[j] == 0) break;
}
}
return cnt;
}
void solve()
{
shai(maxn - 10);
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++)
{
int n;
vector<int> a;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
int t;
scanf("%d", &t);
a.push_back(t);
}
sort(a.begin(), a.end());
int pt = 1;
long long ans = 0;
for (auto& it : a)
{
while (phi[pt] < it)
pt++;
ans += pt;
}
printf("Case %d: %lld Xukha\n", i, ans);
}
}
int main()
{
freopen("Testin.txt", "r", stdin);
solve();
return 0;
}
LightOJ1370 Bi-shoe and Phi-shoe 欧拉函数
标签:c代码 cst include const can pen oid phi open
原文地址:https://www.cnblogs.com/danzh/p/11412208.html