Files
python/TangDou/LuoGuBook/P1029.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

27 lines
583 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
//最大公约数
int gcd(int x, int y) {
return y ? gcd(y, x % y) : x;
}
//最小公倍数
int lcm(int x, int y) {
return y / gcd(x, y) * x; //注意顺序防止乘法爆int
}
int cnt;
int x, y;
int main() {
//y的范围1e6,双重循环妥妥的TLE
cin >> x >> y;
//双重循环,傻查法,最基本,最朴素
for (int i = x; i <= y; i++)
for (int j = x; j <= y; j++)
if (gcd(i, j) == x && lcm(i, j) == y) cnt++;
cout << cnt << endl;
return 0;
}