-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture24.cpp
More file actions
82 lines (62 loc) · 1.2 KB
/
Copy pathLecture24.cpp
File metadata and controls
82 lines (62 loc) · 1.2 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
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
#include<iostream>
#include<vector>
using namespace std;
int fastExpo(int a, int b ) {
int res = 1;
while(b > 0) {
if(b&1) {
//odd
res = res*a;
}
b = b >> 1; // b = b/2
a = a * a;
}
return res;
}
// GREATEST COMMON FACTOR
int gcd(int a, int b) {
if(a==0)
return b;
if(b==0)
return a;
while(a != b) {
if(a>b)
{
a = a-b;
}
else{
b = b-a;
}
}
return a;
}
bool isPrime(int n) {
if(n<=1)
return false;
for(int i=2; i<n; i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
// SIEVE
int countprime(int n){
int cnt = 0;
vector<bool> prime(n+1,true);
prime[0]=prime[1]= false;
for(int i = 2; i<n; i++){
if(prime[i]){
cnt++;
}
for(int j=2*i; j<n; j=j+i){
prime[j]=false;
}
}
return cnt;
}
int main(){
}
// remaining segmented sieve