Skip to the code
+25 XP

#645 Divide a Prize Pool

medium

A game's reward system works with values modulo the prime 1000000007. To split a pool of total points among people, it needs the number x with people × x ≡ total (mod 1000000007). That x is "total / people modulo 1000000007".

Write poolShare(total, people) that returns that x, between 0 and 1000000006. Since the modulus is prime, x = total × people^(1000000005) mod 1000000007.

Example 1

Input: total = 10, people = 2
Output: 5

2 × 5 = 10, so when the division is exact the answer is the normal quotient.

Example 2

Input: total = 1, people = 2
Output: 500000004

2 × 500000004 = 1000000008, which is 1 more than the modulus, so it counts as 1.

Constraints

  • 0 <= total < 1000000007
  • 1 <= people < 1000000007
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).