Recursive Function

3.4

60 votes
Easy
Problem

Implement the recursive function given by the following rules and print the last 3 digits:

F(x, y) = {
y + 1 when x = 0,
F(x - 1, 1) when x > 0 and y = 0,
F(x - 1, F(x, y - 1)) when x > 0 and y > 0
}

Input Format
A single line containing two integers X,Y
1 <= X,Y <= 100000

Output Format
The last three digits

Input Constraints
X and Y are non-negative integers. Problem Setter: Practo Tech Team

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Note: x and y are non-negative integers

Editor Image

?