Hdu 4497 GCD and LCM(数论)
来源:互联网 发布:boxers知乎 编辑:程序博客网 时间:2024/05/17 03:52
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4497
思路:x%G==0,y%G==0,z%G==0,所以L%G==0,若L%G!=0则一定无解。
考虑
L/G=(p1^t1)*(p2^t2)*......*(pn^tn)
x'=x/G=(p1^a1)*(p2^a2)*......*(pn^an)
y'=y/G=(p1^b1)*(p2^b2)*......*(pn^bn)
z'=z/G=(p1^c1)*(p2^c2)*.......*(pn^cn)
对于pi一定有max(ai,bi,ci)==ti,min(ai,bi,ci)==0,否则最大公约数pi^min(ai,bi,ci)*g>g 。
则对于每个pi有
0 0 ti 三种 ti ti ti 三种 0 ti 1--(ti-1) (ti-1)*6种,所以共有6*ti种。
#include<cstdio>#include<vector>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=1e6+50;int v[maxn];vector<int> prime;void prepare(){ for(int i=2; i<maxn; i++) { if(!v[i]) { prime.push_back(i); for(int j=2*i; j<maxn; j+=i) v[j]=1; } } /*for(int i=0;i<prime.size();i++) cout<<i<<" "<<prime[i]<<endl;*/}int main(){ int t; prepare(); scanf("%d",&t); while(t--) { int L,G,ans=1,tot; scanf("%d%d",&G,&L); if(L%G) { printf("0\n"); continue; } int tmp=L/G; for(int i=0; i<prime.size(); i++) if(tmp%prime[i]==0) { tot=0; while(tmp%prime[i]==0) { tot++; tmp/=prime[i]; } ans*=6*tot; } if(tmp>1)ans*=6*tot; printf("%d\n",ans); } return 0;}
0 0
- Hdu 4497 GCD and LCM(数论)
- 【数论】 HDU 4497 GCD and LCM
- hdu 4497 GCD and LCM(数论,排列组合)
- HDU 4497 GCD and LCM (数论&组合数学)
- hdu 4497 GCD and LCM 数论 素数分解
- HDU 4497 - GCD and LCM (质因式分解 GCD LCM)
- hdu(4497) GCD and LCM
- HDU 4497 GCD and LCM(数学)
- hdu 4497 GCD and LCM(排列组合)
- HDU-4497 GCD and LCM (数学)
- HDU4497:GCD and LCM(数论)
- hdu 4497 GCD and LCM
- hdu 4497 GCD and LCM
- HDU - 4497 GCD and LCM
- HDU - 4497 GCD and LCM
- HDU 4497 GCD and LCM
- HDU 4497 GCD and LCM
- HDU 4497 GCD and LCM
- 生命的思考.纪念雷博
- HDOJ-----5137最短路
- 剑指offer - 从尾到头打印链表
- javascript之数组、ById、ByTagName、循环、cssText和this
- SpringMVC整合fastjson
- Hdu 4497 GCD and LCM(数论)
- C++对象模型
- 深入讲解Android中Activity launchMode
- linux文件系统
- F4 help functionality for a dynpro screen field using the PROCESS ON VALUE-REQUEST statement
- django ifequal标签的使用方式
- mybities insert 的时候得到主键的值
- 不敢死队问题
- maven setting.xml配置说明