Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6424 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@mantu_singh | 3532 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1160 |

@gurshehzadsingh | 1052 |

@nithinreddy3210 | 801 |

@mohanreddy8847 | 702 |

@balwanyadav34 | 622 |

@satyamchhatrala | 616 |

@pritsahkar2000 | 614 |

@AkashLahoty | 606 |

@amangiri168 | 596 |

@iamchaitanyahegde | 589 |

@iib2019024 | 587 |

Complete Leaderboard |

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.

**Example 1:**

Input:x =2,y =3,n =10Output:9Explanation: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.

**Example 2:**

Input:x =5,y =7,n =10Output:3Explanation:We can form 3 out of 10 numbers using 5 and 7 and 10; 5 = 5, 7 = 7, 5+5 = 10.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **getCount()** which takes 3 Integers x,y and n respctively as input and returns the answer.

**Expected Time Complexity:** O(n)

**Expected Auxiliary Space:** O(n)

**Constraints:**

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

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Count numbers which can be constructed using two numbers

...