-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomdiv2.cpp
More file actions
57 lines (53 loc) · 955 Bytes
/
comdiv2.cpp
File metadata and controls
57 lines (53 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pr pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
void seive(bool isNPrime[],int Primes[],int &nPrimes )
{
int MAX=1000000;
isNPrime[0]=true;
isNPrime[1]=true;
int i;
for(i=0;i*i<MAX;i++){
if(isNPrime[i]==false){
for(int j=i*i;j<MAX;j=j+i)
isNPrime[j]=true;
}
}
for(i=0;i<MAX;i++)
if(isNPrime[i]==false)
Primes[nPrimes++]=i;
}
int main(){
int t,g,a,b,f,i;
scanf("%d",&t);
bool isNPrime[1000000];
int A[100000];
int nPrimes=0;
seive(isNPrime,A,nPrimes);
while(t--){
scanf("%d%d",&a,&b);
g=__gcd(a,b);
f=1;
if(g==1){
printf("%d\n",f);
continue;
}
for(i=0;A[i]<=g && i<nPrimes;i++){
int c=1;
while(g%A[i]==0){
g=g/A[i];
c++;
}
f=f*c;
}
if(f==1)
f++;
printf("%d\n",f);
}
}