Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable.

In this problem, you will be given two integers a and b. You have to find the summation of the scores of the numbers froma to b (inclusive). The score of a number is defined as the following function.

score (x) = n2, where n is the number of relatively prime numbers with x, which are smaller than x

For example,

For 6, the relatively prime numbers with 6 are 1 and 5. So, score (6) = 22 = 4.

For 8, the relatively prime numbers with 8 are 1, 3, 5 and 7. So, score (8) = 42 = 16.

Now you have to solve this task.

Input

Input starts with an integer T (≤ 105), denoting the number of test cases.

Each case will contain two integers a and b (2 ≤ a ≤ b ≤ 5 * 106).

Output

For each case, print the case number and the summation of all the scores from a to b.

Sample Input

3

6 6

8 8

2 20

Sample Output

Case 1: 4

Case 2: 16

Case 3: 1237

Note

题意:

   不是求区间内素数个数的平方和,是求区间内欧拉函数值的平方和

思路:欧拉函数打表(模板)+前缀和+预处理不然TLE

求欧拉函数1-N的打表模板:

 void init()
{
memset(ans,,sizeof(ans));//一定要清空
ans[]=;
for(int i=; i<=N; i++)
{
if(ans[i]==)
{
for(int j=i; j<=N; j+=i)
{
if(ans[j]==)
{
ans[j]=j;
}
ans[j]=ans[j]/i*(i-);
} }
}
}
 #include<stdio.h>
#include<map>
#include<string.h>
#include<iostream>
typedef long long ll;
using namespace std; const int N=*1e6+;
unsigned long long ans[N];//unsigned long long输出是%llu,long long会爆,前者20位,后者19位 void init()
{
memset(ans,,sizeof(ans));//一定要清空,不然WA
ans[]=;
for(int i=; i<=N; i++)
{
if(ans[i]==)
{
for(int j=i; j<=N; j+=i)
{
if(ans[j]==)
{
ans[j]=j;
}
ans[j]=ans[j]/i*(i-);
} }
}//欧拉函数打表
for(int i=; i<=N; i++)
{
ans[i]=ans[i-]+ans[i]*ans[i];//计算前缀和
}
}
int main()
{
init();
int tt=,t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d %d",&a,&b);
printf("Case %d: %llu\n",tt++,ans[b]-ans[a-]);//取区间,左端区间-1,别弄错了
} return ;
}

LightOJ-1007-Mathematically Hard-欧拉函数打表+前缀和+预处理的更多相关文章

  1. lightoj 1007 - Mathematically Hard 欧拉函数应用

    题意:求[a,b]内所有与b互质个数的平方. 思路:简单的欧拉函数应用,由于T很大 先打表求前缀和 最后相减即可 初次接触欧拉函数 可以在素数筛选的写法上修改成欧拉函数.此外本题内存有限制 故直接计算 ...

  2. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  3. A - Bi-shoe and Phi-shoe (欧拉函数打表)

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

  4. hdu 2824 The Euler function 欧拉函数打表

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. UVA 11426 GCD - Extreme (II)(欧拉函数打表 + 规律)

    Given the value of N, you will have to find the value of G. The definition of G is given below:Here ...

  6. POJ 2478 欧拉函数打表的运用

    http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很 ...

  7. LightOJ 1370- Bi-shoe and Phi-shoe (欧拉函数)

    题目大意:一个竹竿长度为p,它的score值就是比p长度小且与且与p互质的数字总数,比如9有1,2,4,5,7,8这六个数那它的score就是6.给你T组数据,每组n个学生,每个学生都有一个幸运数字, ...

  8. nyoj 1007 GCD(数学题 欧拉函数的应用)

    GCD 描述 The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b) ...

  9. LightOJ - 1370 Bi-shoe and Phi-shoe (欧拉函数打表)

    题意:给N个数,求对每个数ai都满足最小的phi[x]>=ai的x之和. 分析:先预处理出每个数的欧拉函数值phi[x].对于每个数ai对应的最小x值,既可以二分逼近求出,也可以预处理打表求. ...

随机推荐

  1. pycharm破解教程

    转载 查询 https://blog.csdn.net/u014044812/article/details/86679150

  2. Development 编程规范

    { 命名规范类命名 1)所有的类名,接口名(Protocol)均以大写字母开头,多单词组合时,后面的单词首字母大写.   类,接口名必须是有意义的,切忌使用中文拼音命名.另外所有类都要加标致前缀:“O ...

  3. NOI2019赛前两周被吊打记录

    7.1 T1看了半天发现会个暴力FWT,然后突然返发现随便容斥一下就好了 T2猜了个只有13和23的,结果打个表发现伪了,然后标号不只一种连搜索都写错了,也没想过可以轮廓线dp,菜哭了o(╥﹏╥)o ...

  4. 2019年12月12日英语学习-Will I Or Won't I ?

    这节英语课上的内容没记住多少东西,觉得这个主题太枯燥了,不过整堂课和外教沟通交流还是不错的,因为这节课就我一个学生.给我了充分的机会去张嘴交流互动. 也没记住什么东西,不知道写什么.只记住将要决定做某 ...

  5. NX二次开发-UFUN将工程图中的点坐标映射到建模绝对坐标UF_VIEW_map_drawing_to_model

    #include <uf.h> #include <uf_ui.h> #include <uf_draw.h> #include <uf_view.h> ...

  6. 剑指offer——11矩阵覆盖

    题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法?   题解: 使用递归或者动态规划,明显,递归没有动态规划优 ...

  7. java could not open `C|D|E|F:\jre\lib\amd64\jvm.cfg' 解决方案与原因

    因为安装了 jdk 后发现有多个 jre 一个是安装目录下的. 还有一个是安装后的自动安装的注意路径都不一样. 由于本人有强迫症所有不能容忍有两个 jre 目录的存在,所以果断删除了 D 盘下的.谨慎 ...

  8. 关于JQuery Ajax 跨域 访问.net WebService

    关于这个 jQuery Ajax跨域访问 WebService 前天整了好几个小时没整明白 今天再看一下 结果突然就顿悟了 1.建一个空webApplication --添加--新建项--web服务( ...

  9. Android笔记之Fragment中创建ViewModel的正确方式

    之前一直都是这么写的 pageViewModel = ViewModelProviders.of(this).get(PageViewModel.class); //参数this是当前fragment ...

  10. 【POJ】1860 Currency Exchange

    真是气skr人..没把d[]换成double...de了一上午的bug// 记得用G++提交啊 题目链接:http://poj.org/problem?id=1860 题意:告诉你n个点,m条路.起始 ...