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 #232: The Race

Project Euler #232: The Race

Problem
Submissions
Leaderboard
Discussions

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

Two players share an unbiased coin and take it in turns to play "The Race". On Player 1's turn, he tosses the coin once: if it comes up Heads, he scores one point; if it comes up Tails, he scores nothing. On Player 2's turn, she chooses a positive integer and tosses the coin times: if it comes up all Heads, she scores points; otherwise, she scores nothing. Player 1 goes first. The winner is the first to or more points.

On each turn Player 2 selects the number, , of coin tosses that maximises the probability of her winning.

What is the probability that Player 2 wins? As the number is obviously rational and can be represented as with integer and , write the answer as

Input Format

The first line of each test file contains a single integer , that is the number of queries. lines follow, each containing a single integer .

Constraints

Output Format

Print exactly lines with the answer to the corresponding query on each line.

Sample Input 0

1
1

Sample Output 0

333333336

Explanation 0

The answer is which is equal to

Author

bayleef

Difficulty

Easy

Max Score

100

Submitted By

667

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