Lightoj1007【欧拉函数-素数表】
基础题。
PS:注意unsigned long long; 以及%llu
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL; const int N=5e6+10;
bool isprime[N];
ULL res[N];
void init()
{
res[1]=1ULL;
for(LL i=1;i<=5000000;i++)
{
isprime[i]=true;
res[i]=i;
}
for(LL i=2;i<=5000000;i++)
{
if(!isprime[i]) continue;
res[i]=res[i]*(i-1)/i;
for(LL j=i+i;j<=5000000;j+=i)
{
isprime[j]=false;
res[j]=res[j]*(i-1)/i;
}
}
for(int i=2;i<=5000000;i++)
res[i]=res[i]*res[i]+res[i-1];
} int main()
{
int T,cas=1,a,b;
init();
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&a,&b);
printf("Case %d: %llu\n",cas++,res[b]-res[a-1]);
}
return 0;
}
Lightoj1007【欧拉函数-素数表】的更多相关文章
- Bi-shoe and Phi-shoe(欧拉函数/素筛)题解
Bi-shoe and Phi-shoe Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe ...
- P2158 [SDOI2008]仪仗队 线性筛(欧拉函数和素数表)
上三角行恰好是[1,n-1]的欧拉函数 http://www.luogu.org/problem/show?pid=2158#sub //#pragma comment(linker, "/ ...
- Farey Sequence (素筛欧拉函数/水)题解
The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...
- UVA - 11426 欧拉函数(欧拉函数表)
题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1 ...
- (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...
- HDU 3970 Harmonious Set 容斥欧拉函数
pid=3970">链接 题解:www.cygmasot.com/index.php/2015/08/17/hdu_3970 给定n 求连续整数[0,n), 中随意选一些数使得选出的 ...
- HDU 1695 GCD (欧拉函数,容斥原理)
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- (转载)O(N)的素数筛选法和欧拉函数
转自:http://blog.csdn.net/dream_you_to_life/article/details/43883367 作者:Sky丶Memory 1.一个数是否为质数的判定. 质数,只 ...
- (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)
题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- 开发的第一个PHP扩展
下载php源码php-5.4.23.tar.gz,解压,进入/home/hubo/php-5.4.23/ext/扩展目录 wget http://cn2.php.net/get/php-5.4.23. ...
- Redis——慢查询分析
核心知识点: 1.什么是慢查询? 2.客户端执行一条命令的步骤? 3.阈值和慢查询日志的设置? 4.慢查询日志的操作命令:slowlog get.slowlog len.slowlog reset. ...
- Kattis - cardhand Card Hand Sorting 【暴力枚举】
题意 给出 一个扑克牌的序列 求排成一个"有序"序列 最少的插入次数 有序是这样定义的 同一个花色的 必须放在一起 同一花色中的牌 必须是 升序 或者是 降序 然后 A 是最大的 ...
- PAT 天梯赛 L3-003. 社交集群 【并查集】
题目链接 https://www.patest.cn/contests/gplt/L3-003 思路 并查集 用一个 cou[i] 来表示 第 i 门课程 的第一个 感兴趣的人 并的时候 判断 cou ...
- CSS3定时提示动画特效
在线演示 本地下载
- 初学OpenMP
这两天在看多核计算的书,就要用到openmp,因为我使用vs2015,从微软可以看到是支持openmp2.0版本的 具体使用: 在vs里创造一个控制台项目,然后打开属性管理器,在属性管理器里找到配置属 ...
- 算法(Algorithms)第4版 练习 1.3.13
(a) 0 1 2 3 4 5 6 7 8 9 (b) 4 6 8 7 5 3 2 9 0 1 (c) 2 5 6 7 4 8 9 3 1 0 (d) 4 3 2 1 0 5 6 7 8 9 答案:b ...
- Contiki源码结构
Contiki源码结构 apps目录下,用于存放Application,也就是我们的应用程序放在这个目录下.如webserver,webrowser等,如下图所示. core目录是contiki操作系 ...
- 京东SDK模板卡盘效果实现代码
最近在做京东模板,因为是最新平台,好多功能都需要摸索,俺技术一般,摸索出一个简易的卡盘功能 ——————使用的是分类推荐模块哦! 本着共享的精神,俺将代码放到这儿了,各人请自便.(代码还不够完善, ...
- poj3666序列对应——DP
题目:http://poj.org/problem?id=3666 很普通的DP,离散化(sort)一下即可: mn的求法很不错(比我原来开了mn[]……简洁). 代码如下: #include< ...