We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is giving me Time Error Exceed, maybe due to the exponential operations
Python#!/bin/python3importmathimportosimportrandomimportreimportsyssys.setrecursionlimit(20000)## Complete the 'solve' function below.## The function is expected to return a STRING.# The function accepts following parameters:# 1. LONG_INTEGER k# 2. LONG_INTEGER n#defsolve(k,n):# Write your code hereifk==1:return1else:returnk**n+solve(k-1,n)if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')t=int(input().strip())fort_itrinrange(t):first_multiple_input=input().rstrip().split()k=int(first_multiple_input[0])n=int(first_multiple_input[1])result=solve(k,n)result=result%100ifresult<10:strRes="0"+str(result)else:strRes=str(result)fptr.write(strRes+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Power Calculation
You are viewing a single comment's thread. Return to all comments →
This is giving me Time Error Exceed, maybe due to the exponential operations