天天看點

牛客OI賽制測試賽2 A :無序組數

#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);
  }
}      

繼續閱讀