版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37960603/article/details/82494507
题目传送门
去掉重复的就可以了
代码:
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,int>M;
int main(){
int T;
scanf("%d",&T);
while(T--){
int A,B;
scanf("%d%d",&A,&B);
int atot,btot,same;
atot=btot=same=0;
M.clear();
for(int i=1;i*i<=A;i++) if(A%i==0){
atot++,M[i]=1;
if(i*i!=A) atot++,M[A/i]=1;
}
for(int i=1;i*i<=B;i++) if(B%i==0){
btot++;
if(M.count(i)) same++;
if(i*i!=B){
btot++;
if(M.count(B/i)) same++;
}
}
printf("%d\n",atot*btot-same*(same-1)/2);
}
}