-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEASYFACT.cpp
More file actions
57 lines (55 loc) · 1.13 KB
/
EASYFACT.cpp
File metadata and controls
57 lines (55 loc) · 1.13 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
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define gc getchar_unlocked
int prime[100000009];
vector<int>save;
void pre(){
for(int i = 3 ; i*i <= 100000000 ; i+=2){
if(!prime[i]){
for(int j = i*i ; j<= 100000000 ; j+=i)
prime[j] = 1;
}
}
for(int j = 3 ; j<= 100000000 ; j+=2)
if(!prime[j])
save.pb(j);
}
inline void getInt(int &x)
{
register int c = gc();
x = 0;
int neg = 0;
for(;((c<48 || c>57) && c != '-');c = gc());
if(c=='-') {neg=1;c=gc();}
for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
if(neg) x=-x;
}
int main(){
pre();
cout<<2<<" ";
for(int i = 0 ; i < 100 ; i++)
cout<<save[i]<<" ";
cout<<endl;
int t;
getInt(t);
while(t--){
int n , m;
getInt(n);getInt(m);
ll ans=1 , cnt=0 , total_cnt=0;
int size = save.size();
for(int i = 0 ;i<size && (ll)save[i]*save[i] <= n ; i++){
total_cnt = 0;
for(int j = save[i] ; cnt = n/j ; j*=save[i])
total_cnt += cnt;
ans *= total_cnt + 1;
if(ans >= m)
ans %= m;
}
int start = n / sqrt(n);
start = n / start;
printf("%lld\n", (ans+m-1)%m);
}
return 0;
}