Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones.

Every prime p larger than 5, evenly divides the repunit Rp-1.



E.G.
The repunit R6 is evenly divisible by 7.

111111 / 7 = 15873

The repunit R42 is evenly divisible by 43.

111111111111111111111111111111111111111111 / 43 = 2583979328165374677002583979328165374677

And so on.



There are composite numbers that also have this same property. They are often referred to as deceptive non-primes or deceptive numbers.



The repunit R90 is evenly divisible by the composite number 91 (=7*13).

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 / 91 = 1221001221001221001221001221001221001221001221001221001221001221001221001221001221001221


Task 
 Find and show at least the first 10 deceptive numbers; composite numbers n that evenly divide the repunit Rn-1


See also
 Numbers Aplenty - Deceptive numbers
 OEIS:A000864 - Deceptive nonprimes: composite numbers k that divide the repunit R_{k-1}




#include <gmpxx.h>
 
#include <iomanip>
#include <iostream>
 
bool is_prime(int n) {
    if (n < 2)
        return false;
    if (n % 2 == 0)
        return n == 2;
    if (n % 3 == 0)
        return n == 3;
    for (int p = 5; p * p <= n; p += 4) {
        if (n % p == 0)
            return false;
        p += 2;
        if (n % p == 0)
            return false;
    }
    return true;
}
 
int main() {
    std::cout << "First 100 deceptive numbers:\n";
    mpz_class repunit = 11;
    for (int n = 3, count = 0; count != 100; n += 2) {
        if (n % 3 != 0 && n % 5 != 0 && !is_prime(n) &&
            mpz_divisible_ui_p(repunit.get_mpz_t(), n))
            std::cout << std::setw(6) << n << (++count % 10 == 0 ? '\n' : ' ');
        repunit *= 100;
        repunit += 11;
    }
}