Project Euler Problem 387 states:
A Harshad or Niven number is a number that is divisible by the sum of its digits. 201 is a Harshad number because it is divisible by 3 (the sum of its digits.) When we truncate the last digit from 201, we get 20, which is a Harshad number. When we truncate the last digit from 20, we get 2, which is also a Harshad number. Let's call a Harshad number that, while recursively truncating the last digit, always results in a Harshad number a right truncatable Harshad number.
Also: 201/3=67 which is prime. Let's call a Harshad number that, when divided by the sum of its digits, results in a prime a strong Harshad number.
Now take the number 2011 which is prime. When we truncate the last digit from it we get 201, a strong Harshad number that is also right truncatable. Let's call such primes strong, right truncatable Harshad primes.
Given a number n
, determine the first n
strong, right truncatable Harshad primes.
Input: An integer, n
, where n<50
. (This means your program will need to be somewhat efficient.)
Output: The first n
strong, right truncatable Harshad primes, with some form of whitespace in between each value.
Reference Table:
The first 20 strong, right truncatable Harshad primes are:
1-10:181 211 271 277 421 457 631 2011 2017 2099
11-20:2473 2477 4021 4027 4073 4079 4231 4813 4817 6037 8011
Shortest code wins. Good luck!
1117
not a strong, right truncatable Harshad prime? \$\endgroup\$