Project Euler #130: Composites with prime repunit property

  • + 1 comment

    For those who passed all test cases, could you please give a hint on whether we should approach this problem by

    1. Iterating on starting from to (+= 2 and skipping multiples of ) and feed them to primality testing (e.g. Miller-Rabin), or

    2. Generating all composite numbers from primes except and ? (e.g. using a heap)

    Do we need to make use of the observation that is the least common multiple between and if ?

    I was using the first approach and only passed the first 6 test cases. My implementataion of the A(i) function was by performing curr = (curr * 10 + 1) % i on each iteration step, and the upper bound of this function is which is not very nice.

    EDIT: An observation, that for example , where is one of the valid answers, but , and are all invalid answers. I wonder if there is any pattern there. Also, it is curious that is the largest prime we need for up to .