基础题。

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【欧拉函数-素数表】的更多相关文章

  1. Bi-shoe and Phi-shoe(欧拉函数/素筛)题解

    Bi-shoe and Phi-shoe Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe ...

  2. P2158 [SDOI2008]仪仗队 线性筛(欧拉函数和素数表)

    上三角行恰好是[1,n-1]的欧拉函数 http://www.luogu.org/problem/show?pid=2158#sub //#pragma comment(linker, "/ ...

  3. Farey Sequence (素筛欧拉函数/水)题解

    The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/ ...

  4. UVA - 11426 欧拉函数(欧拉函数表)

    题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1 ...

  5. (Relax 数论1.8)POJ 1284 Primitive Roots(欧拉函数的应用: 以n为模的本原根的个数phi(n-1))

    /* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> # ...

  6. HDU 3970 Harmonious Set 容斥欧拉函数

    pid=3970">链接 题解:www.cygmasot.com/index.php/2015/08/17/hdu_3970 给定n  求连续整数[0,n), 中随意选一些数使得选出的 ...

  7. HDU 1695 GCD (欧拉函数,容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. (转载)O(N)的素数筛选法和欧拉函数

    转自:http://blog.csdn.net/dream_you_to_life/article/details/43883367 作者:Sky丶Memory 1.一个数是否为质数的判定. 质数,只 ...

  9. (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 ...

随机推荐

  1. Kibana + ElasticSearch

    上面一张介绍了ElasticSearch的安装和简单用法. 现在应该都知道ElasticSearch是用来做全文搜索的,那今天我就简单介绍下Kibana. 它是专门用来查看ElasticSearch内 ...

  2. MV45AOZZ 销售订单增强点

    [转自 http://blog.csdn.net/zhongguomao/article/details/6712580]choose the table VBAP or VBAK ( dependi ...

  3. MySQL——并发控制(锁)

    核心知识点: 1.表锁和行级锁代表着锁的级别:读锁和写锁代表锁定真实类型. 2.读锁属于共享锁,共享同一资源,互不干扰:写锁属于排他锁,为了安全起见,写锁会阻塞其他的读锁和写锁. 3.表锁的开销最小, ...

  4. 开始使用Python

    1. 开始使用Python 1.1 print使用str()函数显示对象,而交互式解释器调用repr()函数来显示对象. 1.2 在解释器中_表示最后一个表达式的值. 1.3 >>用来重定 ...

  5. <JAVA8新增内容>关于匿名内部集合和lambda表达式

    要想说清楚JAVA中的Lambda表达式,必须想讲一下匿名内部类来帮助理解本质. 一.匿名内部类 匿名内部类适合创建那种只需要一次使用的类,例如前面介绍命令模式时所需要的Command对象,匿名内部类 ...

  6. Centos虚拟机克隆后的ip配置

    1. rm -rf /etc/udev/rules.d/-persistent-net.rules 2. 重启,然后: vi /etc/udev/rules.d/70-persistent-net.r ...

  7. 如何在Mac的Finder中显示/usr、/tmp、/var等隐藏目录

    原文链接: http://blog.csdn.net/yhawaii/article/details/7435918 Finder中默认是不显示/usr./tmp./var等隐藏目录的,通过在终端中输 ...

  8. 使用libcurl,根据url下载对应html页面

    1. [图片] Capture.JPG ​2. [代码]GetPageByURL //static member variable definestring GetPageByURL::m_curPa ...

  9. 分享知识-快乐自己:微服务的注册与发现(基于Eureka)

    1):微服务架构 服务提供者.服务消费者.服务发现组件这三者之间的关系: 各个微服务在启动时,将自己的网络地址等信息注册到服务发现组件中,服务发现组件会存储这些信息. 服务消费者可从服务发现组件查询服 ...

  10. linux应用之tomcat安装(centos)

    安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz下载地址:http://tomcat.apache.org/download-70.cgi 安装前提 系统必须已经安装配 ...