We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Mathematics
  3. Number Theory
  4. Megaprime Numbers

Megaprime Numbers

Problem
Submissions
Leaderboard
Discussions
Editorial

A prime number is an integer greater than that has no positive divisors other than and itself.

We call a number megaprime if it is prime and all of its individual digits are prime. For example, is megaprime because it is prime and all its digits ( and ) are prime; however, is not megaprime because it is not prime (it's divisible by and ), and is not megaprime because it has a non-prime digit ( is not prime).

Given two long integers, and , find and print the total number of megaprime numbers in the inclusive range between and .

Input Format

Two space-separated long integers describing the respective values of and .

Constraints

Output Format

Print a long integer denoting the total number of megaprimes in the inclusive interval between and .

Sample Input 0

1 100

Sample Output 0

8

Explanation 0

There are eight megaprime numbers in the inclusive range from to (i.e., , , , , , , , and ), so we print as our answer.

Author

_mfv_

Difficulty

Medium

Max Score

50

Submitted By

455

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature