Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

 

Trailing Zeros 10

# Python3 program to
# count trailing 0s
# in n!

# Function to return
# trailing 0s in
# factorial of n


def findTrailingZeros(n):

    # Initialize result
    count = 0

    # Keep dividing n by
    # 5 & update Count
    while(n >= 5):
        n //= 5
        count += n

    return count


# Driver program
n = int(input())
print(findTrailingZeros(n))





CIRCULAR DEFEAT

import sys

def kill(people, passes):

    #If there is one person left, no need 
    #to continue.
    if people == 1:
        return 0
    #kill(people-1, passes) is the position 
    #of the survivor in the next iteration 
    #of the circle.
    #kill(people-1, passes) + passes is the 
    #position of the NEXT person who is out.
    return ((kill(people - 1,passes)+passes) % people)

try:
    people = int(raw_input())
    passes = int(raw_input())

    #The recursive solution is off by one 
    #so we add one at the end to account 
    #for it. The reason for the off by one 
    #is due to how we index each person
    survivor = kill(people, passes) + 1

    if survivor < 1:
        survivor = people

    print (survivor)

except ValueError:
    print("\nError reading integer(s). Quitting.")
    sys.exit()




Post a Comment

Previous Post Next Post