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.
Input: total = 10, people = 2 Output: 5
2 × 5 = 10, so when the division is exact the answer is the normal quotient.
Input: total = 1, people = 2 Output: 500000004
2 × 500000004 = 1000000008, which is 1 more than the modulus, so it counts as 1.
0 <= total < 10000000071 <= people < 1000000007Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #645 Divide a Prize Pool. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.