-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_prime.cpp
79 lines (73 loc) · 1.91 KB
/
is_prime.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
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include </home/poeticpotato/work/cpp/debug.h>
#else
#define deb(x...)
#endif
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FOR(i, a, b) for (ll i = (a); (i) < (b); (i)++)
#define FORN(i, a, b) for (ll i = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (ll i = (a); (i) > (b); (i)--)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define eb emplace_back
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
template <typename T>
using vv = vector<vector<T>>;
template <typename T>
using vvv = vector<vv<T>>;
template <typename T, typename N>
using um = unordered_map<T, N>;
template <typename T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using MaxHeap = priority_queue<T>;
const ll MOD[] = {999727999, 1070777777, 1000000007, 998244353};
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int M = MOD[2];
const int inf = (int)1e9;
const ll INF = 1e18;
const ll N = 1e8;
int P[N+1];
vll primes;
void init() {
memset(P, 0, sizeof(int)*(N+1));
FORN(i, 2, N) if (!P[i]) {
primes.eb(i);
for (int j=i+i;j<=N;j+=i)
P[j] = 1;
}
}
void solve() {
ll n;
cin>>n;
if (!P[n]) return (void) (cout<<n<<" is prime.\n");
cout<<"n = ";
vll fac, exp;
ll t = n;
for (ll p : primes) {
if (p>t) break;
if (!(t%p)) {
ll id = fac.size();
fac.eb(p);
exp.eb(0);
while (!(t%p)) exp[id]++, t/=p;
}
}
ll m = fac.size(), cnt=0, div=1;
REP(i, m) {
cout<<fac[i]<<"^"<<exp[i]<<" ";
cnt+=exp[i];
div *= exp[i]+1;
}
cout<<"\nnumber of primes: "<<cnt<<"\n";
cout<<"number of distinct primes: "<<m<<"\n";
cout<<"number of divisors: "<<div<<"\n";
}
int main() {
init();
while (true) solve();
}