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
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Number Theory
  4. Twins

Twins

Problem
Submissions
Leaderboard
Discussions
Editorial

Lia is fascinated by anything she considers to be a twin. She calls a pairs of positive integers, and , twins if:

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

  • Their absolute difference is exactly equal to (i.e., ).

Given an inclusive interval of integers from to , can you help Lia find the number of pairs of twins there are in the interval (i.e., )? Note that pairs and are considered to be the same pair.

Input Format

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

Constraints

Output Format

Print a single integer denoting the number of pairs of twins.

Sample Input 0

3 13

Sample Output 0

3

Explanation 0

There are three pairs of twins: , and .

Author

shef_2318

Difficulty

Medium

Max Score

30

Submitted By

4144

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website