-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathqnumberPerfect.cpp
107 lines (94 loc) · 1.52 KB
/
qnumberPerfect.cpp
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<lli,lli>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define endl '\n'
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
map<lli,lli> PF;
lli total;
void factorize(lli n)
{
total = 1;
for(lli i=2;i*i<=n;i++)
if(n % i == 0)
{
int cnt = 0;
while(n % i == 0)
cnt++ , n /= i;
PF[i] = cnt;
total *= (cnt + 1);
}
if(n > 1) PF[n] = 1 , total *= 2;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
lli t , n , q , k;
cin>>n>>q;
factorize(n);
while(q--)
{
cin>>t>>k;
if(t == 1)
{
lli res = 1;
for(ii p : PF)
{
lli cnt = 0;
while(k % p.ff == 0)
cnt++ , k /= p.ff;
res *= min(cnt , p.ss) + 1;
}
cout<<res<<endl;
}
else
if(t == 2)
{
lli res = 1;
for(ii p : PF)
{
lli cnt = 0;
while(k % p.ff == 0)
cnt++ , k /= p.ff;
if(cnt > p.ss)
{
res = 0;
break;
}
res *= (p.ss - cnt + 1);
}
if(k > 1) res = 0;
cout<<res<<endl;
}
else
{
lli res = 1;
for(ii p : PF)
{
lli cnt = 0;
while(k % p.ff == 0)
cnt++ , k /= p.ff;
if(cnt > p.ss)
{
res = 0;
break;
}
res *= (p.ss - cnt + 1);
}
if(k > 1) res = 0;
cout<<total-res<<endl;
}
}
}