📜  二次方程的根是给定方程的根的 K 倍

📅  最后修改于: 2021-10-25 11:23:26             🧑  作者: Mango

给定三个整数ABC代表二次方程Ax 2 + Bx + C = 0的系数和一个正整数K ,任务是找到二次方程的系数,其根是二次方程的根的K 倍给定的方程。

例子:

方法:给定的问题可以通过使用二次根的概念来解决。请按照以下步骤解决问题:

  • 设方程Ax 2 + Bx + C = 0的根分别为PQ。
  • 然后,上述方程的根的乘积由P * Q = C / A给出,上述方程的根之和由P + Q = -B / A 给出
  • 因此,所需方程的根的乘积等于:
  • 同样,所需方程的根之和为2 * K (-B / C)
  • 因此,所需的二次方程等于:

下面是上述方法的实现:

C++
// C++ program for the above approach
#include 
using namespace std;
 
// Function to find the quadratic
// equation whose roots are K times
// the roots of the given equation
void findEquation(int A, int B, int C,
                  int K)
{
    // Print quadratic equation
    cout << A << " " << K * B
         << " " << K * K * C;
}
 
// Driver Code
int main()
{
    int A = 1, B = 2, C = 1, K = 2;
 
    findEquation(A, B, C, K);
 
    return 0;
}


Java
// Java program for the above approach
import java.util.*;
 
class GFG{
 
// Function to find the quadratic
// equation whose roots are K times
// the roots of the given equation
static void findEquation(int A, int B,
                         int C, int K)
{
     
    // Print quadratic equation
    System.out.print(A + " " + K * B +
                      " " + K * K * C);
}
 
// Driver Code
public static void main(String []args)
{
    int A = 1, B = 2, C = 1, K = 2;
 
    findEquation(A, B, C, K);
}
}


Python3
# Python3 program for the above approach
 
# Function to find the quadratic
# equation whose roots are K times
# the roots of the given equation
def findEquation(A, B, C, K):
   
    # Prquadratic equation
    print(A, K*B, K*K*C)
 
# Driver Code
if __name__ == '__main__':
    A, B, C, K = 1, 2, 1, 2
 
    findEquation(A, B, C, K)
 
# This code is contributed by mohit kumar 29.


C#
// C# program for the above approach
using System;
 
class GFG{
 
// Function to find the quadratic
// equation whose roots are K times
// the roots of the given equation
static void findEquation(int A, int B,
                         int C, int K)
{
     
    // Print quadratic equation
    Console.Write(A + " " + K * B +
                      " " + K * K * C);
}
 
// Driver Code
public static void Main()
{
    int A = 1, B = 2, C = 1, K = 2;
 
    findEquation(A, B, C, K);
}
}
     
// This code is contributed by ukasp


Javascript


输出:
1 4 4

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