Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular coach for his success. He needs some bamboos for his students, so he asked his assistant Bi-Shoe to go to the market and buy them. Plenty of Bamboos of all possible integer lengths (yes!) are available in the market. According to Xzhila tradition,
Score of a bamboo = Φ (bamboo's length)
(Xzhilans are really fond of number theory). For your information, Φ (n) = numbers less than n which are relatively prime (having no common divisor other than 1) to n. So, score of a bamboo of length 9 is 6 as 1, 2, 4, 5, 7, 8 are relatively prime to 9.
The assistant Bi-shoe has to buy one bamboo for each student. As a twist, each pole-vault student of Phi-shoe has a lucky number. Bi-shoe wants to buy bamboos such that each of them gets a bamboo with a score greater than or equal to his/her lucky number. Bi-shoe wants to minimize the total amount of money spent for buying the bamboos. One unit of bamboo costs 1 Xukha. Help him.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 10000) denoting the number of students of Phi-shoe. The next line contains n space separated integers denoting the lucky numbers for the students. Each lucky number will lie in the range [1, 106].
Output
For each case, print the case number and the minimum possible money spent for buying the bamboos. See the samples for details.
Sample Input
3
5
1 2 3 4 5
6
10 11 12 13 14 15
2
1 1
Sample Output
Case 1: 22 Xukha
Case 2: 88 Xukha
Case 3: 4 Xukha
Sponsor
#include<stdio.h>
#include<string.h>
//#include<algorithm>
//using namespace std;
int p[1000001]={1,1};
int t, n, m;
int main()
{
for(int i=2; i<=1000001; i++)
{
if (p[i]==1)
continue;
for (int j=i+i; j<=1000001; j+=i)
p[j]=1;
}
int x=1;
long long sum;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
sum=0;
while(n--)
{
scanf("%d",&m);
for (int i=m+1; ; i++)
{
if (p[i]==0)
{
sum+=i;
break;
}
}
}
printf("Case %d: %lld Xukha\n", x++,sum);
}
return 0;
}
竹竿跳马在 Xzhiland 是一项大规模流行的运动。和皮鞋师傅是一个非常受欢迎的教练, 他的成功。他需要一些竹子给他的学生, 所以他要求他的助手双鞋去市场买他们。很多竹子的所有可能的整数长度 (是!) 在市场上可用。根据 Xzhila 的传统,
竹子的分数 = f (竹子的长度)
(Xzhilans 真的很喜欢数论)。对于您的信息, f (n) = 小于 n 的数字 (在1之外没有共同的除数) 到 n。因此, 长度为9的竹子的得分是 6, 1, 2, 4, 5, 7, 8 是相对素数到9。
助理双鞋必须为每个学生买一根竹子。作为一个转折, 皮鞋的每个竿跳马学生有一个幸运数字。双鞋想买竹子, 这样他们每人得到一个分数大于或等于他/她的幸运数字的竹子。双鞋想尽量减少购买竹子所花的钱的总金额。竹子的一个单位花费 1 Xukha。帮帮他。
输入
输入以整数 T (≤ 100) 开始, 表示测试用例的数量。
每个案例都以一条包含整数 n (1 ≤ 10000) 的直线开始, 表示皮鞋的学生数量。下一行包含 n 个空格分隔整数, 表示学生的幸运数字。每个幸运数字将位于范围 [1, 106]。
欧拉函数题
题意 找出这组数中 比各个数大的最小素数们 的和
思路 素数的欧拉函数值即为p-1,所以就是找答案即为找距离x+1最近的素数