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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #27: Quadratic primes

Project Euler #27: Quadratic primes

Problem
Submissions
Leaderboard
Discussions

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

Euler published the remarkable quadratic formula:

It turns out that the formula will produce 40 primes for the consecutive values to . However, when , is divisible by , and certainly when , is clearly divisible by .

Using computers, the incredible formula was discovered, which produces primes for the consecutive values to . The product of the coefficients, and , is .

Considering quadratics of the form:

where is the modulus/absolute value of
e.g. and

Find the coefficients, and , for the quadratic expression that produces the maximum number of primes for consecutive values of , starting with .

Note For this challenge you can assume solution to be unique.

Input Format

The first line contains an integer .

Output Format

Print the value of and separated by space.

Constraints

Sample Input

42

Sample Output

-1 41

Explanation

for and , you get 42 primes.

Author

shashank21j

Difficulty

Easy

Max Score

100

Submitted By

3927

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy