1007 - Mathematically Hard
Time Limit: 2 second(s) Memory Limit: 64 MB

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

Output for Sample Input

3

6 6

8 8

2 20

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  using the formula

欧拉函数打表。抄的大白书上的板子。一开始没看note  自己yy筛法。果然很弱智,题目已经给了Note了,眼瞎。

/* ***********************************************
Author :guanjun
Created Time :2016/6/10 19:35:28
File Name :1007.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 5000100
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int phi[maxn];
ull sum[maxn];
void phi_table(int n){
for(int i=;i<=n;i++)phi[i]=;
phi[]=;
for(int i=;i<=n;i++)if(!phi[i]){
for(int j=i;j<=n;j+=i){
if(!phi[j])phi[j]=j;
phi[j]=phi[j]/i*(i-);
}
}
sum[]=;
for(int i=;i<=maxn;i++){
sum[i]=sum[i-]+(ull)phi[i]*phi[i];
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
phi_table(maxn);
int T,a,b;
cin>>T;
for(int t=;t<=T;t++){
scanf("%d%d",&a,&b);
printf("Case %d: %llu\n",t,sum[b]-sum[a-]);
}
return ;
}

Lightoj 1007 - Mathematically Hard的更多相关文章

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

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

  2. 1007 - Mathematically Hard

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

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

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

  4. lightoj 1007

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

  5. LightOj1007 - Mathematically Hard(欧拉函数)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1007 题意:给你两个数a和b,求他们之间所有数的欧拉值得平方和; a and b (2 ...

  6. SCNU 2015ACM新生赛初赛【1007. ZLM的扑克牌】解题报告

            题目链接详见SCNU 2015新生网络赛 1007. ZLM的扑克牌 .         其实我在想这题的时候,还想过要不要设置求最小的排列,并且对于回文数字的话,可以把扑克牌折起来( ...

  7. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  8. LightOj 1298 - One Theorem, One Year(DP + 欧拉)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...

  9. PKU 1007

    题名:DNA排序 题意:给定字符串长度.个数,计算每个字符串的逆序数,然后从大到小排列,有兴趣的可以去看下原题. 计算字符串逆序数,然后排序,这里使用了快速排序算法,string释放的时候竟然有问题, ...

随机推荐

  1. shell for mysql backup in linux

    今天上班只有一台linux系统,就学着在linux上写了个脚本,没啥技术含量 省得每天敲代码备份 没有设置自动备份时间,这里可以参照 http://www.th7.cn/db/mysql/201305 ...

  2. Web安全解决方案

    什么是 .NET Framework 安全性? .NET Framework 提供了用户和代码安全模型,允许对用户和代码可以执行的操作进行限制.要对基于角色的安全性和代码访问安全性进行编程,可以从 S ...

  3. 【01】sass基础信息:

    [01]基础信息:   2016年4月16日   最新版本:3.4.22   官网:http://sass-lang.com/(下图)       CSStoSCSS 网站:http://css2sa ...

  4. 大数据学习——yum安装tomcat

    https://www.cnblogs.com/jtlgb/p/5726161.html 安装tomcat6 yum install tomcat6 tomcat6-webapps tomcat6-a ...

  5. POJ-1861,Network,最小生成树水题,,注意题面输出有问题,不必理会~~

    Network Time Limit: 1000MS   Memory Limit: 30000K          Special Judge http://poj.org/problem?id=1 ...

  6. php5.5编译安装

    系统环境:centos6.5PHP包:5.5.15https://wiki.swoole.com/wiki/page/177.html下载 PHP 源码包wget http://cn2.php.net ...

  7. [USACO10FEB]慢下来Slowing down

    线段树  树的dfs序 来自   洛谷 P1982   的翻译 by  GeneralLiu 来自 jzyz 的翻译 %mzx 线段树  dfs序 数据结构的应用 “数据结构 是先有需求 再有应用” ...

  8. [luoguP2015] 二叉苹果树(DP)

    传送门 貌似是个树形背包... 好像吧.. f[i][j]表示节点i选条边的最优解 #include <cstdio> #include <cstring> #include ...

  9. java web 项目常用框架

    java框架实在是太多了,网上一搜索一大箩筐,根本就了解不到什么. 我还是以我的经验来说一下j2ee的框架. 1.首先力推struts2框架,这是最经典的框架(可以说没有“之一”).可以帮你快速搭建出 ...

  10. 用DW制作简单的浮动广告

    原文发布时间为:2008-11-08 -- 来源于本人的百度文章 [由搬家工具导入] 浮动广告可以用层和时间轴结合做出,先选择你的dreamweaver“窗口”,然后从“窗口”菜单中选择“时间轴”,时 ...