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 ...
随机推荐
- 摄像机互联网直播之EasyCloud云平台与EasyNVS云端管控的全局对比
背景分析 近期,Easy系列推出了EasyNVS,在功能上也是可以满足将内网的视频直播转发到公网,再由公网进行视频流的分发. 听起来和EasyCloud功能上是冲突的,其实两者之间的差别还是存在的,本 ...
- getParameterMap的使用
就是前端提交到Servlet或者Action里面的参数Map哈,如果你是以表单提交,那么request.getParameterMap()中将包含你表单里面所有input标签的数据,以其name为ke ...
- 新手之使用git
本篇博客针对不会Git的小童鞋,大神们可以绕过,错误之处谢谢指正: 关于GitHub的强大此处不在说明,知道GitHub也有一段时间了,但是一直苦于不会使用. 本篇文章介绍的是如何将工程代码托管到上面 ...
- C#动态删除控件
foreach (Control var in panel.Controls) { if (var is Billet) { panel.Controls.Remove(var); var.Dispo ...
- CSS3边框border-radius
一.官方解释 设置或检索对象使用圆角边框.提供2个参数,2个参数以“/”分隔,每个参数允许设置1~4个参数值,第1个参数表示水平半径,第2个参数表示垂直半径,如第2个参数省略,则默认等于第1个参数. ...
- Django的models方法返回值异常,待解决
class BookInfo(models.Model): #创建书本信息类,继承models.Model booktitle=models.CharField(max_length=20) book ...
- VMware下安装CentOS
开始安装VMware 下载CentOS 7.4 镜像 可以去阿里云的镜像站下载:https://opsx.alibaba.com/mirror 来到主页面,点击centos 选择 7.4 版本 选择镜 ...
- 如何用云存储和CDN加速网站图片视频、阿里云OSS的使用(转)
总有人说阿里云主机带宽小,那只是因为你还停留在单机架构上. 阿里的架构设计,云主机主要用来跑程序的,附件的存储和访问主要靠OSS. 有人又会说了,OSS按存储费+流量双重计费伤不起,只是你不知道OSS ...
- python 文件格式为 txt 转换成 csv 格式
1 txt 文件的读取 open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=Tr ...
- node+npm安裝配置
控制臺輸入node 根據提示安裝 sudo apt-get install -g npm配置淘寶源 npm config set registry https://registry.npm.tao ...