Given three positive integers x, y and n, the task is to find count of all numbers from 1 to n that can be formed using x and y. A number can be formed using x and y if we can get it by adding any number of occurrences of x and/or y.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains the integers x, y and n respectively.

**Output:**

Print the count of all numbers between 1 and n which can be formed using x and y. Print the answer for each test case in a new line.

**Constraints:**

1 <= T <= 100

1 <= x, y, n <= 10^{5}

**Example:**

**Input:**

2

2 3 10

5 7 10

**Output:**

9

3

**Explanation:**

Input : n = 10, x = 2, y = 3

Output : 9

We can form 9 out of 10 numbers using 2 and 3 and 10 2 = 2, 3 = 3, 4 = 2+2, 5 = 2+3, 6 = 3+3 7 = 2+2+3, 8 = 3+3+2, 9 = 3+3+3 , 10 = 3+3+2+2.

Author: Dharmesh

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

madhursengar24 | 86 |

PiyushPandey4 | 617 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 448 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.