题意:给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 (欧拉函数打表)的更多相关文章

  1. hdu 2824 The Euler function 欧拉函数打表

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. 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) 值为 ...

  3. POJ 2478 欧拉函数打表的运用

    http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很 ...

  4. A - Bi-shoe and Phi-shoe (欧拉函数打表)

    Description Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a ver ...

  5. 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 ...

  6. light1370 欧拉函数打表

    /* 给定n个数ai,要求欧拉函数值大于ai的最小的数bi 求sum{bi} */ #include<bits/stdc++.h> using namespace std; #define ...

  7. 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板

    Problem I. Count Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  8. AcWing 201. 可见的点 (欧拉函数打表)打卡

    在一个平面直角坐标系的第一象限内,如果一个点(x,y)与原点(0,0)的连线中没有通过其他任何点,则称该点在原点处是可见的. 例如,点(4,2)就是不可见的,因为它与原点的连线会通过点(2,1). 部 ...

  9. FZU 1759 欧拉函数 降幂公式

    Description   Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000 ...

随机推荐

  1. beautifulSoup安装

    Python2.7 + beautifulSoup 4.4.1 安装配置 原创 2016年05月09日 10:20:30 标签: python 1261 1. 前言 最近研究python 的爬虫功能, ...

  2. sql把varchar转化为int型

    select Max(convert(int,id))from member_Info;

  3. 命令行执行php

    D:\software\phpStudy\php55

  4. 使用 Notepad 或 TextEdit 来编写 HTML

    可以使用专业的 HTML 编辑器来编辑 HTML: Adobe Dreamweaver Microsoft Expression Web CoffeeCup HTML Editor 不过,我们同时推荐 ...

  5. Ajax.BeginForm提示不支持live属性或方法的错误

    解决: 在nuget下载最新版本的jquery.unobtrusive-ajax.min.js文件 Ajax异步请求: 引用JS: <script type="text/javascr ...

  6. 2018 ACM-ICPC 北京赛区小结 @ Reconquista

    Statistics TYPE: Onsite Contest NAME: 2018 - ICPC Regional - Asia EC - Beijing PLAT: Hihocoder TIME: ...

  7. npm install 不自动生成 package-lock.json文件

    package-lock.json这个文件的作用就不详细说明了 有需要的可以参考 :https://www.cnblogs.com/cangqinglang/p/8336754.html 网上都说 n ...

  8. IntelliJ Idea Hide excluded folders 隐藏或显示你需要的文件夹

    IntelliJ Idea,以前用idea时,经常maven编译就出现了exclude下的文件夹通常是target,如何隐藏自己不想看见的文件夹,或显示偶尔会用到的文件夹 点击齿轮右下小标 选中文件夹 ...

  9. android 127.0.0.1/localhost connection refused,在模拟器上应该用10.0.2.2访问你的电脑本机

    调试中通过android simulator模拟器链接localhost或者127.0.0.1,因为我在电脑上面建立了apache,我的代码大概就是URL url = new URL(urlStrin ...

  10. [cocos2dx] cocosdx编译工程那些事

    cocos compile -p android 上面这条命令可以将cocos2dx的工程编译出android apk,需要注意的是如果有新增的cpp文件,都需要在“CocosProject\proj ...