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$

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
while True:
	(n, m, x) = map(int, input().split())
	if n == 0 and m == 0 and (x == 0):
		break
	money = 0
	for i in range(n):
		money = money + (x + m * i) // n
	print(money)


from math import gcd

def abc(n, a, d):
	return n * (2 * a + (n - 1) * d) // 2
while True:
	(n, m, x) = map(int, input().split())
	if m == n == x == 0:
		break
	c = gcd(n, m)
	l = m // c
	print((abc(m, x, n) - c * abc(l, x % c, c)) // m)


while True:
	(n, m, x) = list(map(int, input().split()))
	if n == m == x == 0:
		break
	y = 0
	for i in range(n):
		y += (m * i + x) // n
	print(y)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def abc(n, a, d):
	return n * (2 * a + (n - 1) * d) // 2
while 1:
	(n, m, x) = map(int, input().split())
	if m == n == x == 0:
		break
	c = gcd(n, m)
	l = m // c
	ans = (abc(m, x, n) - c * abc(l, x % c, c)) // m
	print(ans)


while 1:
	(n, m, x) = map(int, input().split())
	if n == 0 and m == 0 and (x == 0):
		break
	cost = 0
	for j in range(n):
		cost += (x + j * m) // n
	print(cost)


(n, m, x) = map(int, input().split())
while n != 0 and m != 0 and (x != 0):
	i = 0
	s = 0
	while i < n:
		s += (x + i * m) // n
		i += 1
	print(s)
	(n, m, x) = map(int, input().split())


import math

def main():
	while True:
		(n, m, x) = map(int, input().split())
		if n == 0 and m == 0 and (x == 0):
			break
		k = int(1)
		l = int(0)
		r = int(0)
		ans = 0
		while True:
			l = (m * k - x + n - 1) // n
			l = int(l)
			r = (m * (k + 1) - x + n - 1) // n
			r -= 1
			r = int(r)
			if l >= m:
				break
			if l < 0:
				l = 0
			if r >= m:
				r = m - 1
			if l > r:
				k += 1
				continue
			ans += (r - l + 1) * k
			k += 1
		ans = int(ans)
		print(str(ans))
main()


def __starting_point():
	while True:
		(n, m, x) = map(int, input().split())
		if n == 0 and m == 0 and (x == 0):
			break
		sum = 0
		for i in range(n):
			sum += (x + i * m) // n
		print(sum)
__starting_point()


def main():
	while True:
		(n, m, x) = map(int, input().split())
		if [n, m, x] == [0, 0, 0]:
			break
		ans = 0
		for k in range(1111):
			l = (k * m - x + n - 1) // n
			r = ((k + 1) * m - x + n - 1) // n - 1
			l = max(l, 0)
			r = min(r, m - 1)
			if l < m and 0 <= r and (l <= r):
				ans += k * (r - l + 1)
		print(ans)
main()


import sys
input = sys.stdin.readline

def main():
	while True:
		(n, m, x) = map(int, input().split())
		if [n, m, x] == [0, 0, 0]:
			break
		ans = 0
		for k in range(1112):
			l = (k * m - x + n - 1) // n
			r = ((k + 1) * m - x + n - 1) // n - 1
			l = max(l, 0)
			r = min(r, m - 1)
			if l < m and 0 <= r and (l <= r):
				ans += k * (r - l + 1)
		print(ans)
main()


while True:
	(n, m, x) = input().split()
	n = int(n)
	m = int(m)
	x = int(x)
	if n == 0:
		break
	s = (2 * x + (m - 1) * n) * m // 2
	a = x % m
	b = n % m
	curr = 0
	if b == 0:
		s = s - a * m
		curr = m
	while curr < m:
		t = (m - a) // b
		if a + t * b >= m:
			t -= 1
		t = min(t, m - curr - 1)
		s = s - (2 * a + t * b) * (t + 1) // 2
		curr += t + 1
		a = (a + (t + 1) * b) % m
	print(int(s // m))
	if n == 0:
		break


while True:
	(n, m, x) = [int(x) for x in input().split()]
	if n == m == x == 0:
		break
	ans = 0
	for i in range(1, n + 1):
		ans += (x + (i - 1) * m) // n
	print(ans)


from math import gcd

def sum(a, d, n):
	return n * (2 * a + (n - 1) * d) // 2
while True:
	(n, m, x) = map(int, input().split())
	if m is 0:
		break
	hcf = gcd(n, m)
	f = m // hcf
	ans = (sum(x, n, m) - hcf * sum(x % hcf, hcf, f)) // 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)