Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => Kth-Largest-Factor ) Codevita Previous Questions | Kth Largest Factor | THE INQUISITIVE





Kth Largest Factor

LEVEL:Beginner

Description

A positive integer d is said to be a factor of another positive integer N if when N is divided by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two factors, 1 and the number k itself.Given two positive integers N and k, write a program to print the kth largest factor of N.

Input Format

The input is a comma-separated list of positive integer pairs (N, k).
Constraints:
1 1 You can assume that N will have no prime factors which are larger than 13.

Output Format

The kth highest factor of N. If N does not have k factors, the output should be 1.


Example 1:

Input
12 3
Output
4
Example 2:

Input
30 9
Output
1
Example 3:

Input
100 2
Output
50

oops

Login to see Discussion




Approach

Given n,m are integers.
Take a variable C and initialize with 0.
Now iterate a loop from N to 0 and check whether the iterating number is divisble by given interger.
If yer increament the C value.
And check that if C equal to given m value then print that number.


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution