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 ;
}

最新文章

  1. Java国际化(i18n)
  2. jQuery美化下拉菜单插件dropkick
  3. js控制滚动条平滑滚动到制定位置
  4. Android文本输入框(EditText)切换密码的显示与隐藏
  5. mysql awr v1.0.1发布
  6. 关于使用注解出现BeanCreationException或者NameNotFoundException的解决方法
  7. Apache的虚拟主机配置
  8. 如何用asp.net MVC框架、highChart库从sql server数据库获取数据动态生成柱状图
  9. Hello_IOS ios开发transform属性
  10. Thread.sleep(0)的意义
  11. X Shell 4配色方案[Solarized Dark]
  12. (转载) css实现小三角(尖角)
  13. 201521123105 第四周Java学习总结
  14. php垃圾回收
  15. linux下Tomcat 安装后执行startup.sh,出现– Cannot find …bin/catalina.sh
  16. 【PHP版】火星坐标系 (GCJ-02) 与百度坐标系 (BD-09ll)转换算法
  17. Visual Studio 2010 集成 SP1 补丁 制作 Visual Studio 2010 Service Pack 1 完整版安装光盘的方法
  18. @Transactional 可以写在 Controller 方法上面了
  19. Coding能力提升小技巧
  20. python常见面试题(mark)

热门文章

  1. [Shell] 分隔字符串为数组
  2. BZOJ1070: [SCOI2007]修车(最小费用最大流,思维)
  3. H5最佳格式
  4. 解决phpStorm使用vue提示&quot;Attribute v-xxx is not allowed here&quot;的问题
  5. python 二分查找代码
  6. apidoc 接口文档系统
  7. LightGBM新特性总结
  8. POJ 3083 -- Children of the Candy Corn(DFS+BFS)TLE
  9. ShockUtil振动工具类
  10. Docker监控:最佳实践以及cAdvisor和Prometheus监控工具的对比