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. Prime Path (POJ - 3126 )(BFS)

    转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82697622     作者:Mercury_Lc 题目链接 题意:就是给你一个n, ...

  2. HDU 2177 —— (威佐夫博弈)

    威佐夫博弈奇异态(必败态)的条件是a[k]=[k*(sqrt(5.0)+1.0)/2.0].暴力找出必败态即可. 代码如下: #include <stdio.h> #include < ...

  3. 牛券Cow Coupons

    USACO12FEB 久违的奶牛题. 题意: FJ准备买一些新奶牛,市场上有 $ N $ 头奶牛 $ (1 \leq N \leq 50000) $ ,第i头奶牛价格为 $ P_i (1 \leq P ...

  4. crobtab

    在使用node-cron包,作者在issue建议使用 https://crontab.guru/ 测试使用定时任务 发现一个问题 https://crontab.guru/#0_23_11-12,18 ...

  5. 短信的内容提供者Uri和短信表结构

    * sms表 * address :手机号码 * date :收发短信的时间 * read :短信的阅读状态 1,已读 0,未读 * type :收发短信的类型 1,收到短信 2,发出短信 * bod ...

  6. 发送Http请求调用webService

    如果调用WebService的不是在.NET中,无法直接添加web引用,那怎么调用webservice. 有两种方式 第一种方式:GET方式 string strUrl = "http:// ...

  7. Win10设置文件夹权限报错-(提示:无法枚举容器中的对象 访问被拒绝)

    一.右击文件 选择“属性”-“安全”-“高级”,如下图 二.查看哪个用户的权限是:“完全控制”,我这里是“SYSTEM”用户. 三.选择顶部的 “更改-“高级”-“立即查找”,然后选择管理员账户“SY ...

  8. PHP拼多多模式,砍价免费拿商品算法

      我12年开始做网站,对拼多多关注两三年了,一直对他们的拉新模式很感兴趣,下面我对砍价送礼品的算法跟大家分享下. 拼多多砍价免费拿商品有几个核心的东西: 1.需要拉新多人给商品,这个是直接在数据库配 ...

  9. Nodejs源码系列

    一直想着看Nodej源码,断断续续的折腾了一下,但总串不起来,太久不看又忘记.决心每天看一点,特地记录在这里,作为逼迫自己的动力. 2019/09/22 一.源码编译 之前在电脑上了下源码,源码目录截 ...

  10. 新导入的项目目录结构不对(main目录)

    Eclipse导入一个maven项目,碰到一个这样的错误:项目的包路径编程了main.java开头的,而java代码中的pakge却是com开头的,如图. 导致项目编译不通过 错误提示: 解决办法: ...