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 #239: Twenty-two Foolish Primes

Project Euler #239: Twenty-two Foolish Primes

Problem
Submissions
Leaderboard
Discussions

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

A set of disks numbered through are placed in a line in random order.

What is the probability that we have a partial derangement such that exactly prime number discs are found away from their natural positions? (Any number of non-prime disks may also be found in or out of their natural positions.)

It can be shown that for a given constraints the answer can be represented as , where and are coprime positive integers and . Print the value of modulo .

Input Format

The only line of input contains two integers and separated by single space.

Constraints

  • where is number of primes in range from to inclusive.

Output Format

Print the only line with the answer.

Sample Input 0

10 3

Sample Output 0

498412760

Explanation 0

The actual value of is .

Author

yakutovd

Difficulty

Medium

Max Score

100

Submitted By

284

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