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为质数 的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...
随机推荐
- Luogu题目集合[6/未完待续]
1. P1327数列排序 题目描述 给定一个数列{an},这个数列满足ai≠aj(i≠j),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? 输入输出格式 输入格 ...
- Strcmp(字符串1,字符串2)函数 Sizeof && strlen() Substr(a,b)
Strcmp(字符串1,字符串2)函数 { strcmp函数是比较两个字符串的大小,返回比较的结果.一般形式是: i=strcmp(字符串,字符串); 其中,字符串1.字符串2均可为字符串常量或变量 ...
- MarkdownPad Win10 无法预览
软件环境 系统:windows 10 x64 软件:MarkDownPad 2 遇到问题 Markdownpad的实时预览无法显示 解决办法 安装 Awesonmium sdk后,重新打开Markdo ...
- 解决Apache/PHP无法启动的问题
最近经常被问到Apache无法启动的情况,所以写一篇文章,总结一下Windows下经常遇到的 Apache/PHP 无法启动的情况的解决方法. Apache/PHP 无法启动分两种情况: 1..Apa ...
- 隐写技巧——利用JPEG文件格式隐藏payload
0x00 前言 继续对图片隐写技巧的学习,这次是对JPEG文件格式的学习和理解.同PNG文件的格式对比,JPEG文件相对简单,读取其中隐藏payload的方式大同小异,两者区别在于文件格式不同,可供利 ...
- http协议(二)请求和响应报文的构成
http协议用于客户端和服务器之间的通信,请求访问资源的一方称为客户端,而提供资源响应的一方称为服务器端. 下面就是客户端和服务端之间简单的通信过程 PS:请求必须从客户端建立通信,服务端没收到请求之 ...
- wechat开发
1.easywechat安装 2.weichat打通服务器 function getTest(Request $request){ $token = 'zhenhaokeji'; $data = $r ...
- Location of several networks in brain
Source: Naci, L., et al. (2014). "A common neural code for similar conscious experiences in dif ...
- 前端见微知著番外篇:Bitbucket进行代码管控
说道代码管控,一般都会提到TFS.Git等,但是在这里我们将要用到Bitbucket,其实其操作方式和Git基本上一样,但是和TFS则有很大的不同了.但是原理基本上都是一致的. 这里我不会过多的涉及到 ...
- 一个Java Dao测试用例
import static org.junit.Assert.assertTrue; import java.util.Date; import java.util.HashMap; import j ...