http://www.lydsy.com/JudgeOnline/problem.php?id=2820

Description

神犇YY虐完数论后给傻×kAc出了一题给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对kAc这种
傻×必然不会了,于是向你来请教……多组输入

Input

第一行一个整数T 表述数据组数接下来T行,每行两个正整数,表示N, M

Output

T行,每行一个整数表示第i组数据的结果

Sample Input

2
10 10
100 100

Sample Output

30
2791

————————————————————————

看hzw的博客吧,他讲的蛮清楚的……

我主要是没有可以写数学公式的东西……

http://hzwer.com/6142.html

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=;
int miu[N],su[N],sum[N];
ll f[N];
bool he[N];
void Euler(int n){
int tot=;
miu[]=;
for(int i=;i<=n;i++){
if(!he[i]){
su[++tot]=i;
miu[i]=-;
}
for(int j=;j<=tot;j++){
if(i*su[j]>=n)break;
he[i*su[j]]=;
if(i%su[j]==){
miu[i*su[j]]=;break;
}
else miu[i*su[j]]=-miu[i];
}
}
for(int i=;i<=tot;i++){
int p=su[i];
for(int j=;j*p<=n;j++)f[j*p]+=miu[j];
}
for(int i=;i<=n;i++)f[i]+=f[i-];
return;
}
int main(){
Euler();
int t;
scanf("%d",&t);
while(t--){
int a,b;ll ans=;
scanf("%d%d",&a,&b);
if(a>b)swap(a,b);
for(int i=,j;i<=a;i=j+){
j=min(a/(a/i),b/(b/i));
ans+=(f[j]-f[i-])*(a/i)*(b/i);
}
printf("%lld\n",ans);
}
return ;
}

最新文章

  1. python嵌套函数、闭包与decorator
  2. jQuery 中时间显示的模版
  3. Sunny-Code Beta版总结会议
  4. git项目开发版本控制实践
  5. 【HDU 1003】 Max Sum
  6. YII2.0 secruity
  7. 在shell脚本中使用函数
  8. pic/at89c2051 programmer
  9. vmware workstation下的虚拟Linux通过NAT模式共享上网
  10. POJ 1185 状态压缩DP(转)
  11. codevs 1047 邮票面值设计
  12. 神经网络和BP算法推导
  13. 【Android】android图片轮播
  14. ios文本框基本使用,以及所有代理方法的作用
  15. CWnd *和HWnd转换
  16. 一个操作cvs格式的c++类
  17. ipython notebook 安装
  18. TIJ -- 任务间使用管道进行输入/输出
  19. 基于CentOS搭建VNC远程桌面服务
  20. LeetCode69.x的平方根

热门文章

  1. 「知识学习」二分图的最大匹配、完美匹配和匈牙利算法(HDU-2063)
  2. 前端开发工程师 - 01.页面制作 - 第4章.CSS
  3. 关于java中“使用了未经检查或不安全的操作、有关详细信息,请使用 ——Xlint:unchecked重新编译”
  4. JDK源码分析:Integer.java部分源码解析
  5. Y460蓝牙键盘无法连接问题解决
  6. Kali渗透测试工具-netcat
  7. 自测之Lesson6:文件I/O
  8. 团队Beta阶段事后分析
  9. 第一次课堂作业---circle
  10. eg_3