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
#include <iostream>
#include <cmath>
#include <vector>
std::vector<std::size_t> prime_numbers_till( std::size_t ubound )
{
// generate a prime number sieve up to ubound
std::vector<bool> sieve( ubound, true ) ;
for( std::size_t i = 2 ; i < ubound ; ++i )
if( sieve[i] )
for( auto j = i*i ; j < ubound ; j += i ) sieve[j] = false ;
std::vector<std::size_t> primes( 1, 2 ) ;
for( std::size_t i = 3 ; i < ubound ; i += 2 ) if( sieve[i] ) primes.push_back(i) ;
return primes ;
}
std::vector<long long> prime_factors_of( long long n )
{
if( n < 0 ) return prime_factors_of(-n) ;
std::vector<long long> factors ;
for( int p : prime_numbers_till( std::sqrt(n) + 2 ) ) while( n%p == 0 )
{
factors.push_back(p) ;
n /= p ;
if( n == 1 ) break ; // no more factors
}
if( n > 1 ) factors.push_back(n) ; // n is a prime number
return factors ;
}
int main()
{
const long long n = 2LL * 19*19*19*19*19 * 41*41 * 1151 * 2239 ;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
uname -a
echo && clang++ --version | grep clang && echo && clang++ -std=c++14 -stdlib=libc++ -O3 -Wall -Wextra -pedantic-errors main.cpp && ./a.out
echo && g++ --version | grep GCC && echo && g++ -std=c++14 -O3 -Wall -Wextra -pedantic-errors main.cpp && ./a.out
Linux stacked-crooked 3.2.0-74-virtual #109-Ubuntu SMP Tue Dec 9 17:04:48 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

clang version 3.7.0 (tags/RELEASE_370/final 246979)

2 19 19 19 19 19 41 41 1151 2239 

g++ (GCC) 5.2.0

2 19 19 19 19 19 41 41 1151 2239