hdu 5663 Hillan and the girl 莫比乌斯反演
Hillan and the girl
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
While everyone has his girl(gay) friend, I only have my keyboard!”
Tired of watching others' affair, Hillan burst into scream, which made
him decide not to hold it back.
“All right, I am giving you a
question. If you answer correctly, I will be your girl friend.” After
listening to Hillan, Girl replied, “What is the value of ∑ni=1∑mj=1f(i,j), where f(i,j)=0 if gcd(i,j) is a square number and f(i,j)=1 if gcd(i,j) is not a square number(gcd(i,j) means the greatest common divisor of x and y)?”
But Hillan didn't have enough Intelligence Quotient to give the right answer. So he turn to you for help.
For each test case, the only line contains two integers n,m(1≤n,m≤10,000,000) with a white space separated.
1 2333333
10 10
33
In the first test case, obviously $f\left(i,j\right)$ always equals to 0, because $i$ always equals to 1 and $\gcd\left(i,j\right)$ is always a square number(always equals to 1).
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
#define pi 4*atan(1)
const int N=1e7+,M=1e7+,inf=1e9+,mod=1e9+;
int mu[N], p[N], np[N], cnt, sum[N];
ll gg[N];
void init() {
mu[]=;
for(int i=; i<N; ++i) {
if(!np[i]) p[++cnt]=i, mu[i]=-;
for(int j=; j<=cnt && i*p[j]<N; ++j) {
int t=i*p[j];
np[t]=;
if(i%p[j]==) { mu[t]=; break; }
mu[t]=-mu[i];
}
}
for(int i=;i*i<N;i++)
{
for(int t=i*i;t<N;t+=(i*i))
sum[t]+=mu[t/i/i];
}
for(int i=;i<N;i++)
gg[i]=gg[i-]+sum[i]; }
ll getans(ll b,ll d)
{
if(b>d)swap(b,d);
ll ans=;
for(ll L=,R=;L<=b;L=R+)
{
R=min(b/(b/L),d/(d/L));
ans+=(b/L)*(d/L)*(gg[R]-gg[L-]);
}
return ans;
}
int main()
{
int T;
init();
scanf("%d",&T);
while(T--)
{
ll b,d;
scanf("%I64d%I64d",&b,&d);
printf("%I64d\n",(b*d)-getans(b,d));
}
return ;
}
hdu 5663 Hillan and the girl 莫比乌斯反演的更多相关文章
- HDU 5663 Hillan and the girl (莫比乌斯反演 + 分块)
题意:给定n,m,求,其中F(x)=0,,如果x是完全平方数,否则是1. 析: 由于按照题意的F,不好筛选,所以我们反过来,F(x),x是平方数,就是1,否则是0. 这个是可以预处理出来的,可以用筛选 ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解
题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...
- HDU 2841 Visible Trees(莫比乌斯反演)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...
- HDU 5321 Beautiful Set (莫比乌斯反演 + 逆元 + 组合数学)
题意:给定一个 n 个数的集合,然后让你求两个值, 1.是将这个集合的数进行全排列后的每个区间的gcd之和. 2.是求这个集合的所有的子集的gcd乘以子集大小的和. 析:对于先求出len,len[i] ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 4746 Mophues (莫比乌斯反演应用)
Mophues Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327670/327670 K (Java/Others) Total ...
- HDU 4746 Mophues【莫比乌斯反演】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4746 题意: 1≤x,y≤n , 求gcd(x,y)分解后质因数个数小于等k的(x,y)的对数. 分 ...
- hdu.5212.Code(莫比乌斯反演 && 埃氏筛)
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
随机推荐
- hdu1829(A Bug's Life)
题目链接:传送门 题目大意:有n个昆虫,有m组关系,接下来m行表示两个昆虫性别不同,问是否有矛盾情况(同男同女) 题目思路:并查集的高级应用,开两倍数组大小,后n个数组表示和当前昆虫不同性别的集合 # ...
- 【BZOJ4849】[Neerc2016]Mole Tunnels 模拟费用流
[BZOJ4849][Neerc2016]Mole Tunnels Description 鼹鼠们在底下开凿了n个洞,由n-1条隧道连接,对于任意的i>1,第i个洞都会和第i/2(取下整)个洞间 ...
- UESTC 482 Charitable Exchange(优先队列+bfs)
Charitable Exchange Time Limit: 4000/2000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- 【转】mysql利用init-connect增加访问审计功能
mysql的连接首先都是要通过init-connect初始化,然后连接到实例. 我们利用这一点,通过在init-connect的时候记录下用户的thread_id,用户名和用户地址实现db的访问审计功 ...
- yum命令的实例
1) 自定义yum仓库:createrepo 2) 自定义repo文件 3) 使用yum命令安装httpd软件包(在这里需要强调一点,本身执行yum.repos.d时,文件里面是有自带的yum源的,需 ...
- Python学习笔记1_初识Python
一.Python的发展 1.CNRI时期:CNRI是自助Python发展初期的重要单位,Python1.5版之前的成果大部分都在此时期内完成 2.BeOpen时期:Guido van Rossum与B ...
- C#对Excel中指定一列或一行实现隐藏或显示!
C#对Excel中指定一列或一行实现隐藏或显示!不会,求指导!
- 【LeetCode】 子字符串思路
在一些求字串含有固定字符最短串,含有不同字符最长子串等问题中,利用 vector<int> map(128, 0)可以解决 题一:最短给定子串 Minimum Window Substri ...
- typeset的常见用法
typeset用于设置变量属性,如大小写,宽度,左右对齐等都可以用typeset来控制, 当用typeset改变一个变量的属性时,这种改变是永久的,下面以ksh为例,演示typeset的几种典型用法 ...
- Linux 基础一---操作系统&常用命令
UNIX是一个计算机操作系统,一个用来协调.管理和控制计算机硬件和软件资源的控制程序. 1.UNIX操作系统的特点:多用户和多任务: a) 多用户表示在同一时刻可以有多个用户同时使用UNIX操作系统而 ...