Hillan and the girl

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)

Problem Description
“WTF!
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.
 
Input
The first line contains an integer T(1≤T≤10,000)——The number of the test cases.
For each test case, the only line contains two integers n,m(1≤n,m≤10,000,000) with a white space separated.
 
Output
For each test case, the only line contains a integer that is the answer.
 
Sample Input
2
1 2333333
10 10
 
Sample Output
0
33

Hint

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).

 
Source
                  min(n,m) min(n/k,m/k)
思路:首先推到∑     ∑ mu(d)  * [n/k/d] * [m/k/d];  k为完全平方数;
      k=1   d=1
   令T=k*d;
   可得:
      min(n,m)                    
      ∑   [n/T] * [m/T]  ∑   mu(T/k)  ;
      T          k|T
      令gg数组等于 ∑   mu(T/k)  相当于原来的mu函数;
             k|T
      和原来一样分块即可;
#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 ;
}

最新文章

  1. 基于SS5服务端的Socks5客户端
  2. 韩国&quot;被申遗&quot; (转自果壳)
  3. 1.把二元查找树转变成排序的双向链表[BST2DoubleLinkedList]
  4. iOS-Runtime-Headers
  5. JQuery validate验证 自定义
  6. C++学习44 格式化输出,C++输出格式控制
  7. Labview实现脉波调制( PDM )
  8. poj 1236 Network of Schools(又是强连通分量+缩点)
  9. Flash正则例子
  10. 数据库关于group by 两个或以上条件的分析
  11. 【伪一周小结(没错我一周就做了这么点微小的工作)】HDOJ-1241 Oil Deposits 初次AC粗糙版对比代码框架重构版
  12. .Net Core在X86上实现Interlocked.Increment(ref long)的方式
  13. Gradle实现自动打包,签名,自定义apk文件名
  14. ceph 问题处理
  15. WebSphere的jython编码的一个坑
  16. 4-Five-Youth
  17. YII创建应用
  18. 三个 CSS 预处理器(框架):Sass、LESS 和 Stylus
  19. 数据库中查询json 样式的值的sql语句
  20. 数据导入(二):MapReduce

热门文章

  1. Farm Tour(最小费用最大流模板)
  2. 记录--java获取网络资源(图片、音频等)保存本地
  3. [IOI2018]狼人
  4. yum命令的实例
  5. selenium屏蔽谷歌浏览器弹出的通知
  6. Vue-router2.0学习笔记(转)
  7. tomcat8.5.11的manager页面总是提示403的问题
  8. php 数组 高效随机抽取指定条记录的算法
  9. C# partial 关键字
  10. point-to-point(点对点) 网口