Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x, y, z) = L? 
Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the least common multiple of x, y and z. 
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.

InputFirst line comes an integer T (T <= 12), telling the number of test cases. 
The next T lines, each contains two positive 32-bit signed integers, G and L. 
It’s guaranteed that each answer will fit in a 32-bit signed integer.OutputFor each test case, print one line with the number of solutions satisfying the conditions above.Sample Input

2
6 72
7 33

Sample Output

72
0
昨天想了好久都没想通,,今天早上灵感突然的就来了。
题解:首先我们要理解,最大公约数和最小公倍数的关系,比如说a*b=gcd(a,b)*lcm(a,b) 如果两边同时除以gcd的平方 lcm%gcd==0 所以,如果lcm%gcd!=0的话 应该不会存在关系
第二: 我们让gcd和lcm同时除以gcd可得新的gcd和lcm gcd=1 lcm=lcm/gcd 他们分别是x/gcd y/gcd z/gcd的gcd和lcm 因此我们只要分解lcm/gcd就可以了
第三:lcm=p1^max(a1,a2,a3)*p2^max(b1,b2,b3)....
    x0=p1^a1....
    y0=p1^b1...
    z0=p1^c1...
假如说a1 b1 c1 都不为0,那么他们的最大公约数不会是1,因此他们三者中至少有一个为0 ,最多有两个为0(3个为0的情况不会出现,p1一定是其中一个数的只质因子)由于是有顺序的
(0,a1,c1)加入最多的为a1那么C1的取值为0--a1我们先考虑为0和相等的情况 有a1-1中,,变换一下顺序一共有6(a1-1)种,还有(0,0,a1)和(0,a1,a1)我们没考虑共3+3种因此共有6(a1-1)+6种
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1e6+;
bool p[N]={,,};
int prime[N];
int k=;
void pre(){
k=;
for(int i=;i<N;i++){
if(p[i]==){
prime[k++]=i;
for(int j=i+i;j<=N;j+=i){
p[i]=;
}
}
}
} int main(){
pre();
int t;
cin>>t;
while(t--){
int n,m;
scanf("%d%d",&n,&m);
if(m%n!=){//最大公约数应该是最下公倍数的系数比如说a*b=gcd*lcm两边同时除以gcd的平方,so lcm%gcd=0
puts("");
continue ;
}
int x=m/n;
int sum=;
for(int i=;i<k&&prime[i]<x;i++){
if(x%prime[i]==){
int ans=;
while(x%prime[i]==){
ans++;
x=x/prime[i];
}
sum*=*ans;
}
}
if(x>) sum*=;
cout<<sum<<endl; } return ;
}
												

最新文章

  1. JavaScript中严格模式&quot;use strict&quot;;需注意的几个雷区:
  2. C# 直接调用vs 委托vs动态调用vs动态类型vs反射,最佳性能测试
  3. 在公司内网上创建自己的 OSM.Planet 街道级别地图服务器及其客户端程序
  4. [转]DB2时间类函数
  5. JavaScript笔记三两个
  6. ffmepg 指定RTSP网络连接模式UDP还是TCP
  7. google域名邮箱申请 gmail域名邮箱申请(企业应用套件)指南
  8. iOS实现地图半翻页效果--老代码备用参考
  9. 【BZOJ 1597】 [Usaco2008 Mar]土地购买 (斜率优化)
  10. 【巧妙消维DP】【HDU2059】龟兔赛跑
  11. UITabBarItem
  12. IO流的总结
  13. 付款页面DEMO
  14. Confluence, JIRA, Fisheye
  15. Unix时间戳转换成C#中的DateTime
  16. Ant学习总结2
  17. Java经典编程题50道之五十
  18. jQuery 文档操作方法 (四)
  19. hihocoder 1496 寻找最大值
  20. thinkphp验证器

热门文章

  1. CTF_WriteUp_HTTP基本认证(Basic access authentication)
  2. Centos 8 安装 Consul-Template
  3. SpringBoot 集成多数据源
  4. centos7中安装mysql
  5. CyclicBarrier是如何成为一个&quot;栅栏&quot;的
  6. STM32F103ZET6的中断管理
  7. for、forEach、for-in与for-of的区别
  8. Golang入门(4):并发
  9. 痞子衡嵌入式:走进二维码(QR Code)的世界(1)- 引言
  10. ACL,NAT的使用