LOJ 1370 Bi-shoe and Phi-shoe(欧拉函数的简单应用)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1370
题意:给你n个整数,第i个整数为Xi。定义phi(k)为k的欧拉函数值,设pi为满足phi(pi)>=Xi的最小整数,题目就是要求sum(p1,p2,p3,...,pn)
思路:对任意x,有prime[i]<=x<prime[i+1]必定有EulerPhi[x]<=prime[i],要满足phi(p)>=x那么p必定为x后面的第一个素数,进行素数打表即可。
code:
#include <cstdio>
#include <cstring>
typedef long long LL;
const int MAXN = ; int p[MAXN];
bool isPrime[MAXN]; void init()
{
memset(isPrime, true, sizeof(isPrime));
isPrime[] = false;
isPrime[] = false;
// isPrime[1000001] = true;
for (int i = ; i * i < MAXN; ++i) {
if (isPrime[i]) {
int j = i * i;
while (j < MAXN) {
isPrime[j] = false;
j += i;
}
}
}
int k = ;
for (int i = ; i >= ; --i) {
if (isPrime[i]) {
p[i] = k;
k = i;
continue;
}
p[i] = k;
}
} int main()
{
init();
int nCase;
scanf("%d", &nCase);
for (int cas = ; cas <= nCase; ++cas) {
int n, k;
scanf("%d", &n);
LL ans = ;
for (int i = ; i < n; ++i) {
scanf("%d", &k);
ans += p[k];
}
printf("Case %d: %lld Xukha\n", cas, ans);
}
return ;
}
LOJ 1370 Bi-shoe and Phi-shoe(欧拉函数的简单应用)的更多相关文章
- (hdu step 7.2.2)GCD Again(欧拉函数的简单应用——求[1,n)中与n不互质的元素的个数)
题目: GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- FZU 1759 欧拉函数 降幂公式
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000 ...
- poj3696 快速幂的优化+欧拉函数+gcd的优化+互质
这题满满的黑科技orz 题意:给出L,要求求出最小的全部由8组成的数(eg: 8,88,888,8888,88888,.......),且这个数是L的倍数 sol:全部由8组成的数可以这样表示:((1 ...
- HDU 4483 Lattice triangle(欧拉函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4483 题意:给出一个(n+1)*(n+1)的格子.在这个格子中存在多少个三角形? 思路:反着想,所有情 ...
- UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)
题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x ...
- lightOJ1370 欧拉函数性质
D - (例题)欧拉函数性质 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:32768KB ...
- 【欧拉函数】【HDU1286】 找新朋友
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 1695 GCD(欧拉函数+容斥原理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...
- SPOJ 5152 Brute-force Algorithm EXTREME && HDU 3221 Brute-force Algorithm 快速幂,快速求斐波那契数列,欧拉函数,同余 难度:1
5152. Brute-force Algorithm EXTREME Problem code: BFALG Please click here to download a PDF version ...
随机推荐
- Android Studio设置自动编译工程
- NOI2011 Day1
NOI2011 Day1 兔农 题目描述:\(fib[1]=fib[2]=1, fib[i]=fib[i-2]+fib[i-1] (i\geq 3)\),若\(fib[i] \equiv 1(mod ...
- Openstack 的 RPC使用。
大家都已经很熟悉了RPC了. 比如说nfs就是采用的RPC通信. 尤其SUN RPC 已经成为了C语言开发的经典一种进程间调用机制. openstack 的RPC 机制, 是基于AMQP 活着其他高级 ...
- Error copying image in the datastore: Not allowed to copy image file
opennebula error copying image in the datastore not allowed to copy image file Error copying image i ...
- find the mincost route(最小环,最短路,floyd)
find the mincost route Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- UVa 10491 Cows and Cars (概率&广义三门问题 )
10491 - Cows and Cars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...
- 通过案例掌握Spring 管理事务的步骤及配置
案例描述 通过完成生成订单业务,掌握事务处理. 需要d_order表和d_item表 订单生成时的业务逻辑:向d_order插入1条数据的同时,向t_item中插入若干条数据 这就是一个独立的 ...
- 从零开始学习UNITY3D(GUI篇 2)
复合控件极其使用,toolbar,selectgrid 先看效果图: toolbar可以看作是一个button按钮的集合,一次只能点击一个按钮, selectgrid又可以堪称是一个toolbar的集 ...
- Oracle存储过程返回一张表数据
在oracle数据库中你要在程序里得到一张表的数据就必须先创建游标和SQL Service不一样. --创建游标create or replace package pkg_Dataas type re ...
- English - when用法
一.作为副词,它有以下的用法: 1. 作为疑问副词,引导特殊疑问句,意为“什么时候:何时”.如: ( 1 ) When will they come back?( 2 ) What time wil ...