Recursion

Let f ( 1 ) = 1 , f ( 2 ) = 2 f(1)=1, f(2)=2 and f ( n ) = f ( n 2 ) + 2 f ( n 1 ) f(n) = f(n-2) + 2f(n-1) where n > 2 n>2 be a recursive function. Write a program to find the image value of any positive integral value n.

Can you find f(33) mod 2016 mod 100 ?


this problem is a part of the set Fundamental Programming
27 81 42 64

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Arulx Z
Dec 23, 2015

I wrote a pretty straightforward program -

1
2
3
4
5
6
7
8
9
>>> def f(n):
        if n == 1:
            return 1
        if n == 2:
            return 2
        return f(n - 2) + 2 * f(n - 1)

>>> f(33) % 2016 % 100
81

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...