-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPrimeFactorisation.cpp
116 lines (108 loc) · 1.41 KB
/
PrimeFactorisation.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
106
107
108
109
110
111
112
113
114
115
116
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define LD long double
#define gc getchar_unlocked
#define pc putchar_unlocked
#define MOD 1000000007
#define MAXN 2*100005
#define bitcount _builtin_popcount
#define INF 2000000000
#define EPS 1e-9
template<typename T>T absll(T X)
{
if(X<0)
return -1*X;
else
return X;
}
vector<int> factors[1053];
vector<int> primes;
vector<int> mprimes(1053,0);
LL N,M,L,R;
LL modPow(LL A,LL B,LL C)
{
LL X=1LL;
while(B)
{
if(B&1)
{
X=(X*A)%C;
}
A=(A*A)%C;
B/=2LL;
}
return X%C;
}
LL power(LL A,LL B)
{
LL X=1LL;
while(B)
{
if(B&1)
{
X=(X*A);
}
A=(A*A);
B/=2LL;
}
return X;
}
void sieve()
{
primes.pb(2);
for(int i=4;i<1053;i+=2)
{
mprimes[i]=1;
}
for(int i=3;i<1053;i+=2)
{
if(!mprimes[i])
{
primes.pb(i);
for(int j=2*i;j<1053;j+=i)
{
mprimes[j]=1;
}
}
}
}
void primeFactorisation()
{
int cnt=0;
int flag=true;
for(int i=2;i<1053;i++)
{
int number=i;
while(number>1)
{
for(int j=0;j<primes.size();j++)
{
int product=1;
cnt=0;
while(number%primes[j]==0)
{
number/=primes[j];
++cnt;
}
if(cnt>0)
{
factors[i].pb(power(primes[j],cnt));
}
if(number==1)
{
flag=false;
break;
}
}
if(flag==false)
{
flag=true;
break;
}
}
}
}