amboo的score值就是其长度x的欧拉函数值(即小于x且与x互质的数的个数),每单位长度花费1Xukha,求买这些bamboo的最小花费。
欧拉函数有一个性质:素数p的欧拉函数值为p-1;
我们要找长度最小的bamboo,只需将幸运数字加1开始找,如果该数字x是素数,那么这个数字x-1就是长度为x的score值,且满足条件,所求的x就是满足条件bamboo的长度
#include<map>
#include<set>
#include<list>
#include<stack>
#include<deque>
#include<queue>
#include<vector>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<math.h>
#include<ctype.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<functional>
#define CPY(A,B)memcpy(A,B,sizeof(A))
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
typedef long long LL;
typedef unsigned long long uLL;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fLL;
const double OO=1e20;
const double EPS=1e-9;
const double PI=acos (-1.0);
int dx[]= {0,1,0,-1};
int dy[]= {1,0,-1,0};
using namespace std;
int gcd (const LL &a,const LL &b) {
return b==0?a:gcd (b,a%b);
}
inline int dcmp (double a,double b) {
if (fabs (a-b) <EPS) { return 0; }
return a>b;
}
const int M=1e6+100;
double a[M];
void Init() {
for (int i=1; i<M; ++i) {
a[i]=i;
int mid=i;
for (int j=2; j*j<=mid; ++j) {
if (mid%j==0) {
a[i]*= (j-1);
while (mid%j==0) {
mid/=j;
}
a[i]/=j;
}
}
}
}
int main() {
int T,cas=0;
cin>>T;
Init();
while (T--) {
int n,x;
scanf ("%d",&n);
LL sum=0;
while (n--) {
scanf ("%d",&x);
int xx=x+1;
while (a[xx]<x) {
xx++;
}
sum+=xx;
}
printf("Case %d: %lld Xukha\n",++cas,sum);
}
return 0;
}