给定三个数字A,B,C ,它们代表二次方程的系数(常数) ,任务是检查这些常数表示的方程式的一个根是否是其他常数的两倍。
例子:
Input: A = 1, B = -3, C = 2
Output: Yes
Explanation:
The given quadratic equation is
Its roots are (1, 2).
Input: A = 1, B = -5, C = 6
Output: No
Explanation:
The given quadratic equation is
Its roots are (2, 3). or
方法:这个想法是使用二次根的概念来解决问题。我们可以通过以下公式来确定检查一个根是否是另一个根的两倍所需的条件:
- 根数之和= + = 3 。该值等于:
- 同样,根的乘积= * = 2 。该值等于:
- 我们可以解决以上两个方程式和得到条件:
- 因此,为了使根的第一个假设成立,上述条件必须成立。因此,我们简单地检查上述条件对于给定系数是否成立。
下面是上述方法的实现:
C++
// C++ program to check if one root
// of a Quadratic Equation is
// twice of other or not
#include
using namespace std;
// Function to find the required answer
void checkSolution(int a, int b, int c)
{
if (2 * b * b == 9 * a * c)
cout << "Yes";
else
cout << "No";
}
// Driver code
int main()
{
int a = 1, b = 3, c = 2;
checkSolution(a, b, c);
return 0;
}
Java
// Java program to check if one root
// of a quadratic equation is
// twice of other or not
class GFG{
// Function to find the required answer
static void checkSolution(int a, int b, int c)
{
if (2 * b * b == 9 * a * c)
System.out.print("Yes");
else
System.out.print("No");
}
// Driver Code
public static void main(String[] args)
{
int a = 1, b = 3, c = 2;
checkSolution(a, b, c);
}
}
// This code is contributed by shubham
Python3
# Python3 program to check if one root
# of a Quadratic Equation is
# twice of other or not
# Function to find the required answer
def checkSolution(a, b, c):
if (2 * b * b == 9 * a * c):
print("Yes");
else:
print("No");
# Driver code
a = 1; b = 3; c = 2;
checkSolution(a, b, c);
# This code is contributed by Code_Mech
C#
// C# program to check if one root
// of a quadratic equation is
// twice of other or not
using System;
class GFG{
// Function to find the required answer
static void checkSolution(int a, int b, int c)
{
if (2 * b * b == 9 * a * c)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
// Driver Code
public static void Main()
{
int a = 1, b = 3, c = 2;
checkSolution(a, b, c);
}
}
// This code is contributed by shivanisinghss2110
Javascript
输出:
Yes