Algorithm Analysis
To solve the problem, we will use a conditional statement. Since , then . We will use the type long long
to avoid overflow.
Algorithm Implementation
Read the input value .
scanf("%lld",&x);
Calculate the value of .
if (x >= 10) y = x * x * x + 5 * x; else y = x * x - 2 * x + 4;
Output the result.
printf("%lld\n",y);
Algorithm Implementation – Ternary Operator
Read the input value .
scanf("%lld",&x);
Calculate the value of .
y = (x >= 10) ? x * x * x + 5 * x : x * x - 2 * x + 4;
Output the result.
printf("%lld\n",y);
Java Implementation
import java.util.*; public class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); long y, x = con.nextLong(); if (x >= 10) y = x * x * x + 5 * x; else y = x * x - 2 * x + 4; System.out.println(y); con.close(); } }
Python Implementation
Read the input value .
x = int(input())
Calculate the value of .
if x >= 10: y = x * x * x + 5 * x else: y = x * x - 2 * x + 4
Output the result.
print(y)