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.

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

题意:t个测试样例,每个样例 n 个数,对于给定的每个数a[i],要求一个数x,满足x的欧拉函数值大于a[i]

要找n个满足条件的数x,并且要求n 个数x 的和 cnt 最小,输出 cnt

题解:一个素数 p 的欧拉函数值等于 p-1;所以要找满足条件:欧拉函数值大于a[i] 的最小x;只要找大于a[i] 的最小素数即可,最后输出n个素数的和

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<string>
#define ll long long
#define mx 1000010
using namespace std;
int prim[mx];
void init()//素数打表
{
memset(prim,,sizeof(prim));
prim[]=;
for(int i=;i<mx;i++)
{
if(prim[i])//是偶数
continue; for(int j=i<<;j<mx;j=j+i)//把素数的倍数标记
prim[j]=;
}
}
int main()
{
int t,n,x;
cin>>t;
init();
for(int i=;i<=t;i++)
{
cin>>n;
ll cnt=;
for(int j=;j<n;j++)
{
cin>>x;
for(int k=x+;k<mx;k++)
{
if(prim[k]==)
{
cnt=cnt+k;
break;
}
}
}
cout<<"Case "<<i<<": "<<cnt<<" Xukha"<<endl;
}
return ;
}

最新文章

  1. php内核分析(八)-zend_compile
  2. java基础知识(一)数据类型(下)
  3. 【转载】CentOS6.5_X64下安装配置MongoDB数据库
  4. 【Leetcode】Evaluate Reverse Polish Notation JAVA
  5. MeetMe
  6. oracle 事务简介,锁的概念,java访问数据库注意事项
  7. oracle几个函数整理 DECODE() NVL NVL2 NULLIF Coalesce(转)
  8. extJS4.2.0 Json数据解析,嵌套及非嵌套(二)
  9. Go语言结构体(struct)
  10. 在X64系统中PowerDesigner无法连接MySQL的解决方法
  11. net core体系-API-Restful+Swagger搭建API
  12. template模板的使用方法
  13. [MicroPython]TPYBoardv102播放音乐实例
  14. BZOJ.4767.两双手(组合 容斥 DP)
  15. 如何使用 lsyncd 实时同步并执行 shell 命令
  16. vue路由传值方式
  17. nginx负载均衡的5种策略
  18. Groovy 学习手册(7)
  19. crop和resize操作区别
  20. org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/JJ]]

热门文章

  1. Debian 系统修改网卡ens33名称为 eth0
  2. UVA 10881 Piotr&#39;s Ants(模拟)
  3. Wx-小程序-组件式开发之Vant
  4. office自签名证书
  5. MyBatis-Spring整合之方式1
  6. 通过颜色绘制图片UIImage
  7. 【PAT甲级】1073 Scientific Notation (20 分)
  8. 传奇定时器OnTimer功能详解(泡点、时间触发、任务活动)
  9. LFTP命令笔记
  10. iOS 与 js交互的其一方法 WebViewJavascriptBridge的使用