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
Hint
#include<iostream>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 1000030
#define N 10009
#define INF 1000000009
/*
欧拉函数
打表
*/
LL T, n, a[N];
bool notprime[MAXN];
vector<LL> prime;
void Init()
{
memset(notprime, sizeof(notprime), false);
notprime[] = true;
//prime.resize(N);
for (LL i = ; i < MAXN; i++)
{
if (!notprime[i])
{
prime.push_back(i);
for (int j = i + i; j < MAXN; j+=i)
{
notprime[j] = true;
}
}
}
}
LL solve(LL x)
{
return *upper_bound(prime.begin(), prime.end(), x);
}
int main()
{
Init();
scanf("%lld", &T);
for(LL cas = ;cas<=T;cas++)
{
scanf("%lld", &n);
LL sum = ;
for (LL i = ; i < n; i++)
{
scanf("%lld", &a[i]);
sum += solve(a[i]);
}
printf("Case %lld: %lld Xukha\n",cas,sum);
}
return ;
}
Bi-shoe and Phi-shoe 欧拉函数 素数的更多相关文章
- Poj 2478-Farey Sequence 欧拉函数,素数,线性筛
Farey Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14291 Accepted: 5647 D ...
- lightoj1370欧拉函数/素数筛
这题有两种解法,1是根据欧拉函数性质:素数的欧拉函数值=素数-1(可根据欧拉定义看出)欧拉函数定义:小于x且与x互质的数的个数 #include<map> #include<set& ...
- poj 2480 Longge's problem 欧拉函数+素数打表
Longge's problem Description Longge is good at mathematics and he likes to think about hard mathem ...
- FZU 1759 欧拉函数 降幂公式
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000 ...
- poj3696 快速幂的优化+欧拉函数+gcd的优化+互质
这题满满的黑科技orz 题意:给出L,要求求出最小的全部由8组成的数(eg: 8,88,888,8888,88888,.......),且这个数是L的倍数 sol:全部由8组成的数可以这样表示:((1 ...
- HDU 4483 Lattice triangle(欧拉函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4483 题意:给出一个(n+1)*(n+1)的格子.在这个格子中存在多少个三角形? 思路:反着想,所有情 ...
- UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)
题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x ...
- 【欧拉函数】【HDU1286】 找新朋友
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 1695 GCD(欧拉函数+容斥原理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...
随机推荐
- B1231 [Usaco2008 Nov]mixup2 混乱的奶牛 状压dp
发现是状压dp,但是还是不会...之前都白学了,本蒟蒻怎么这么菜,怎么都学不会啊... 其实我位运算基础太差了,所以状压学的不好. 题干: Description 混乱的奶牛 [Don Piele, ...
- 解析HTML文件
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- from bs4 import BeautifulSoup import operator import ...
- Halcon学习笔记之支持向量机(一)
例程:class_overlap_svm.hdev 说明:这个例程展示了如何用一个支持向量机来给一幅二维的图像进行分类.使用二维数据的原因是因为它可以很容易地联想成为区域和图像.本例程中使用了三个互相 ...
- 前端Canvas思维导图笔记
看不清的朋友右键保存或者新窗口打开哦!喜欢我可以关注我,还有更多前端思维导图笔记
- Android第一次项目
学习了一个月的Android,接触了人生中第一个安卓项目,对于一个小白来说,总结是很重要的学习方法,以下我把学到的东西总结以下: 1. 1>okhttp3用法解析(边贴代码边熟悉) public ...
- DeltaFish 校园物资共享平台 第四次小组会议
一.上周记录汇报 齐天扬 学习慕课HTML至14章.构建之法10-14章 李 鑫 学习制作简易的JSP页面和servlet,看完关于HTML的慕课 陈志锴 学习编制简易JSP页面和servlet, ...
- 闰年or平年判断
<script type="text/javascript">var year = prompt("请输入一个年份");if(year!=null) ...
- IE浏览器发展史
- Assembly之instruction之MOV
MOV[.W] Move source to destinationMOV.B Move source to destination Syntax MOV src,dst or M ...
- 如何在编辑器打开Java程序
我们都知道运行JAVA文件,可以从软件控制台运行我们写好的java文件,也可以从windows窗口运行,我们最开始接触的是通过windows窗口来运行java文件,下面简单介绍一下如何如何在编辑器打开 ...