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. Rapid Object Detection using a Boosted Cascade of Simple Features 部分翻译

    Rapid ObjectDetection using a Boosted Cascade of Simple Features 使用简单特征级联分类器的快速目标检测 注:部分翻译不准处以红色字体给出 ...

  2. 【集训队作业2018】count

    CSP后第一发Blog. 这道题没有一下子过掉,开始还推出了错的结论.在错误的生成函数里绕了好久-- 很显然的转笛卡尔树,一个笛卡尔树对应一种序列.只要考虑一个笛卡尔树是否合法. 贪心地填数发现,从根 ...

  3. 发布web项目时,关于未能加载文件或程序集或它的某一个依赖项。拒绝访问的问题

    asp.net的程序是发布再iis上面的嘛,然后iis里面呢选中你的程序,在右边菜单有个编辑权限.然后添加权限Everyone.设置文件夹只读为否

  4. Linux 系统设置命令之ulimit

    定义 ulimit 用于限制 shell 启动进程所占用的资源,支持以下各种类型的限制:所创建的内核文件的大小.进程数据块的大小.Shell 进程创建文件的大小.内存锁住的大小.常驻内存集的大小.打开 ...

  5. Java线程之join

    简述 Thread类的join方法用来使main线程进入阻塞状态,进而等待调用join方法的线程执行,join有三个重载方法: public final void join() 使主线程进入阻塞状态, ...

  6. 白鹭引擎EUI做H5活动 巩固篇

    项目目录 上面这张图片是项目的目录结构,咋们一点一点来讲解: .wing:包括 Egret 项目的任务配置文件和启动配置文件. wingProperties.json:Egret Wing 项目配置文 ...

  7. AT3576 Popping Balls

    AT3576 Popping Balls 好题!一种以前没怎么见过的思路! %%ywy 以什么方式,什么位置统计本质不同的方案,才能不重不漏是处理所有计数问题的主心骨. 本题难以容斥.难以DP. 所以 ...

  8. JS判断开始时间不能大于检查结束时间

    //用来检验检查开始时间不能大于检查结束时间 function checkDate(date){ var startDate = $("#jcrwModel_rwfqsj").va ...

  9. ES6中的模板字符串使用方法

    传统的 JavaScript 语言,输出模板通常是这样写的. $('#result').append( 'There are <b>' + basket.count + '</b&g ...

  10. C++代码匈牙利命名规范

    一.类 除了异常类等个别情况(不希望用户把该类看作一个普通的.正常的类之情况)外,C++类/结构的命名应该遵循以下准则: C++类的命名    类的名称都要以大写字母“C”开头,后跟一个或多个单词.为 ...