Bi-shoe and Phi-shoe
解题思路:
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int unprime[1000200];
void is_prime(){
memset(unprime,0,sizeof(unprime));
unprime[1] = 1;
for(int i = 2; i <= 1000100; i++){//注意临界值
int tt = 1000100/i;
for(int j = 2; j <= tt; j++){
unprime[i*j] = 1;
}
}
}
int main(){
is_prime();
int T,t = 1;
scanf("%d",&T);
while(T--){
int n,x;
scanf("%d",&n);
ll ans = 0;
for(int i = 0; i < n; i++){
scanf("%d",&x);
for(int j = x+1; ; j++){
if(!unprime[j]){
ans += j;
break;
}
}
}
printf("Case %d: %lld Xukha\n",t++,ans);
}
return 0;
}
本文介绍了一种解决Bi-shoeandPhi-shoe问题的算法,通过使用预处理技巧和数学方法,有效地提高了求解效率。具体包括算法实现、复杂度分析和实际应用案例。
196

被折叠的 条评论
为什么被折叠?



