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
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #196: Prime triplets

Project Euler #196: Prime triplets

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 196 from projecteuler.net

Build a triangle from all positive integers in the following way:

image

Each positive integer has up to eight neighbours in the triangle.

A set of three primes is called a if one of the three primes has the other two as neighbours in the triangle.

For example, in the second row, the prime numbers and are elements of some prime triplet.

If row is considered, it contains two primes which are elements of some prime triplet, i.e. and .
If row is considered, it contains only one prime which is an element of some prime triplet: .

Define as the sum of the primes in row which are elements of any prime triplet.
Then and .

You are given that .

Find .

Input Format

The only line of each test file contains exactly two integers separated by a single space: and .

Constraints

Output Format

Output exactly one number that equals to .

Sample Input 0

8 9

Sample Output 0

97

Sample Input 1

9 10000

Sample Output 1

950007656

Author

bayleef

Difficulty

Medium

Max Score

100

Submitted By

358

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

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