-
Notifications
You must be signed in to change notification settings - Fork 8
/
204.cpp
73 lines (57 loc) · 1.42 KB
/
204.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
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
typedef unsigned long long int llu;
const llu N = 1000000000;
const int MAX_PRIME = 100;
int prime_cnt = 1;
llu primes[ MAX_PRIME ];
void eratosthenes() {
primes[ 0 ] = 2;
for ( llu candidate = 3; candidate < MAX_PRIME; candidate += 2 ) {
bool prime = true;
for ( int witness = 0;
witness < prime_cnt
&& primes[ witness ] * primes[ witness ] <= candidate;
++witness ) {
if ( candidate % primes[ witness ] == 0 ) {
prime = false;
break;
}
}
if ( prime ) {
primes[ prime_cnt++ ] = candidate;
}
}
}
inline llu value( vector< llu > factors ) {
llu ret = 1;
for ( int i = 0; i < prime_cnt; ++i ) {
ret *= pow( primes[ i ], factors[ i ] );
}
return ret;
}
inline bool increment( vector< llu > &factors ) {
for ( int i = 0; i < prime_cnt; ++i ) {
++factors[ i ];
if ( value( factors ) <= N ) {
return true;
}
factors[ i ] = 0;
}
return false;
}
int main() {
eratosthenes();
llu total = 0;
vector< llu > factorization;
for ( int i = 0; i < prime_cnt; ++i ) {
factorization.push_back( 0 );
}
while ( increment( factorization ) ) {
++total;
}
printf( "%llu\n", total + 1 );
return 0;
}