Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

let int a = 2

for i in range 1 to abs(n)


a*=2
if n<0 print 1/a
else print a

Complexity: O(n)
----------------------------

function f(int x)
if(x>0) return 2*f(x-1)
elseif(x<0) return 2*f(x+1)
else return 1
main()
int n
input n
if(n>=0) print f(n)
else print 1/f(n)

Complexity: O(n)

You might also like