-
对于每个素数显然有其phi[N] = N - 1
-
不妨设两个素数p1,p2 p1≤p2 对于求所有[p1,p2)内的数有最小值p2
#include <bits/stdc++.h>
using namespace std;
const int MAXP=1e6 + 100;
typedef long long LL;
bool notprime[MAXP];
int phi[MAXP];
void Eratosthenes_Phi() {
notprime[1] = true;
for(int i = 1; i < MAXP; i++) phi[i] = 1;
for(int i = 2; i < MAXP; i++) {
if( !notprime[i] ) {
phi[i] *= i - 1;
// 和传统素数筛法的区别在于这个i+i
for(int j = i+i; j < MAXP; j += i) {
notprime[j] = true;
int n = j / i;
phi[j] *= (i - 1);
while(n % i == 0) n /= i, phi[j] *= i;
}
}
}
}int main() {
Eratosthenes_Phi();
int T;
scanf("%d",&T);
for (int cs = 1; cs <= T;cs++) {
int N;
scanf("%d",&N);
LL ans= 0;
for (int i = 1;i <= N;i++) {
int num;
scanf("%d",&num);
for (int j = num + 1;;j++) {
if (!notprime[j]) {
ans += j;
break;
}
}
}
printf(“Case %d: %lld Xukha\n”,cs,ans);
}
return 0;
}
08-13
08-13