The statement of this exercise is identical to that of exercise problem://problemsjutge.org:problems/p1/roura/perfecte.pbm. But here the solution required is more efficient in general.
Given a natural number , let be the sum of the digits of . In this exercise, we say that is a perfect prime if the infinite sequence , , , … only contains prime numbers. For instance, 977 is a perfect prime, because 977, , , 5, …, are all prime numbers.
Write a recursive function that tells if a natural number @n@ is a perfect prime or not.
| C++ | |
| C | |
| Java | |
| Python | |
|
We have @n@ .
You only need to submit the required procedure; your main program will be ignored.
Input/Output