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 ...
随机推荐
- rsyslog masg和rawmsg的区别
msg the MSG part of the message (aka "the message" ;)) message 的MSG 部分 rawmsg the message ...
- poj2039---写出c++reverse函数,且且依次输出每一行的第一个、第二个.....
#include <stdio.h> #include <stdlib.h> #include <string.h> void reverse(char *p1,c ...
- c++基础 之 面向对象特征一 : 继承
class Base { public: void f() { cout<<"void f()"<<endl<<endl; } void f(i ...
- ZOJ 3829 Known Notation (2014牡丹江H称号)
主题链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=5383 Known Notation Time Limit: 2 S ...
- Tomcat配置一个ip绑定多个域名
在网上找了半天也没找到相关的资料,都说的太含糊. 本人对tomcat下配置 一ip对多域名的方法具体例如以下,按以下配置一定能成功,经过測试了. <Host name="localho ...
- 运行JBoss 5.1.0 GA时出现Error installing to Instantiated:name=AttachmentStore state=Described错误的解决办法
第一次开JBoss服务器:有些时候会遇到这种情况:把以下的文字替换即可 进到类似目录 server/default/conf/bootstrap,打开文件 profile.xml找到: Xml代码 & ...
- 关于K-Means算法
在数据挖掘中,K-Means算法是一种cluster analysis的算法,其主要是来计算数据聚集的算法,主要通过不断地取离种子点最近均值的算法. 问题 K-Means算法主要解决的问题如下图所示. ...
- 浅谈Mybatis(一)
一.MyBatis引言 1.基本概念 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google co ...
- Convert Binary Search Tree (BST) to Sorted Doubly-Linked List
(http://leetcode.com/2010/11/convert-binary-search-tree-bst-to.html) Convert a BST to a sorted circu ...
- 如何创建一个简单的struts2程序
如何创建一个简单的Struts2程序 “计应134(实验班) 凌豪” 1.创建一个新的Web项目test(File->new->Web Project) 2.Struts2框架的核心配置文 ...