Codes/Volume 01/E0049 Prime permutations.cpp
/*
Statement:
 The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three 
 terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

 There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit 
 increasing sequence.

 What 12-digit number do you form by concatenating the three terms in this sequence?
*/
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three
terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit
increasing sequence.


The arithmetic sequence 1487 4817 8147 in which each of the terms increases by 3330 is unusual in two ways : ( i ) each of the three terms are prime and ( ii ) each of the 4 - digit numbers are permutations of one another . There are no arithmetic sequences made up of three 1 - 2 - or 3 - digit primes exhibiting this property but there is one other 4 - digit increasing sequence .
vector<int> primeSieveTill(int maxNum){
    if(maxNum == 1) return vector<int>();
    vector<bool> oddComposite(maxNum/2+1);  
    vector<int> primes{2};
    for(int p = 3; p <= maxNum; p+=2){
        if(oddComposite[p>>1]) continue;
        primes.push_back(p);
        if(maxNum/p < p) continue;
        for(int multiple = p*p; multiple <= maxNum; multiple += p+p)
            oddComposite[multiple/2] = true;
    }
    return primes;
}
vector < int > primeSieveTill ( int maxNum ) { if ( maxNum == 1 ) return vector < int > ( ) ; vector < bool > oddComposite ( maxNum / 2 + 1 ) ; vector < int > primes { 2 } ; for ( int p = 3 ; p <= maxNum ; p += 2 ) { if ( oddComposite [ p >> 1 ] ) continue ; primes . push_back ( p ) ; if ( maxNum / p < p ) continue ; for ( int multiple = p * p ; multiple <= maxNum ; multiple += p + p ) oddComposite [ multiple / 2 ] = true ; } return primes ; }
Statement:
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three
terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
Statement : The arithmetic sequence 1487 4817 8147 in which each of the terms increases by 3330 is unusual in two ways : ( i ) each of the three terms are prime and ( ii ) each of the 4 - digit numbers are permutations of one another .
// oddComposite[i] = whether 2*i+1 is non-prime