Time Limit: 2 sec
Memory Limit: 128000 kB
Let us define a function f as f(x)=x2+2x+3. Given an integer t, find f(f(f(t)+t)+f(f(t))).
Here, it is guaranteed that the answer is an integer not greater than 2×109.
Input
The input consists of a single integer.
Constraints
t is an integer between 0 and 10 (inclusive).
Output
Print the answer as an integer.
Solution:
Java Code: -
import java.util.*;
public class Main {
public static int f(int x) {
return x * x + 2 * x + 3;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int ans = f(f(f(t) + t) + f(f(t)));
System.out.println(ans);
}
}
C++ Code:-
#include<iostream>
using namespace std;
int f(int x){
return x*x+2*x+3;
}
int main(){
int t;
cin>>t;
cout <<f(f(f(t)+t)+f(f(t)))<<endl;
return 0;
}
JavaScript Code:-
let t = require("fs").readFileSync("/dev/stdin", "utf8");
function f(x) {
return (x * x) + (2 * x) + 3;
}
const result = f(f(f(t) + Number(t)) + f(f(t)));
console.log(result );
Python Code:-
def f(x):
return x**2+2*x+3
t=int(input())
ans=f(f(f(t)+t)+f(f(t)))
print(ans)
No comments: