LightOJ - 1370 Bi-shoe and Phi-shoe (欧拉函数打表)
题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和。
分析:先预处理出每个数的欧拉函数值phi[x]。对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
int phi[maxn];
int res[maxn];
bool isprime[maxn]; void Euler(){ //欧拉函数筛
for(int i=;i<maxn;++i) phi[i] = i;
memset(isprime,,sizeof(isprime));
isprime[] = isprime[] = false;
phi[] =;
for(int i=;i<maxn;++i){
if(!isprime[i]) continue;
for(int j=i;j<maxn;j+=i){
isprime[j] = false;
phi[j] -= phi[j]/i;
}
}
} void pre(){
memset(res,,sizeof(res));
for(int i=;i<maxn;++i){
for(int j=phi[i];j>= && res[j]==;--j){
res[j] = i;
}
}
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int T,N,a,cas=;
Euler();
pre();
scanf("%d",&T);
while(T--){
scanf("%d",&N);
LL sum=;
for(int i=;i<N;++i){
scanf("%d",&a);
sum +=res[a];
}
printf("Case %d: %lld Xukha\n",cas++,sum);
}
return ;
}
LightOJ - 1370 Bi-shoe and Phi-shoe (欧拉函数打表)的更多相关文章
- hdu 2824 The Euler function 欧拉函数打表
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- uva 11426 GCD - Extreme (II) (欧拉函数打表)
题意:给一个N,和公式 求G(N). 分析:设F(N)= gcd(1,N)+gcd(2,N)+...gcd(N-1,N).则 G(N ) = G(N-1) + F(N). 设满足gcd(x,N) 值为 ...
- POJ 2478 欧拉函数打表的运用
http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很 ...
- A - Bi-shoe and Phi-shoe (欧拉函数打表)
Description Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a ver ...
- UVA 11426 GCD - Extreme (II)(欧拉函数打表 + 规律)
Given the value of N, you will have to find the value of G. The definition of G is given below:Here ...
- light1370 欧拉函数打表
/* 给定n个数ai,要求欧拉函数值大于ai的最小的数bi 求sum{bi} */ #include<bits/stdc++.h> using namespace std; #define ...
- 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板
Problem I. Count Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- AcWing 201. 可见的点 (欧拉函数打表)打卡
在一个平面直角坐标系的第一象限内,如果一个点(x,y)与原点(0,0)的连线中没有通过其他任何点,则称该点在原点处是可见的. 例如,点(4,2)就是不可见的,因为它与原点的连线会通过点(2,1). 部 ...
- FZU 1759 欧拉函数 降幂公式
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000 ...
随机推荐
- thinkphp 从服务器拉取下来 验证码失效
public function verify(){ ob_end_clean();//加入 $verify = new \Think\Verify(); $verify->entry(1); }
- Python 数据库连接池
python编程中可以使用pymysql进行数据库连接及增删改查操作,但每次连接mysql请求时,都是独立的去请求访问,比较浪费资源,而且访问数量达到一定数量时,对mysql的性能会产生较大的影响.因 ...
- char类型能否存储一个中文字符?为什么
char类型能否存储一个中文字符?为什么 解答:可以.一个char是两个字节,而一个中文也是两个字节.
- Flea Circus(Project Euler 213)
original version hackerrank programming version 题目大意是N*N的格子,每个格子一开始有1个跳蚤,每过单位时间跳蚤会等概率向四周跳,问M秒后空格子的期望 ...
- 非阻塞IO 和阻塞IO【转】
IO模式设置网络编程常见问题总结—IO模式设置,阻塞与非阻塞的比较,recv参数对性能的影响—O_NONBLOCK(open使用).IPC_NOWAIT(msgrcv).MSG_DONTWAIT(re ...
- 【Raspberry pi】set up an ftp server
http://www.debian-administration.org/articles/228 As a means of distributing large collections of fi ...
- Idea定位打开文件在左边工程中的文件路径
勾选掉Autoscoll from Source
- Eclipse下导入外部jar包的3种方式
http://blog.csdn.net/mazhaojuan/article/details/21403717
- ext布局问题之tab panel内的gridpanel内容数据变多,出现滚动条
1)解决之道: 1.修改tabPanel var tabs= new Ext.TabPanel({ border: false, region:'center', id:'center', activ ...
- java-通过 HashMap、HashSet 的源码分析其 Hash 存储机制
通过 HashMap.HashSet 的源码分析其 Hash 存储机制 集合和引用 就像引用类型的数组一样,当我们把 Java 对象放入数组之时,并非真正的把 Java 对象放入数组中.仅仅是把对象的 ...