222k views
2 votes
Write a python function that returns an integer K such that for any given integer N, N%K is the largest.

User IcarusNM
by
8.3k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

def find_largest(N):

if N <= 1:

return N

max = 0

largestK = 0

for K in range(1, N+1):

modulus = N % K

if modulus > max_:

max_ = modulus

largestK = K

return largestK

User Dispersia
by
8.4k points

No related questions found