给定一个数字 。任务是为以下给定值找到以下表达式的值 。
例子:
Input: X = √2
Output: 198
Explanation:
= 198
Input: X = 3
Output: 4160
方法:想法是使用二项式表达式。我们可以将这两个术语视为2个二项式表达式。通过扩展这些术语,我们可以找到所需的总和。以下是条款的扩展。
现在把X = 在情商(1)中
下面是上述方法的实现:
C++
// CPP program to evaluate the given expression
#include
using namespace std;
// Function to find the sum
float calculateSum(float n)
{
int a = int(n);
return 2 * (pow(n, 6) + 15 * pow(n, 4)
+ 15 * pow(n, 2) + 1);
}
// Driver Code
int main()
{
float n = 1.4142;
cout << ceil(calculateSum(n)) << endl;
return 0;
}
Java
// Java program to evaluate the given expression
import java.util.*;
class gfg
{
// Function to find the sum
public static double calculateSum(double n)
{
return 2 * (Math.pow(n, 6) + 15 * Math.pow(n, 4)
+ 15 * Math.pow(n, 2) + 1);
}
// Driver Code
public static void main(String[] args)
{
double n = 1.4142;
System.out.println((int)Math.ceil(calculateSum(n)));
}
}
//This code is contributed by mits
Python3
# Python3 program to evaluate
# the given expression
import math
#Function to find the sum
def calculateSum(n):
a = int(n)
return (2 * (pow(n, 6) + 15 * pow(n, 4)
+ 15 * pow(n, 2) + 1))
#Driver Code
if __name__=='__main__':
n = 1.4142
print(math.ceil(calculateSum(n)))
# this code is contributed by
# Shashank_Sharma
C#
// C# program to evaluate the given expression
using System;
class gfg
{
// Function to find the sum
public static double calculateSum(double n)
{
return 2 * (Math.Pow(n, 6) + 15 * Math.Pow(n, 4)
+ 15 * Math.Pow(n, 2) + 1);
}
// Driver Code
public static int Main()
{
double n = 1.4142;
Console.WriteLine(Math.Ceiling(calculateSum(n)));
return 0;
}
}
//This code is contributed by Soumik
PHP
Javascript
输出:
198