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总结5——常量、文件上传
5.1常量 系统常量: PHP_OS 操作系统 PHP_VERSION php版本 PHP_SAPI 运行方式 自定义常量: define("常量名称"," ...
- opencv操作相机相关函数
1.基本操作 capture = cv2.VideoCapture(0) ret, image = capture.read() cv2.imwrite("photo.jpg", ...
- 【shell】判断一个变量是否为空
#!/bin/bash argv=" if [ -z "$argv" ] then echo "argv is empty" else echo &q ...
- long_query_time 设置不生效问题
由于原来的慢查询日志太大了,有1G多,并且其中包含上一次查询优化前的慢sql,所以想收集最近两天的慢查询语句,故 mysql> show global variables like 'slow% ...
- 更新TP-LINK路由器的外网IP到花生壳动态IP解析
------------------------------------------------------------------------------- 以下内容可能还是存在问题,等之后有时间再 ...
- make和rest用法
位置(position):下一个要读取或写入的数据的索引.缓冲区的位置不能为负,并且不能大于其限制(limit). 标记(mark)与重置(reset):标记是一个索引,通过Buffer中的mark( ...
- spawning cl.exe
可能很多人在安装VC 6.0后有过点击“Compile”或者“Build”后被出现的“Compiling... ,Error spawning cl.exe”错误提示给郁闷过.很多人的选择是重装,实际 ...
- PYTHON 爬虫笔记八:利用Requests+正则表达式爬取猫眼电影top100(实战项目一)
利用Requests+正则表达式爬取猫眼电影top100 目标站点分析 流程框架 爬虫实战 使用requests库获取top100首页: import requests def get_one_pag ...
- python绘制圆和椭圆
源自:https://blog.csdn.net/petermsh/article/details/78458585 1. 调用包函数绘制圆形Circle和椭圆Ellipse from matplot ...
- Java中内部类中使用外面变量为什么final修饰?
所以final从语法上约束了实际上两个不同变量的一致性(表现为同一变量). 我的理解: 例如这样的代码: public void test(String str){ str="abc&quo ...