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 ...
随机推荐
- 解决Deepin每次打开Chome都提示解锁登录密钥环的麻烦
密钥环是linux系统用于安全保存程序私密数据的模块,可以用于加密保存密码.证书.密钥等安全数据.chrome的密钥环用于保存本地访问站点密码或缓存从google服务器同步下来的访问站点的密码. De ...
- ASP.NET中JSON对时间进行序列化和反序列化
JSON格式不直接支持日期和时间.DateTime值显示为“/Date(0+0800)/”形式的JSON字符串,其中第一个数字是GMT时区中自1970年1月1 日午夜以来按正常时间(非夏令时)经过的毫 ...
- jquery图片上传前预览剪裁
http://www.webmotionuk.co.uk/jquery/image_upload_crop.php http://keleyi.com/a/bjad/liuvpkke.htm 不错的d ...
- debug命令
debug -r 查看寄存器-a 输入指令-t 执形命令 通用寄存器:AX=AH+ALBX=BH+BLCX=CH+CLDX=DH+DL 2Byte 16bitFFFF0-(2的16次方减1) debu ...
- poj 2531(dfs)
题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). #include<iostream> #i ...
- Machine Learning Yearning - Andrew NG
链接(1~12章): https://gallery.mailchimp.com/dc3a7ef4d750c0abfc19202a3/files/Machine_Learning_Yearning_V ...
- ios --转载-从URL中截取所包含的参数,并且以字典的形式返回和参数字典转URL
- (NSString *)keyValueStringWithDict:(NSDictionary *)dict { if (dict == nil) { return nil; } NSMutab ...
- spring 项目升级到spring cloud记录 数据源配置
用的阿里的数据源 增加pom <dependency> <groupId>com.alibaba</groupId> <artifactId>drui ...
- boost::interprocess(1)
发送端:#include <iostream> #include <windows.h> #include <string> using namespace std ...
- 获取TXT文件,解决读取TXT乱码问题,查找所输入字是否在TXT文件中,
/// <summary> /// 查看是否存在 /// </summary> /// <param name="str"></param ...