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 ...
随机推荐
- 本地连接linux虚拟机的方法
1.给虚拟机添加一个ehtX: 2. 3.添加一个ethX 4. 5.设置使用的是哪一个网卡,ifconfig的时候变会得到相应的ip 6. 再在cmd那ping ifconfig出来的自动获取的ip ...
- chckbox多选
1.HTML结构 <input type="checkbox" name="test" value="1"/><span& ...
- python - 判断是否为正小数和正整数
判断输入的金额是否为正整数和正小数 def check_float(string): #支付时,输入的金额可能是小数,也可能是整数 s = str(string) if s.count('.') == ...
- 2、手把手教React Native实战之从React到RN
###React简介 RN是基于React设计,了解React有助于我们开发RN应用: React希望将功能分解化,让开发变得像搭积木一样,快速而且可维护 React主要有如下3个特点: *作为UI( ...
- java各个版本垃圾收集器?
1.7G1
- [越狱开发] theOpenDev配置与搭建碰到的问题
CodeSign error: code signing is required for product type 'Dynamic Library' in SDK 'iOS 6.1' 如何解决?
- python bottle学习(四)request.quest/query_string/params/body等方法介绍
假设url:http://0.0.0.0:18082/api/cluster/group?wzd=111&abc=cc 方法类型:POST,body是{"name":& ...
- Spring配置dataSource的三种方式 数据库连接池
1.使用org.springframework.jdbc.dataSource.DriverManagerDataSource 说明:DriverManagerDataSource建立连接是只要有连接 ...
- CSS-微信开放UI样式
下面的链接是微信开放的CSS的样式: http://weui.github.io/weui/ 附上GitHub地址:https://github.com/weui/weui
- RadioButton ---- 样式效果切换
\res\drawable\radio_button_bg.xml <?xml version="1.0" encoding="utf-8"?> & ...