-
Notifications
You must be signed in to change notification settings - Fork 4
/
sieve.cpp
49 lines (42 loc) · 1.15 KB
/
sieve.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
freopen("input.txt", "r", stdin);
long long n = 2147483648;
bool* isPrime;
auto generateSieve = [&](long long n) -> void {
for (long long i = 0 ; i < n; i++) {
isPrime[i] = 1;
}
for ( long long i = 2; i * i <= n; i++ ) {
if ( isPrime[i] ) {
for(long long p = i * i; p <= n; p += i) {
isPrime[p] = false;
}
}
}
};
auto getPrimeFactors = [&](long long n) -> vector<long long> {
vector<long long> primeFactors;
for(long long i = 2; i * i <= n; i+=1 ) {
if ( n % i == 0 ) {
if ( isPrime[i] ) { primeFactors.push_back(i); }
if ( isPrime[n / i] ) { primeFactors.push_back(n / i); }
}
}
return primeFactors;
};
isPrime = new bool[n];
generateSieve(n);
auto primeFactors = getPrimeFactors(n);
for(long long i: primeFactors) {
if ( i != 2 && i != 3 && i!=5 ) {
return 0;
}
}
cout<<"Ugly";
return 0;
}