Problem F: 我是好人
Description
众所周知,我是好人!
所以不会出太难的题,题意很简单 给你两个数n和m,问你有多少对正整数对最大公约数是n,最小公倍数是m
最后友情提供解题代码(我真是太好人了)
void solve()
{
long long n, m;
scanf("%lld%lld", &n, &m);
int ans = 0;
for (long long i = 1; i <= m; i++)
{
for (long long j = i; j <= m; j++)
{
if (gcd(i, j) == n && lcm(i, j) == m) ans++;
}
}
printf("%d\n", ans);
}
祝大家AC愉快!最好AK,送某扬兑现诺言^_^
Input
输入第1行是一个整数T,表示共T组数据。 接下来是T组数据,每组数据占1行,每一行有2个整数n,m(1 <= n, m <= 10000000000),两个数由一个空格隔开。
Output
结果输出T行,对应T组数据。(T<=100)
每行输出这样的正整数对有多少对(看我多好人,不用你们输出所有整数对)
Sample Input
31 17 100864 16
Sample Output
101
HINT
1.if (m%n!=0) ans=0;
2.if (m==n) ans=1;
3.若x为m/n中不同质因子的个数, ans=2的(x-1)次方
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef long long LL;
vector<LL> s;
LL T, N, M;
void Solve()
{
if (M % N){
cout << 0 << endl;
return;
}
else if (M == N){
cout << 1 << endl;
return;
}
s.clear();
LL dif = M / N;
for (LL i = 2; i*i <= M; i++){
if (dif%i == 0){
s.push_back(i);
while (dif%i == 0)
dif /= i;
}
}
if (dif > 1) s.push_back(dif);//!!
LL ans = (LL)1 << (s.size() - 1);
cout << ans << endl;
}
int main(int argc, char *argv[])
{
cin >> T;
while (T--)
{
cin >> N >> M;
Solve();
}
return 0;
}