Array ( [0] => [1] => questions [2] => Basic [3] => Kth-Largest-Factor )
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.
The input is a comma-separated list of positive integer pairs (N, k).
Constraints:
1
The kth highest factor of N. If N does not have k factors, the output should be 1.
12 3
4
30 9
1
100 2
50
Login to see Discussion
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.
Login to see Solution