Algorithm of 10533 - Digit Primes

Problem Description Link

Algorithm:

This is a simple prime related problem
if a number is a prime then check that if sum of prime digit also prime then this digit is called digit prime
For example the prime number 41 is a digit prime because 4+1=5 and 5 is a prime number. 17 is not a digit prime because 1+7 = 8, and 8 is not a prime number.
But to solve this problem if you follow ittarative way then you may got TLE.
so you must generate prime and digit-prime before goe input.
and follow this technique.
1.pre calculate number of digit primes from 1 to 1000000
2. when you get t1 & t2 , number of digit primes t2 subtract number of digit primes t1-1
3. if t1 = 10, t2 = 100 . Number of digit primes at 10 is 4 and number of digit primes at 100 is 14
so dprime[100] - dprime[10-1] = 14 - 4 = 10
4. print the difference.

image

No comments:

Post a Comment

Write your comment - Share Knowledge and Experience