hdu4497 GCD and LCM
来源:互联网 发布:安卓graviboard软件 编辑:程序博客网 时间:2024/06/05 17:50
GCD and LCM
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1460 Accepted Submission(s): 653
Problem Description
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.
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.
Input
First 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.
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.
Output
For 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
给出gcd和lcm,求出满足条件的(x,y,z)这样的三元组有多少个。
把这些数分解因子,gcd因子个数是这些数里面拥有这个因子最少的数的因子个数,gcd因子个数是这些数里面拥有这个因子最多的数的因子个数。所以这里面先用lcm除以gcd,把除了之后得到的数分解因子,对于每个因子,假设个数是m,x,y,z里面一定有一个数的这个因子个数是m,一个数因子个数为m,剩下一个在0到n之间。因此对于这个因子,三个数的组合有(m-1)*6+6种。
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<stack>#include<map>#include<set>#include<algorithm>#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long LL;const int MAXN=300010;const int SIZE=4096;const int INF=0x3f3f3f3f;int T;LL G,L;int main(){ freopen("in.txt","r",stdin); scanf("%d",&T); while(T--){ scanf("%lld%lld",&G,&L); if(L%G!=0||L<G){ printf("0\n"); continue; } LL n=L/G; LL sq=sqrt(n)+1; int ans=1; for(LL i=2;i<=n&&i<=sq;i++){ int m=0; while(n%i==0){ n/=i; m++; } if(m>0) ans*=(m-1)*6+6; } if(n>1) ans*=6; printf("%d\n",ans); } return 0;}
0 0
- hdu4497 GCD and LCM
- hdu4497 GCD and LCM
- hdu4497 lcm and gcd
- HDU4497 GCD and LCM
- HDU4497 GCD and LCM 数论 素数分解
- HDU4497:GCD and LCM(数论)
- hdu4497 GCD and LCM 容斥原理
- Hdu4497 GCD and LCM 素数筛法+分解质因数
- hdu4497——GCD and LCM(数论&容斥原理or排列组合)
- GCD and LCM
- hdu5341 Gcd and Lcm
- GCD and LCM Aizu
- The GCD and LCM
- gcd and lcm
- GCD and LCM HDU
- GCD and LCM
- GCD and LCM HDU
- GCD and LCM HDU
- ios6方向旋转问题
- Android Bander设计与实现 - 设计篇
- mongodb备份与恢复(下)—ttlsa教程系列之mongodb(九)
- rbac权限设计思路
- [leetcode] 132.Palindrome Partitioning II
- hdu4497 GCD and LCM
- JSP页面中预览本地图片
- 暑假期望和学习
- Light OJ 1049 - One Way Roads (暴力 or DFS)
- Redis_conf配置文件说明
- c++ 常量指针 const*const
- GRE写作必备句型
- ios 开发之获取手机的外网IP和内网IP
- Swift入坑--@selector