-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCOMDIV.cpp
More file actions
52 lines (52 loc) · 1.01 KB
/
COMDIV.cpp
File metadata and controls
52 lines (52 loc) · 1.01 KB
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
#include <bits/stdc++.h>
using namespace std;
int prime[100000];
bool check[1000009];
void pre()
{
for(int i = 3 ; i<=1000 ; i+=2)
{
if(!check[i])
{
for(int j = i*i ; j<=1000000 ; j+=i)
check[j] = true;
}
}
int j = 1;
prime[0] = 2;
for(int i = 3; i <=1000000 ; i+=2)
if(!check[i])
prime[j++] = i;
}
int main()
{
pre();
int t;
scanf("%d",&t);
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
long long gcd = __gcd(a,b);
long long res = 1;
if(gcd == 1)
{
printf("1\n");
continue;
}
for(int i = 0 ;i <= 78500 && prime[i] < gcd && gcd; i++)
{
int count = 0;
while(gcd%prime[i] == 0)
{
count++;
gcd/=prime[i];
}
res *= (count + 1);
}
if(gcd > 1)
res *= 2;
printf("%lld\n",res);
}
return 0;
}