Geek and Nerd are strikers playing football with their friend the Goalie. Their energies are denoted by X,Y and Z respectively. 
Strikers can only score a goal if the Goalie's energy is a factor of their energy. For every goal scored the energy of the respective player is decreased by 1. Each save decreses the Goalie's energy by 1. The game ends when the Goalie's energy is reduced to 1. The strikers can try to goal repeatedly in any order in order to optimise the total number of goals. Geek takes the lead whenever in doubt. 
Find the number of goals made by Geek and Nerd. 
Example 1:
Input: 
X = 4, Y = 9, Z = 5
Output: 3 2
Explaination:
1st Kick: X=4, Y=9, Z=4
Z is not a factor of X or Y. So the Goalie 
will save the first kick and his energy will 
reduce by 1. 
2nd Kick: X=3, Y=9, Z=4
Z is a factor of X. So Geek will take the 
goal and reduce X by 1. 
3rd Kick: X=3, Y=9, Z=3. Goalie saves. 
4th Kick: X=2, Y=9, Z=3. 
Z is a factor of both X and Y. 
When in doubt, Geek takes the lead. 
5th Kick: X=2, Y=8, Z=3. Nerd goals.
6th Kick: X=2, Y=8, Z=2. Goalie saves.
7th Kick: X=1, Y=8, Z=2. Geek goals.
8th Kick: X=1, Y=7, Z=2. Nerd goals.
9th Kick: X=1, Y=7, Z=1. 
Goalie saves and ends the game.
Example 2:
Input: 
X = 13, Y = 10, Z = 7
Output: 0 3
Explaination: Since X is a prime number, 
Geek will never goal. 
Your Task:
You do not need to read input or print anything. Your task is to complee the function goals() which takes X, Y and Z as input parameters and returns a list of integers containing two elements denoting the number of goals scored by Geek and Nerd respectively. 
Expected Time Complexity: O(Z)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ X, Y, Z ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def goals(self, X, Y, Z):

        # code here

Solutions:
class Solution:

	def goals(self, X, Y, Z):
		c1 = 0
		c2 = 0
		while Z > 1:
			if X % Z == 0:
				c1 += 1
				X -= 1
			if Y % Z == 0:
				c2 += 1
				Y -= 1
			else:
				Z -= 1
		val = [c1, c2]
		return val


class Solution:

	def goals(self, X, Y, Z):
		a = X
		b = Y
		while Z > 1:
			if X % Z == 0 and Y % Z == 0:
				X -= 1
			elif X % Z == 0 and Y % Z != 0:
				X -= 1
			elif X % Z != 0 and Y % Z == 0:
				Y -= 1
			elif X % Z != 0 and Y % Z != 0:
				Z -= 1
		return (a - X, b - Y)


class Solution:

	def goals(self, X, Y, Z):
		g = 0
		n = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				g += 1
			if Y % Z == 0:
				Y -= 1
				n += 1
			else:
				Z -= 1
		return [g, n]


class Solution:

	def goals(self, X, Y, Z):
		xc = yc = 0
		while Z != 1:
			if X % Z == 0:
				xc += 1
				X -= 1
			elif Y % Z == 0:
				yc += 1
				Y -= 1
			else:
				Z -= 1
		return (xc, yc)


class Solution:

	def goals(self, X, Y, Z):
		geekScore = 0
		nerdScore = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				geekScore += 1
			if Y % Z == 0:
				Y -= 1
				nerdScore += 1
			else:
				Z -= 1
		return [geekScore, nerdScore]


class Solution:

	def goals(self, X, Y, Z):
		geek_score = 0
		nerd_score = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				geek_score += 1
			if Y % Z == 0:
				Y -= 1
				nerd_score += 1
			else:
				Z -= 1
		return (geek_score, nerd_score)


class Solution:

	def goals(self, X, Y, Z):
		x = 0
		y = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				x += 1
			elif Y % Z == 0:
				Y -= 1
				y += 1
			else:
				Z -= 1
		return (x, y)


class Solution:

	def goals(self, X, Y, Z):
		gs = 0
		ns = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				gs += 1
			if Y % Z == 0:
				Y -= 1
				ns += 1
			else:
				Z -= 1
		return [gs, ns]


class Solution:

	def goals(self, X, Y, Z):
		GS = 0
		NS = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				GS += 1
			elif Y % Z == 0:
				Y -= 1
				NS += 1
			else:
				Z -= 1
		return [GS, NS]


class Solution:

	def goals(self, X, Y, Z):
		goalX = 0
		goalY = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				goalX += 1
			elif Y % Z == 0:
				Y -= 1
				goalY += 1
			else:
				Z -= 1
		return [goalX, goalY]


class Solution:

	def goals(self, X, Y, Z):
		S1 = 0
		S2 = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				S1 += 1
			if Y % Z == 0:
				Y -= 1
				S2 += 1
			else:
				Z -= 1
		return [S1, S2]


class Solution:

	def isfactor(self, M, N):
		if M % N == 0 or N % M == 0:
			return True
		return False

	def goals(self, X, Y, Z):
		self.L = []
		(cx, cy) = (0, 0)
		while Z != 1:
			if self.isfactor(Z, X) and self.isfactor(Z, Y) and (X != 1):
				X -= 1
				cx += 1
			elif self.isfactor(Z, X) and X != 1:
				X -= 1
				cx += 1
			elif self.isfactor(Z, Y) and Y != 1:
				Y -= 1
				cy += 1
			else:
				Z -= 1
		self.L.append(cx)
		self.L.append(cy)
		return self.L


class Solution:

	def goals(self, X, Y, Z):
		XPoints = 0
		YPoints = 0
		while Z > 1:
			if X % Z == 0:
				X = X - 1
				XPoints += 1
			elif Y % Z == 0:
				Y = Y - 1
				YPoints += 1
			else:
				Z = Z - 1
		return [XPoints, YPoints]


class Solution:

	def goals(self, x, y, z):
		x_score = 0
		y_score = 0
		while z > 1:
			if x % z == 0 and y % z == 0 or x % z == 0:
				x -= 1
				x_score += 1
			elif y % z == 0:
				y -= 1
				y_score += 1
			else:
				z -= 1
		return (x_score, y_score)


class Solution:

	def goals(self, X, Y, Z):
		geek = X
		nerd = Y
		while Z != 1:
			if geek % Z == 0 and nerd % Z == 0:
				geek -= 1
			elif geek % Z == 0:
				geek -= 1
			elif nerd % Z == 0:
				nerd -= 1
			else:
				Z -= 1
		return [X - geek, Y - nerd]


class Solution:

	def goals(self, X, Y, Z):
		a = 0
		b = 0
		while Z > 1:
			if X % Z == 0 or Y % Z == 0:
				if X % Z == 0:
					X = X - 1
					a = a + 1
				else:
					Y = Y - 1
					b = b + 1
			else:
				Z = Z - 1
		l = []
		l.append(a)
		l.append(b)
		return l


def factor(A, B):
	if A % B == 0:
		return 1
	else:
		return 0

class Solution:

	def goals(self, X, Y, Z):
		gx = 0
		gy = 0
		while Z != 1:
			flagx = 0
			flagy = 0
			if factor(X, Z) == 1:
				flagx = 1
			if factor(Y, Z) == 1:
				flagy = 1
			if flagx == 1:
				X = X - 1
				gx = gx + 1
			if flagx == 0 and flagy == 1:
				Y = Y - 1
				gy = gy + 1
			if flagx == 0 and flagy == 0:
				Z = Z - 1
		return (gx, gy)


class Solution:

	def goals(self, X, Y, Z):
		gscore = 0
		nscore = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				gscore += 1
			elif Y % Z == 0:
				Y -= 1
				nscore += 1
			else:
				Z -= 1
		return [gscore, nscore]


class Solution:

	def goals(self, X, Y, Z):
		xcnt = ycnt = 0
		while Z > 1:
			if X % Z == 0 and Y % Z == 0:
				xcnt += 1
				X -= 1
			elif X % Z == 0:
				X -= 1
				xcnt += 1
			elif Y % Z == 0:
				Y -= 1
				ycnt += 1
			elif Z - 1 >= 1:
				Z -= 1
				if Z == 1:
					break
		return (xcnt, ycnt)


class Solution:

	def goals(self, X, Y, Z):
		x = X
		y = Y
		r = []
		while Z != 1:
			if X % Z == 0:
				X = X - 1
			elif Y % Z == 0:
				Y = Y - 1
			else:
				Z = Z - 1
		r.append(x - X)
		r.append(y - Y)
		return r
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, Z) = [int(a) for a in input().split()]
		ob = Solution()
		(c1, c2) = ob.goals(X, Y, Z)
		print(c1, end=' ')
		print(c2)


class Solution:

	def goals(self, X, Y, Z):
		grekscore = 0
		nerdscore = 0
		while Z > 1:
			if X % Z == 0:
				grekscore += 1
				X -= 1
			if Y % Z == 0:
				nerdscore += 1
				Y -= 1
			else:
				Z -= 1
		return (grekscore, nerdscore)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, Z) = [int(a) for a in input().split()]
		ob = Solution()
		(c1, c2) = ob.goals(X, Y, Z)
		print(c1, end=' ')
		print(c2)


class Solution:

	def factor(self, a: int, b: int) -> bool:
		return b > 0 and a % b == 0

	def goals(self, X, Y, Z):
		(x, y) = (0, 0)
		(X, Y, Z)
		while Z > 1:
			if self.factor(X, Z):
				x += 1
				X -= 1
			elif self.factor(Y, Z):
				y += 1
				Y -= 1
			else:
				Z -= 1
		return (x, y)
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, Z) = [int(a) for a in input().split()]
		ob = Solution()
		(c1, c2) = ob.goals(X, Y, Z)
		print(c1, end=' ')
		print(c2)


def checkMul(a, b):
	if a % b == 0:
		return True
	else:
		return False

class Solution:

	def goals(self, X, Y, Z):
		(geek, nerd) = (0, 0)
		while Z != 1:
			if checkMul(X, Z) and checkMul(Y, Z):
				geek += 1
				X -= 1
			elif not checkMul(X, Z) and (not checkMul(Y, Z)):
				Z -= 1
			elif not checkMul(X, Z) and checkMul(Y, Z):
				nerd += 1
				Y -= 1
			elif checkMul(X, Z) and (not checkMul(Y, Z)):
				geek += 1
				X -= 1
		return [geek, nerd]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, Z) = [int(a) for a in input().split()]
		ob = Solution()
		(c1, c2) = ob.goals(X, Y, Z)
		print(c1, end=' ')
		print(c2)


class Solution:

	def goals(self, X, Y, Z):
		goalx = 0
		goaly = 0
		while Z > 1:
			if X % Z == 0 and Y % Z == 0:
				X -= 1
				goalx += 1
			elif X % Z == 0 and Y % Z != 0:
				X -= 1
				goalx += 1
			elif X % Z != 0 and Y % Z == 0:
				Y -= 1
				goaly += 1
			else:
				Z -= 1
		return [goalx, goaly]
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(X, Y, Z) = [int(a) for a in input().split()]
		ob = Solution()
		(c1, c2) = ob.goals(X, Y, Z)
		print(c1, end=' ')
		print(c2)


class Solution:

	def goals(self, X, Y, Z):
		X_goal = 0
		Y_goal = 0
		while Z != 1:
			if X % Z != 0 and Y % Z != 0:
				Z = Z - 1
			elif X % Z == 0:
				X_goal = X_goal + 1
				X = X - 1
			elif Y % Z == 0:
				Y_goal = Y_goal + 1
				Y = Y - 1
		return [X_goal, Y_goal]


class Solution:

	def goals(self, X, Y, Z):
		goal = []
		xgoals = 0
		ygoals = 0
		while Z != 1:
			if X % Z != 0 and Y % Z != 0:
				Z -= 1
				continue
			elif X % Z == 0 and Y % Z == 0:
				xgoals += 1
				X -= 1
				continue
			elif X % Z == 0:
				xgoals += 1
				X -= 1
				continue
			elif Y % Z == 0:
				ygoals += 1
				Y -= 1
		goal.append(xgoals)
		goal.append(ygoals)
		return goal


class Solution:

	def goals(self, X, Y, Z):
		countx = 0
		county = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				countx += 1
			elif Y % Z == 0:
				Y -= 1
				county += 1
			else:
				Z -= 1
		return (countx, county)


class Solution:

	def goals(self, x, y, z):
		a = 0
		b = 0
		while z > 1:
			if x % z == 0:
				a += 1
				x -= 1
			elif y % z == 0:
				b += 1
				y -= 1
			else:
				z -= 1
		return (a, b)


class Solution:

	def goals(self, X, Y, Z):
		(c1, c2) = (0, 0)
		while Z > 1:
			if X % Z == 0 and Y % Z == 0:
				X -= 1
				Y -= 1
				c1 += 1
				c2 += 1
			elif X % Z == 0 and Y % Z != 0:
				X -= 1
				c1 += 1
			elif X % Z != 0 and Y % Z == 0:
				Y -= 1
				c2 += 1
			elif X % Z != 0 and Y % Z != 0:
				Z -= 1
		return (c1, c2)


class Solution:

	def goals(self, X, Y, Z):
		first = second = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				first += 1
			if Y % Z == 0:
				Y -= 1
				second += 1
			if X % Z != 0 and Y % Z != 0:
				Z -= 1
		return [first, second]


class Solution:

	def goals(self, x, y, z):
		goalsX = 0
		goalsY = 0
		while z > 1:
			if x % z == 0:
				x -= 1
				goalsX += 1
			elif y % z == 0:
				y -= 1
				goalsY += 1
			else:
				z -= 1
		return (goalsX, goalsY)


class Solution:

	def goals(self, X, Y, Z):
		goal_of_geek = 0
		goal_of_nerd = 0
		while Z > 1:
			if X % Z != 0 and Y % Z != 0:
				Z -= 1
			elif X % Z == 0 and Y % Z == 0 and (X != 0) and (Y != 0):
				goal_of_geek += 1
				X -= 1
			elif X % Z == 0 and X != 0 and (Y % Z != 0):
				goal_of_geek += 1
				X -= 1
			elif Y % Z == 0 and Y != 0 and (X % Z != 0):
				goal_of_nerd += 1
				Y -= 1
		answer_list = [goal_of_geek, goal_of_nerd]
		return answer_list


class Solution:

	def goals(self, x, y, z):
		x_count = 0
		y_count = 0
		while z != 1:
			if x % z == 0 or (x % z == 0 and y % z == 0):
				x -= 1
				x_count += 1
			elif y % z == 0:
				y -= 1
				y_count += 1
			else:
				z -= 1
		return (x_count, y_count)


class Solution:

	def goals(self, X, Y, Z):
		g1 = 0
		g2 = 0
		while Z != 1:
			if X % Z == 0 or (X % Z == 0 and Y % Z == 0):
				X -= 1
				g1 += 1
			elif Y % Z == 0:
				Y -= 1
				g2 += 1
			else:
				Z -= 1
		return (g1, g2)


class Solution:

	def goals(self, X, Y, Z):
		xg = 0
		yg = 0
		while Z > 1:
			if X % Z == 0:
				X = X - 1
				xg = xg + 1
			elif Y % Z == 0:
				Y = Y - 1
				yg = yg + 1
			else:
				Z = Z - 1
		return (xg, yg)


class Solution:

	def goals(self, X, Y, Z):
		geekscore = 0
		nerdscore = 0
		while Z > 1:
			if X % Z == 0:
				X -= 1
				geekscore += 1
			if Y % Z == 0:
				Y -= 1
				nerdscore += 1
			else:
				Z -= 1
		return [geekscore, nerdscore]


class Solution:

	def goals(self, X, Y, Z):
		gbygeek = 0
		gbynerd = 0
		if Z == 1:
			return [0, 0]
		while True:
			if X % Z == 0:
				gbygeek += 1
				X -= 1
			elif Y % Z == 0:
				gbynerd += 1
				Y -= 1
			else:
				Z -= 1
			if Z == 1:
				return [gbygeek, gbynerd]


class Solution:

	def goals(self, x, y, z):
		(g, n) = (0, 0)
		while z > 1:
			if x % z == 0:
				x -= 1
				g += 1
			if y % z == 0:
				y -= 1
				n += 1
			else:
				z -= 1
		return [g, n]


class Solution:

	def goals(self, X, Y, Z):
		X1 = 0
		Y1 = 0
		while Z != 1:
			if X % Z == 0:
				X = X - 1
				X1 = X1 + 1
			elif Y % Z == 0:
				Y = Y - 1
				Y1 = Y1 + 1
			else:
				Z = Z - 1
		return (X1, Y1)


class Solution:

	def goals(self, X, Y, Z):
		or_X = X
		or_Y = Y
		while Z > 1:
			if X % Z == 0:
				X -= 1
			elif Y % Z == 0:
				Y -= 1
			else:
				Z -= 1
		return (or_X - X, or_Y - Y)


class Solution:

	def goals(self, X, Y, Z):
		(x_count, y_count) = (0, 0)
		while Z > 1:
			if not X % Z:
				x_count += 1
				X -= 1
			elif not Y % Z:
				y_count += 1
				Y -= 1
			else:
				Z -= 1
		return (x_count, y_count)


class Solution:

	def goals(self, X, Y, Z):
		countX = 0
		countY = 0
		while Z > 1:
			if X % Z == 0:
				countX += 1
				X -= 1
			elif Y % Z == 0:
				countY += 1
				Y -= 1
			else:
				Z -= 1
		return [countX, countY]


class Solution:

	def goals(self, X, Y, Z):
		(x, y, z) = (0, 0, 0)
		while Z > 1:
			if X % Z == 0 and X > 0:
				X -= 1
				x += 1
			if Y % Z == 0 and Y > 0:
				Y -= 1
				y += 1
			else:
				Z -= 1
		return (x, y)