Mathematically Hard LightOJ-1007(欧拉定理+前缀和)
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(欧拉定理+前缀和)的更多相关文章
- Lightoj 1007 - Mathematically Hard
1007 - Mathematically Hard PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 6 ...
- lightoj 1007 - Mathematically Hard 欧拉函数应用
题意:求[a,b]内所有与b互质个数的平方. 思路:简单的欧拉函数应用,由于T很大 先打表求前缀和 最后相减即可 初次接触欧拉函数 可以在素数筛选的写法上修改成欧拉函数.此外本题内存有限制 故直接计算 ...
- lightoj 1007
预先处理好phi数组和前缀和,水题. #include<cstdio> #include<string> #include<cstring> #include< ...
- 1007 - Mathematically Hard
1007 - Mathematically Hard PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 6 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- lightoj 1145 - Dice (I)(dp+空间优化+前缀和)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1145 题解:首先只要是dp的值只和上一个状态有关系那么就可以优化一维,然后这题 ...
- A New Function(LightOJ 1098)积性函数前缀和的应用
题意:要求对于1~n,每个数的约数(不包括1和其本身)的和. 题解:由于题目数据有2*10^9之大,因而不能直接暴力.需要考虑积性函数的特性,由于必定有重复的约数出现,因而可以对重复约数所在的区间进行 ...
- Trailing Zeroes (II) LightOJ - 1090(预处理+前缀和)
求C(n,r)*p^q的后缀零 考虑一下 是不是就是求 10^k*m 的k的最大值 而10又是由2 和 5 组成 所以即是求 2^k1 * 5^k2 * m1 中k1和k2小的那一个数 短板效应嘛 ...
- LightOj 1289 - LCM from 1 to n(LCM + 素数)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1289 题意:求LCM(1, 2, 3, ... , n)%(1<<32), ...
随机推荐
- 【CUDA 基础】5.4 合并的全局内存访问
title: [CUDA 基础]5.4 合并的全局内存访问 categories: - CUDA - Freshman tags: - 合并 - 转置 toc: true date: 2018-06- ...
- Java的消息机制
Java消息机制 1.问: 什么是 Java 消息服务?答: Java 消息服务(Java Message Service,JMS) API 是一个用于访问企业消息传递系统的 API.是 Java 2 ...
- 空指针/0/NULL
空指针/0/NULL 空指针是一个被赋值为0的指针,在没有被具体初始化之前,其值为0. NULL 是一个标准规定的宏定义,用来表示空指针常量. #define NULL 0 或者 #define ...
- typescript简单的应用
简单来说typescript就是新增一下方法,以及增加类型判断 一.普通的类型判断 1.布尔类型(boolean) let isDone: boolean = false let createdByB ...
- Flutter移动电商实战 --(10)使用FlutterSwiper制作轮播效果
1.引入flutter_swiper插件 flutter最强大的siwiper, 多种布局方式,无限轮播,Android和IOS双端适配. 好牛X得介绍,一般敢用“最”的一般都是神级大神,看到这个介绍 ...
- Flutter移动电商实战 --(2)建立项目和编写入口文件
1.创建项目 采用AndroidStudio构建本项目,FIle>New>New Flutter Project… 创建后的项目如下图所示: 我们着重需要注意一下几个文件夹,其他的暂时不用 ...
- Centos7 部署.Net Core+Nginx+Supervisor
1.安装.Net Core SDK 1.1. 在安装.NET之前,您需要注册Microsoft密钥,注册产品存储库并安装所需的依赖项.这只需要每台机器完成一次. sudo rpm -Uvh https ...
- linux如何离线加载docker镜像?
1. 在已经部署了镜像的机器上获取镜像 1.1 获取镜像名 docker images 1.2 打包选中对应的镜像 docker save <image_name> -o <imag ...
- jQuery常用Method-API
目的:对web页面(HTML/JSP/XML)中的任何标签,属性,内容进行增删改查 (1)DOM简述与分类 (A)DOM是一种W3C官方标准规则,可访问任何标签语言的页面(HTML/JSP/XML) ...
- 深度学习之Faster-R-CNN
哎!还是看大神博客吧 https://blog.csdn.net/liuxiaoheng1992/article/details/81843363