2 条题解
-
0
-
LaTex写公式有点麻烦,所以我用以前写好的代替了
-
想看原版可以戳这里
-
首先来分析一下这个题目

证明:

- 把上面的结论推广一下,得到结论
对于两个正整数,设,则存在
- 应用结论

- 整理一下式子

用心体会这两个式子,你会发现是的整数倍而且是的因子
~~好像这个由gcd和lcm也可以得到?~~嗯,就这样
于是得到一种解题思路
枚举的因子(也就是),如果这个数是的整数倍并且满足那两个式子,则
- code
#include<cstdio> using namespace std; int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int main() { int T; scanf("%d",&T); while(T--) { int a0,a1,b0,b1; scanf("%d%d%d%d",&a0,&a1,&b0,&b1); int p=a0/a1,q=b1/b0,ans=0; for(int x=1;x*x<=b1;x++) if(b1%x==0){ if(x%a1==0&&gcd(x/a1,p)==1&&gcd(q,b1/x)==1) ans++; int y=b1/x;//得到另一个因子 if(x==y) continue; if(y%a1==0&&gcd(y/a1,p)==1&&gcd(q,b1/y)==1) ans++; } printf("%d\n",ans); } return 0; } -
-
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL gcd(LL a, LL b){return (b==0) ? a : gcd(b, a%b);} LL lcm(LL a, LL b){ return a*b/gcd(a, b);} int main() { int n;scanf("%d", &n); while(n--) { LL a0, a1, b0, b1; scanf("%lld%lld%lld%lld", &a0, &a1, &b0, &b1); int ans=0; for(LL i=1; i*i <= b1; i++)if(b1%i == 0) { if(gcd(i, a0) == a1 && lcm(i, b0) == b1) ans++; int j = b1/i; if(i == j) continue; if(gcd(j, a0) == a1 && lcm(j, b0) == b1) ans++; } printf("%d\n", ans); } return 0; }
- 1
信息
- ID
- 735
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 175
- 已通过
- 45
- 上传者