hdu4497 GCD and LCM
2015-07-10 17:30
387 查看
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
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, print one line with the number of solutions satisfying the conditions above.
[align=left]Sample Input[/align]
2 6 72 7 33
[align=left]Sample Output[/align]
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; }
相关文章推荐
- 设计模式读书笔记:Chain of Responsibility(责任链)
- csharp: Export DataSet into Excel and import all the Excel sheets to DataSet
- Python中and和or
- html页面加载和解析流程
- Node.js执行存储过程
- matlab控制运算精度函数digits(A)和vpa(B)的使用方法
- 优酷、YouTube、Twitter及JustinTV视频网站架构设计笔记
- 使用Jquery解析Json基础知识
- [leetcode] 131.Palindrome Partitioning
- JUnit入门
- ViewAnimator 之(一) ImageSwitcher和TextSwitcher
- 开发者所需要知道的 iOS 9 SDK 新特性
- iOS开发--数据存取
- could not build module 'Foundation' ios QRCodeGenerator libqrencode
- 暑假集训之开始学习
- webView介绍
- 纯虚函数
- Android主线程的消息系统(Handler\Looper)
- 知名互联网公司网站架构图
- 关于 in.readLine() 卡死的有关问题