题意
给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和。
Solution
线性筛出phi,把询问数组排序搞就行了
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e4 + 10), __(1e6 + 10);
IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}
int n, a[_], id[_], prime[__], isprime[__], num, phi[__];
ll ans;
IL void Prepare(){
for(RG int i = 2; i <= __; ++i){
if(!isprime[i]) prime[++num] = i, phi[i] = i - 1;
for(RG int j = 1; j <= num && i * prime[j] <= __; ++j){
isprime[i * prime[j]] = 1;
if(!(i % prime[j])){ phi[i * prime[j]] = phi[i] * prime[j]; break; }
else phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
}
}
int main(RG int argc, RG char *argv[]){
Prepare();
for(RG int T = Read(), i = 1; i <= T; ++i){
n = Read(); ans = 0;
for(RG int j = 1; j <= n; ++j) a[j] = Read();
sort(a + 1, a + n + 1);
for(RG int j = 1, l = 1; j <= n; ++j){
while(phi[l] < a[j]) ++l;
ans += l;
}
printf("Case %d: %lld Xukha\n", i, ans);
}
return 0;
}