McCarthy is a famous theorician of computer science. In his work, he defined a recursive function,

called f91 that takes as input a positive integer N and returns a positive integer defined as follows:

If N <= 100, then f91(N) = f91(f91(N+11));

If N >= 101, then f91(N) = N-10.

Write a program, that computes McCarthy's f91.

Input

The input tests will consist of a series of positive integers, each integer is at most 1,000,000. There

will be at most 250,000 test cases. Each number is on a line on its own. The end of the input is

reached when the number 0 is met. The number 0 shall not be considered as part of the test set.

Output

The program shall output each result on a line by its own, following the format given in the sample

output.

Sample Input Sample Output

500

91

0

f91(500) = 490

f91(91) = 91

Of course, you can output the data in a file instead of console and also get the data fron the console instead of generating it!

#include <iostream.h>
#include <cstdlib.h>


int f91(int n)
{
    if(n >= 101)
        return (n - 10);
    if(n <= 100)
        return f91(f91(n + 11));
}

int main(int argc, char* argv[])
{
    for(int i = 250000; i != 0; --i)
    {
        int n = rand() % 1000000;
        char buff[20];
        std::cout << "f[" << itoa(n, buff, 10) << "] = " << f91(n) << std::endl;
    }
    std::cin.get();
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.