Exemplo n.º 1
0
bool test(int n){
    --n;
    // test that its two least significant digits are 01
    if( !(n & 0x1) && ( (n>>1) & 0x1) ){
        // factor
        std::vector<int> divs( getDivisors(n) );
        std::vector<int>::iterator it;
        for(it = divs.begin(); it != divs.end(); it++){
            if( !g_primes.isPrime(*it + n/(*it)) ){
                return false;
            }
        }
        return true;
    }
    else{
        return false;
Exemplo n.º 2
0
std::vector< std::pair<int, int> > getFactors(int n){
    std::vector< std::pair<int, int> > factors;
    int p = 2;
    do{
        int multiplicity = 0;
        while( n % p == 0 ){
            multiplicity++;
            n /= p;
        }
        if( multiplicity ){
            factors.push_back( std::make_pair(p, multiplicity) );
        }
        if( g_primes.isPrime(n) ){
            factors.push_back( std::make_pair(n, 1) );
           break;
        }
    } while( (n > 1) && (p = g_primes.nextPrime(p)) );
    return factors;
}