There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time. 
Unfortunately, reading service is provided sequentially. After all of the $m$ people enter the library, the entrance gate is closed. There is only one reading table. So when someone reads, others have to wait in the waiting room. 
At first everybody chooses $n$ books they want to read. It takes $x$ amount of time. People can choose books simultaneously. Then they enter the waiting room. After reading $n$ books the person leaves the library immediately. 
As nothing is free, the cost of reading is also not free. If a person stays in the library $t$ units of time then the cost of reading is $\left \lfloor \frac{t-n}{m} \right \rfloor$ units of money. So, the $i^{th}$ person pays for time $x$ he needs to choose books and the time $(i-1)*n$ he needs to wait for all the persons before him to complete reading.
Note: $\left \lfloor a \right \rfloor$ denotes the floor($a$).
-----Input-----
- Each case contains three space-separated positive integers $n$, $m$ and $x$ where $n, x \leq 1000$ and $m \leq 10^{15}$. 
- End of input is determined by three zeros. 
- There are no more than 1000 test cases.
-----Output-----
- For each case, output in a single line the total unit of money the library gets in that day.
-----Sample Input-----
1 100 9
11 2 10
12 2 11
0 0 0
-----Sample Output-----
9
15
16
-----Explanation:-----
Testcase 2: Here, $n=11$, $m=2$, $x=10$.
For 1st person, 
$t=21$ and he/she gives $\left \lfloor \frac{21-11}{2} \right \rfloor = 5$ units of money.
For 2nd person,
$t=32$ and he/she gives $\left \lfloor \frac{32-11}{2} \right \rfloor= 10$ units of money.
So, total units of money $= 5+10 = 15$
from math import gcd

def sap(n, a, d):
 return n*(2*a + (n-1) * d)//2

while True:
 n, m, x = list(map(int, input().split()))
 if m is 0:
  break
 c = gcd(n, m)
 l = m//c
 ans = (sap(m, x, n) - c * sap(l, x % c, c))//m
 print(ans)

from math import gcd

def sap(n, a, d):
 return n*(2*a + (n-1) * d)//2

while True:
 n, m, x = list(map(int, input().split()))
 if m is 0:
  break
 c = gcd(n, m)
 l = m//c
 ans = (sap(m, x, n) - c * sap(l, x % c, c))//m
 print(ans)
