Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 votes
1.4k views

image

image

by (610 points) | 1.4k views

1 Answer

0 votes

def isPrime(n):

    if n < 2:

        return False

    if n == 2:

        return True

    if n % 2 == 0:

        return False

    i = 3

    while i * i <= n:

        if n % i == 0:

            return False

        i += 2

    return True

def minimumInterest(M):

    currloan = M

    interest = 0

    while currloan >= 2:

        p = currloan

        # make p odd if needed (except 2)

        if p > 2 and p % 2 == 0:

            p -= 1

        # find largest prime <= currloan

        while p >= 2:

            if isPrime(p):

                break

            p -= 2

        currloan -= p

        interest += 1

    return interest

# Input / Output

M = int(input().strip())

print(minimumInterest(M))

by
Welcome to Itjobxs ; we help companies ease their recruitment process ; we shortlist talented candidates via our portal and send those profiles for job opportunities to IT companies. We also provide IT consulting and services.
23 questions
2,639 answers
22 users