Runtime error

hello there,
i’m trying to slove Problem Code: ADDNATR and i’m getting runtime error.
here’s my code
def function(n):
if n==0:
return 0
elif n==1:
return 1
return n+function(n-1)
n = int(input())

As the value of N can be as big as 10^9, it would obviously result into TLE.
Because nearly 10^8 operations are performed in a sec.
You this direct formula : N*(N+1)/2 with long long int

1 Like

There is no "long long int " in python?

simply use int in python

1 Like