数论A - Bi-shoe and Phi-shoe

 

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.


竹竿跳马在 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]。


题意即为  找出这组数中   比各个数大的最小素数们  的和。


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

 


#include
#include
#include
#include
#include
using namespace std;
int p[1000001]={1,1};   //定义数组p[1000001],使p[0]=1,p[1]=1,其余全部为0  并且在下面的程序中用0标记为素数;
int t, n, m;
int main()
{
    for(int i=2;i<=1000001;i++)
    {
	if (p[i]==1)      //进行判断,该数是否为素数,如果为素数,立即结束本次循环,判断下一个数字 i++;
		continue;
	for (int j=i+i; j<=1000001; j+=i)  //在1000001个数中将非素数标记为1;
		p[j]=1;
    }
    int x=1, i;
    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)  //如果数i标记为0,即i为素数,加入 和(sum) 中,并且结束for循环,继续判断下一个m;
		{
			sum+=i;
			break;
		}
	    }
        }
        printf("Case %d: %lld Xukha\n", x++,sum);
    }
    return 0;
}

 

 

 

你可能感兴趣的:(数论)