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 ;
}

A - Bi-shoe and Phi-shoe 素数打表的更多相关文章

  1. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

  2. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

  3. Codeforces Round #315 (Div. 2C) 568A Primes or Palindromes? 素数打表+暴力

    题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以 ...

  4. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  5. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  6. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  7. Aladdin and the Flying Carpet LightOJ - 1341 (素数打表 + 算术基本定理)

    题意: 就是求a的因数中大于b的有几对 解析: 先把素数打表 运用算术基本定理 求出a的所有因数的个数 然后减去小于b的因数的个数 代码如下: #include <iostream> #i ...

  8. Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)

    题意: 就是哥德巴赫猜想...任意一个偶数 都可以分解成两个(就是一对啦)质数的加和 输入一个偶数求有几对.. 解析: 首先! 素数打表..因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质 ...

  9. uva11610 树状数组+素数打表求因子,好题!

    /* uva11610 树状数组+素数打表+离散化 打出的素数范围在2-1000000之间,不超过六位数,然后按照格式翻转成七位数 */ #include<bits/stdc++.h> u ...

  10. 26-算法训练 Torry的困惑(基本型) 素数打表

      算法训练 Torry的困惑(基本型)   时间限制:1.0s   内存限制:512.0MB      问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.To ...

随机推荐

  1. 【Python】 运算符

    什么是运算符? 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符. 接下来让我们一个个来学习Pytho ...

  2. C# 之 代码实现延时

    Task.Delay();异步实现 using System;using System.Threading.Tasks; namespace csharpYS{ class Program { sta ...

  3. TestNG单元测试与使用详解

    TestNG的基本注解与执行顺序 在类里编辑程序时,在@Test后面,摁 alt+回车,选择对应的插件,可以把目前用到的插件自动添加到 pom.xml 文件中,如下面的testng,每摁一次,就多添加 ...

  4. Speech Bandwidth Extension With WaveNet

    利用WAVENET扩展语音带宽 作者:Archit Gupta, Brendan Shillingford, Yannis Assael, Thomas C. Walters 博客地址:https:/ ...

  5. Python实现云服务器防止暴力密码破解

    云服务器防止暴力密码破解 云服务器暴露在公网上,每天都有大量的暴力密码破解,更换端口,无济于事,该脚本监控安全日志,获取暴力破解的对方ip,加入hosts黑名单 路径说明 描述 路径 登录安全日志 / ...

  6. 2020 i春秋新春战疫公益赛 misc

    0x01 code_in_morse morse decode后得到: RFIE4RYNBINAUAAAAAGUSSCEKIAAAAEUAAAAA7AIAYAAAAEPFOMTWAAABANUSRCB ...

  7. django之orm的高级操作以及xcc安全攻击

    查询用法大全: 1. 比较运算符 # id > 3 res = models.UserInfo.objects.filter(id__gt=3) # id >= 3 res = model ...

  8. 安卓之button按钮

    一.需求 短按按钮时显示  您点击了控件:Button 长按按钮时显示  您点击了控件:Button 二.布局xml文件 <?xml version="1.0" encodi ...

  9. python csv 数据切割定制jmeter数据

    需求压测随机抽取10w数据中自定义区间的指定数量数据进行压测: jmeter csv/txt配置: 需要获取{data: [${myList}]  }  jmeter需要数据类型 获取展读取csv数据 ...

  10. centos7 安装pip2和pip3

    linux pip2 安装cd /usr/bin yum install -y epel-release yum install -y python-pip _____________________ ...