

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
using namespace std;
int count(int a, int b) {
map<int, int> f;
int res = 1;
while (a % 2 == 0) {
f[2]++;
a /= 2;
}
for (int i = 3; i <= sqrt(a); i = i + 2)
while (a % i == 0) {
f[i]++;
a /= i;
}
if (a > 2) f[a]++;
while (b % 2 == 0) {
f[2]++;
b /= 2;
}
for (int i = 3; i <= sqrt(b); i = i + 2)
while (b % i == 0) {
f[i]++;
b /= i;
}
if (b > 2) f[b]++;
for (auto i: f) res *= i.second + 1;
return res;
}
int main() {
freopen("uocso.inp","r",stdin);
freopen("uocso.out","w",stdout);
int t,a,b;
cin >> t;
while (t--) {
cin >> a >> b;
cout << count(a,b) << '\n';
}
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin