We are looking for the product of all integers p such that there exist an integer n⌌e106 with the last digit of pn being 3.
Note that 3 divides one of every 3 of those integers (3, 9, 15, ...), so the 3 required to be in the product is the one with the least significant digit of 3.
Similarly for 5, those integers are (5, 15, 25, ...), and so the smallest prime with the last digit of 5 is required
For 7, only those integers with the last digit of 3 are preserved (21, 63, 105, ...). So we only need to find the smallest prime with 7n has the least significant digit of and not coprime to any smaller . In other words, the smallest multiple of with last digit of is .
In general, we want the smallest multiple of prime p that has the least common multiple of the period of the last digits equal to 3.
For example, with 11, the periods of the last digits are 1 and 9 and divide p and respectively. Hence, the smallest multiples of with the last digit being is .
In other words, we look for the smallest q such that (p−10,p)∣pq
We can use this on ranges of p up to p<⌊100106⌋, and try product of them up to , for an upper bound of multiples of primes.
An easy way to do so is through dynamic programming.
Start with the last prime being multiplied in the form q=pk(p−10)+3 will minimize the unnecessary multiplication on the last steps.
To account for d1<100 and if it exists 100<d2< (with ), note that , since otherwise there would be a smaller prime that is part of the product of the desired number that is module ), have range (other values can easily be eliminated afterwards), and apply for both and (if exists) .
- If p=10, the solution is the product of p′=10,20,30,…,100 and product of () then
The dynamic programming step:
Let A(prime) = the smallest required product with that prime.
The current result after applying some primes is A={M,Smod106} where M is modulo the product
Implementation of it:
- If there is only 1 prime remaining, apply the product min(length(S),productmod106) times,
- Otherwise, find (with the last digit of and a multiple of the remaining prime) that minimizes (the first prime):
Finally, apply the addition modulo 106 repeatedly, with the smallest prime last, to obtain f(106).
The product f(106)=322512174447.
Then, the natural logarithm of the product is lnf(10