Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Exercise 1

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. Write a C
program using function to solve this problem.

Input format:

The first line contains the integers x, y and n respectively.

Output format:

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

Example:

Input:

2 3 10

Output:

Explanation:

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

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.

You might also like