Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Quadratic equation whose roots are K times the roots of given equation

  • Last Updated : 13 May, 2021

Given three integers A, B, and C representing the coefficients of a quadratic equation Ax2 + Bx + C = 0 and a positive integer K, the task is to find the coefficients of the quadratic equation whose roots are K times the roots of the given equation.

Examples:

Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

Input: A = 1, B = 2, C = 1, K = 2
Output: 1 4 4
Explanation:
The given quadratic equation x2 + 2x + 1 = 0.
Roots of the above equation are -1, -1.
Double of these roots are -2, -2.
Therefore, the quadratic equation with the roots (-2, -2) is x2 + 4x + 4 = 0.

Input: A = 1, B = -7, C = 12, K = 2
Output: 1 -14 48



Approach: The given problem can be solved by using the concept of quadratic roots. Follow the steps below to solve the problem:

  • Let the roots of the equation Ax2 + Bx + C = 0 be P and Q respectively.
  • Then, the product of the roots of the above equation is given by P * Q = C / A and the sum of the roots of the above equation is given by P + Q = -B / A.
  • Therefore, the product of the roots of the required equation is equal to:
     

 (K * P ) * (K * Q) = K2 * P * Q = (K2 * C ) / A

  • Similarly, the sum of the roots of the required equation is 2 * K (-B / C).
  • Therefore, the required quadratic equation is equal to:

 x2 – (Sum of the roots)x + (Product of the roots) = 0

=> Ax2 + (KB)x + (K2)C = 0

Below is the implementation of the above approach:

C++




// C++ program for the above approach
#include <bits/stdc++.h>
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




<script>
// Javascript program for the above approach
 
// Function to find the quadratic
// equation whose roots are K times
// the roots of the given equation
function findEquation(A, B, C, K)
{
 
    // Print quadratic equation
    document.write( A + " " + K * B
         + " " + K * K * C);
}
 
// Driver Code
var A = 1, B = 2, C = 1, K = 2;
findEquation(A, B, C, K);
 
// This code is contributed by noob2000.
</script>


Output: 

1 4 4

 

Time Complexity: O(1)
Auxiliary Space: O(1)

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!