📜  平方方程的根与给定方程的根成反比

📅  最后修改于: 2021-04-17 16:39:41             🧑  作者: Mango

给定三个代表二次方程式Ax 2 + Bx + C = 0的系数的整数A,BC ,任务是找到其根与给定方程式的根成倒数的二次方程式。

例子:

方法:这个想法是使用二次根的概念来解决问题。请按照以下步骤解决问题:

  • 认为方程Ax 2 + Bx + C = 0的根p,q。
  • 上式的根的乘积由p * q = C / A给出。
  • 上式的根的总和由p + q = -B / A给出。
  • 因此,根的倒数是1 / p,1 / q。
  • 这些倒数根的乘积为1 / p * 1 / q = A / C。
  • 这些倒数根的和为1 / p + 1 / q = -B /C。
  • 如果知道根的总和和乘积,则二次方程式可以是x 2 –(根的总和)x +(根的乘积)= 0。
  • 在求解上述方程式时,二次方程式变为Cx 2 + Bx + A = 0。

下面是上述方法的实现:

C++
// C++ program for the above approach
 
#include 
using namespace std;
 
// Function to find the quadratic
// equation having reciprocal roots
void findEquation(int A, int B, int C)
{
    // Print quadratic equation
    cout << "(" << C << ")"
         << "x^2 +(" << B << ")x + ("
         << A << ") = 0";
}
 
// Driver Code
int main()
{
    // Given coefficients
    int A = 1, B = -5, C = 6;
 
    // Function call to find the quadratic
    // equation having reciprocal roots
    findEquation(A, B, C);
 
    return 0;
}


Java
// Java program for the above approach
class GFG{
  
// Function to find the quadratic
// equation having reciprocal roots
static void findEquation(int A, int B, int C)
{
     
    // Print quadratic equation
    System.out.print("(" + C + ")" + 
                "x^2 +(" + B + ")x + (" +
                           A + ") = 0");
}
 
// Driver Code
public static void main(String args[])
{
     
    // Given coefficients
    int A = 1, B = -5, C = 6;
 
    // Function call to find the quadratic
    // equation having reciprocal roots
    findEquation(A, B, C);
}
}
 
// This code is contributed by AnkThon


C#
// C# program for the above approach
using System;
using System.Collections.Generic;
 
class GFG{
  
// Function to find the quadratic
// equation having reciprocal roots
static void findEquation(int A, int B, int C)
{
    // Print quadratic equation
    Console.Write("(" + C + ")" + 
             "x^2 +(" + B + ")x + (" +
                        A + ") = 0");
}
 
// Driver Code
public static void Main()
{
     
    // Given coefficients
    int A = 1, B = -5, C = 6;
 
    // Function call to find the quadratic
    // equation having reciprocal roots
    findEquation(A, B, C);
}
}
 
// This code is contributed by bgangwar59


输出:
(6)x^2 +(-5)x + (1) = 0

时间复杂度: O(1)
辅助空间: O(1)