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 ...
随机推荐
- ajax实时获取下拉数据
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ajax ...
- ABAP-创建客户
CALL METHOD CMD_EI_API=>MAINTAIN_BAPI FUNCTION Z_CS_RFC_OA002 . *"------------------------ ...
- Elasticsearch5 及 head插件 安装说明
Elasticsearch5.X及 head插件 安装说明: 1.下载elasticsearch安装文件: a) 下载官方源码: https://artifacts.elastic.co/downlo ...
- hibernate 一对多 级联 保存修改 删除
一对多,一端设置: <set name="TWorkorderHistories" inverse="true" cascade="all&qu ...
- myeclipse内存不足的处理
Myeclipse内存溢出解决方案 1.tomcat内存扩展 修改tomcat中bin目录下catalina.bat文件在echo Using CATALINA_BASE: "%CATAL ...
- smokeping再次部署遇到的问题记录
问题1: Can't locate Sys/Syslog.pm in @INC (@INC contains: /opt/smokeping_workspace/thirdparty/lib/perl ...
- npm使用淘宝镜像安装包
npm使用registry这个属性指定仓库,因此配置这个属性即可.修改npm配置属性的几种方法详见官方文档. 这里只贴出修改registry的方法,以下三种任意一种即可: 修改~/.npmrc文件(没 ...
- codeforces 566D D. Restructuring Company(并查集)
题目链接: D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- HTml js 生成图片
<script type="text/javascript"> function $(id) { return document.getElementById(id); ...
- ACM学习历程—HDU5269 ZYB loves Xor I(位运算 && dfs && 排序)(BestCoder Round #44 1002题)
Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he ...