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