lightoj 1370 欧拉函数
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
System Crawler (2016-07-08)
Description
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
题意:
Φ (n)表示长度为小于数字n的和n互质的数的个数,也就是欧拉函数。现在给出n个幸运数字,对于每一个幸运数字,要求的x,使Φ (n)的值大于等于这个幸运数字,求这些x和的最小值。
思路:
先打表,对输入的n个数排序,然后枚举。
/*
* Author: sweat123
* Created Time: 2016/7/11 13:55:52
* File Name: main.cpp
*/
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<vector>
#include<cstdio>
#include<time.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#define INF 1<<30
#define MOD 1000000007
#define ll long long
#define lson l,m,rt<<1
#define key_value ch[ch[root][1]][0]
#define rson m+1,r,rt<<1|1
#define pi acos(-1.0)
using namespace std;
const int MAXN = ;
int er[MAXN],notprime[MAXN],cnt,n;
int prime[MAXN];
struct node{
int id,val;
friend bool operator <(node fa,node fb){
if(fa.val != fb.val)return fa.val > fb.val;
return fa.id > fb.id;
}
};
int num;
void init(){
cnt = ;
memset(er,,sizeof(er));
memset(notprime,,sizeof(notprime));
for(int i = ; i <= MAXN - ; i++){
if(!notprime[i]){
er[i] = i - ;
prime[cnt++] = i;
}
for(int j = ; j < cnt && 1LL * prime[j] * i <= MAXN; j++){
notprime[i * prime[j]] = ;
if(i % prime[j] == ){
er[i * prime[j]] = er[i] * prime[j];break;
} else {
er[i * prime[j]] = er[i] * (prime[j] - );
}
}
}
}
int a[];
int main(){
init();
int t,Case = ;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = ; i <= n; i++){
scanf("%d",&a[i]);
}
sort(a+,a+n+);
ll ans = ;
int x = ;
for(int i = ; i <= n; i++){
while(er[x] < a[i]){
x += ;
}
ans += x;
}
printf("Case %d: %lld Xukha\n",++Case,ans);
}
return ;
}
lightoj 1370 欧拉函数的更多相关文章
- 1370 - Bi-shoe and Phi-shoe(LightOJ1370)(数论基础,欧拉函数)
http://lightoj.com/volume_showproblem.php?problem=1370 欧拉函数: 在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目. φ(n) ...
- LightOJ 1370 - Bi-shoe and Phi-shoe (欧拉函数思想)
http://lightoj.com/volume_showproblem.php?problem=1370 Bi-shoe and Phi-shoe Time Limit:2000MS Me ...
- LightOJ 1370 Bi-shoe and Phi-shoe 欧拉函数+线段树
分析:对于每个数,找到欧拉函数值大于它的,且标号最小的,预处理欧拉函数,然后按值建线段树就可以了 #include <iostream> #include <stdio.h> ...
- LightOJ 1370 Bi-shoe and Phi-shoe(欧拉函数)
题意:题目给出一个欧拉函数值F(X),让我们求>=这个函数值的最小数N,使得F(N) >= F(X); 分析:这个题目有两种做法.第一种,暴力打出欧拉函数表,然后将它调整成有序的,再建立一 ...
- [LightOJ 1370] Bi-shoe and Phi-shoe(欧拉函数快速筛法)
题目链接: https://vjudge.net/problem/LightOJ-1370 题目描述: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. 知识点 ...
- LightOJ - 1370 Bi-shoe and Phi-shoe (欧拉函数打表)
题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和. 分析:先预处理出每个数的欧拉函数值phi[x].对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求. ...
- 欧拉函数 || LightOJ 1370 Bi-shoe and Phi-shoe
给出x,求最小的y使y的欧拉函数大于等于x *解法:i).求出1e6之内的数的欧拉函数,遍历找 ii).求比x大的第一个质数——因为每个质数n的欧拉函数都是n-1 wa一次是因 ...
- LightOJ - 1370 Bi-shoe and Phi-shoe 欧拉函数 题解
题目: Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popula ...
- 数论-欧拉函数-LightOJ - 1370
我是知道φ(n)=n-1,n为质数 的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...
随机推荐
- HDU2929 Bigger is Better[DP 打印方案 !]
Bigger is Better Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- C#复习(学生信息输入)
在控制台程序中使用结构体.集合,完成下列要求项目要求:一.连续输入5个学生的信息,每个学生都有以下4个内容:1.序号 - 根据输入的顺序自动生成,不需要手动填写,如输入第一个学生的序号是1,第二个是2 ...
- noip模拟赛(10.4) 序列(sequence)
序列(sequence) [题目描述] 给定一个1~n的排列x,每次你可以将x1~xi翻转.你需要求出将序列变为升序的最小操作次数.有多组数据. [输入数据] 第一行一个整数t表示数据组数. 每组数据 ...
- iOS 使用证书时遇到的错误一
证书概念: 那么现在就牵扯到几个名词,Development证书,aps_Development证书(推送证书),测试描述文件,AppID,同理也就有Distribution证书,aps_Distri ...
- apt-get update更新源时,出现“Hash Sum mismatch”问题
当使用apt-get update更新源时,出现下面"Hash Sum mismatch"的报错,具体如下:root@localhost:~# apt-get update.... ...
- python的高级特性3:神奇的__call__与返回函数
__call__是一个很神奇的特性,只要某个类型中有__call__方法,,我们可以把这个类型的对象当作函数来使用. 也许说的比较抽象,举个例子就会明白. In [107]: f = abs In [ ...
- django自带wsgi server vs 部署uwsgi+nginx后的性能对比
一.下面先交代一下测试云主机 cpu: root@alexknight:/tmp/webbench-1.5# cat /proc/cpuinfo |grep model model : model n ...
- wechat开发
1.easywechat安装 2.weichat打通服务器 function getTest(Request $request){ $token = 'zhenhaokeji'; $data = $r ...
- NOIP2016提高组解题报告
NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合
- DWZ中Tree树形菜单的treeCheck如何获取返回值解决方案
最近在对DWZ和asp.net MVC3进行整合,其中遇到了很多问题,总算一一解决了,今天就说说题目所示的问题解决方案. 想做一个基于角色的权限管理,要对每一个Action进行权限控制.就想用DWZ的 ...