Description

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 from a 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

6

8 8

2

Sample Output

Case 1: 4

Case 2: 16

Case 3: 1237

Note

Euler's totient function  applied to a positive integer ø(n) is defined to be the number of positive integers less than or equal to ø(n) that

are relatively prime to ø(n).  is read "phi of n."Given the general prime factorization of  , one can compute ø(n)using the formula

在数论中,对正整数n,欧拉函数  是小于或等于n的正整数中与n互质的数的数目,对欧拉函数打表;

注意 :long long 需要用无符号型;

代码如下:

#include<iostream>
#include<cstdio>
using namespace std;
typedef unsigned long long ll;
const int maxx=;
ll a[maxx];
void init()
{
for(int i=; i<maxx; i++)
a[i]=i;
for(int i=; i<maxx; i++)
{
if(a[i]==i)
{
for(int j=i; j<maxx; j+=i)
a[j]=a[j]/i*(i-);
}
}
for(int i=; i<maxx; i++)
a[i]=a[i]*a[i]+a[i-];
}
int main()
{
init();
int t,Case=;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
printf("Case %d: ",++Case);
cout<<a[m]-a[n-]<<endl;
}
return ;
}

Mathematically Hard LightOJ-1007(欧拉定理+前缀和)的更多相关文章

  1. Lightoj 1007 - Mathematically Hard

    1007 - Mathematically Hard    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 6 ...

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

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

  3. lightoj 1007

    预先处理好phi数组和前缀和,水题. #include<cstdio> #include<string> #include<cstring> #include< ...

  4. 1007 - Mathematically Hard

    1007 - Mathematically Hard    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 6 ...

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

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

  6. lightoj 1145 - Dice (I)(dp+空间优化+前缀和)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1145 题解:首先只要是dp的值只和上一个状态有关系那么就可以优化一维,然后这题 ...

  7. A New Function(LightOJ 1098)积性函数前缀和的应用

    题意:要求对于1~n,每个数的约数(不包括1和其本身)的和. 题解:由于题目数据有2*10^9之大,因而不能直接暴力.需要考虑积性函数的特性,由于必定有重复的约数出现,因而可以对重复约数所在的区间进行 ...

  8. Trailing Zeroes (II) LightOJ - 1090(预处理+前缀和)

    求C(n,r)*p^q的后缀零 考虑一下 是不是就是求 10^k*m  的k的最大值 而10又是由2 和 5 组成  所以即是求 2^k1 * 5^k2 * m1 中k1和k2小的那一个数 短板效应嘛 ...

  9. LightOj 1289 - LCM from 1 to n(LCM + 素数)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1289 题意:求LCM(1, 2, 3, ... , n)%(1<<32), ...

随机推荐

  1. Pap.er 模仿 - 第二天

    最后更新:2017-12-19 在第一天中, 我们完成了项目的基本设置.隐藏Dock.显示和隐藏Popover等操作,接下来的这章中, Pap.er将会去搭建对应 UI. 一.设置Popover对应颜 ...

  2. 发布jar项目到maven仓库

    在要发布的项目pom文件中添加配置: <distributionManagement> <repository> <id>releases</id> & ...

  3. 【软件工程】Beta冲刺(3/5)

    链接部分 队名:女生都队 组长博客: 博客链接 作业博客:博客链接 小组内容 恩泽(组长) 过去两天完成了哪些任务 描述 新增数据分析展示等功能API 服务器后端部署,API接口的beta版实现 展示 ...

  4. RHEL防火墙命令

    firewall-cmd --state 查看防火墙状态 firewall-cmd --reload #重启firewall systemctl stop firewalld.service #停止f ...

  5. asp.net webAPI

    Get: 1.Get参数传递的本质是url字符串拼接:2.url字符串长度受限制:3.Get参数传递在Http请求头部传递,而不支持Request-Body传递:4.Get类型的方法支持参数为基本类型 ...

  6. 2.基于AOP自定义注解Annotation的实现

    上一篇中分析了AOP的实现原理, 总结为: 判断对象是否需要被代理?@Aspect注解的实现是根据切入点表达式 代理之后需要做什么,就是那些通知,本质上是实现了MethodInterceptor的拦截 ...

  7. Nginx优化之服务性能优化

    优化Nginx服务的worker进程个数 修改nginx主配置文件 worker_processes 1; #指定了Nginx要开启的进程数,结尾数字就是进程个数 Nginx有Master进程和wor ...

  8. win10下检查nvidia显卡支持的cuda版本

    1.首先将[C:\Program Files\NVIDIA Corporation\NVSMI]添加至系统环境变量[path]中: 2.在powershell中使用命令[nvidia-smi],即可看 ...

  9. python3.6 列表推导式学习

    a=[i for i in range(1,10) if i%2==0]print(a)c=[(x,y) for x in range(5) if x%2==0 for y in range(5) i ...

  10. js对象和jQuery对象相互转换

    (1)什么是js对象及代码规则 就是使用js-API,即Node接口中的API或是传统JS语法定义的对象,叫做js对象 js代码规则----divElement var divElement = do ...