Project Euler 387
Project Euler 387
题目
Harshad Numbers
A Harshad or Niven number is a number that is divisible by the sum of its digits.
When we truncate the last digit from
When we truncate the last digit from
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:
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
When we truncate the last digit from it we get
Let's call such primes strong, right truncatable Harshad primes.
You are given that the sum of the strong, right truncatable Harshad
primes less than
Find the sum of the strong, right truncatable Harshad primes less
than
解决方案
令
本题主要关注可右截 Harshad 数。这种数的有一种生成思想:如果当前数
很明显,
接下来,我们将枚举出来的可右截 Harshad 数,逐一直接判断是否为强 Harshad 数,并保留强 Harshad 数的一部分。
对每个右截强 Harshad 数
代码
1 | from tools import is_prime |