Wednesday, 21 February 2018

Mindless Algebra

Suppose, 
a = 50 
b = 2000 
c = 40
Define a mathematical function Fun(n) that does the following: 
Fun(n) = n - c, if n > b 
Fun(n) = Fun(a + Fun(a + Fun(a + Fun(a + n)))), if n ≤ b.
Print result of calling this Fun() for n-1, n and n+1.
Input Format
N : an integer N >= 0
Output Format
R1 R2 R3 : 3 integers representing result of function calls - Fun(N-1), Fun(N), Fun(N+1).
Sample Input
2000
Sample Output
2039 2040 1961
Explanation
Well, that's mindless function output for inputs N = 1999, 2000 and 2001.
Program:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int Fun(int n)
{
    if(n>2000)
        return n-40;
    else
        return  Fun(50+ Fun(50 + Fun(50 + Fun(50 + n))));
}
int main() {
    int n;
    cin>>n;
    cout<<Fun(n-1)<<" "<<Fun(n)<<" "<<Fun(n+1);
        
    return 0;
}

No comments:

Post a Comment

ASP.NET Core: How to implement Azure Active Directory (AAD) Authentication in ASP.NET Core

  In this tutorial, we will implement security for ASP.NET Core Application using Azure Active Directory (AAD).  In this tutorial, I will co...