Keplers Law CodeChef Solution – Queslers

Problem: Keplers Law CodeChef Solution

Kepler’s Law states that the planets move around the sun in elliptical orbits with the sun at one focus. Kepler’s 3rd law is The Law of Periods, according to which:

  • The square of the time period of the planet is directly proportional to the cube of the semimajor axis of its orbit.

You are given the Time periods (T1,T2T1,T2) and Semimajor Axes (R1,R2R1,R2) of two planets orbiting the same star.

Please determine if the Law of Periods is satisfied or not, i.e, if the constant of proportionality of both planets is the same.

Print "Yes" (without quotes) if the law is satisfied, else print "No".

Input Format

  • The first line of input contains a single integer TT, denoting the number of test cases. The description of TT test cases follows.
  • Each test case consists a single line of input, containing four space-separated integers T1,T2,R1,R2T1,T2,R1,R2.

Output Format

For each test case, output a single line containing one string — "Yes" or "No" (without quotes); the answer to the problem.

You may print each character of the answer in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1≤T≤1041≤T≤104
  • 1≤T1,T2≤101≤T1,T2≤10
  • 1≤R1,R2≤101≤R1,R2≤10

Subtasks

Subtask 1(100 points): Original constraints

Sample Input 1 

3
1 1 1 1
1 2 3 4
1 8 2 8

Sample Output 1 

Yes
No
Yes

Explanation

  • Test Case 11: 12/13=12/1312/13=12/13
  • Test Case 22: 12/33≠22/4312/33≠22/43
  • Test Case 33: 12/23=82/83

Keplers Law CodeChef Solution in C

#include <stdio.h>

int main(void) {
	int r;
	scanf("%d",&r);
	while(r--)
	{
	    int d1,d2,r1,r2;
	    scanf("%d %d %d %d",&d1,&d2,&r1,&r2);
	    if(d1*d1*r2*r2*r2==d2*d2*r1*r1*r1)
	    {
	        printf("YES\n");
	    }
	    else
	    printf("NO\n");
	}
	return 0;
}

Keplers Law CodeChef Solution in C++

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
   int t;
   cin>>t;
   int t1,t2,r1,r2;
   while(t--)
   {
       cin>>t1>>t2>>r1>>r2;
       if(pow(t1,2)/pow(r1,3)==pow(t2,2)/pow(r2,3))
       {
           cout<<"Yes"<<endl;
       }
       else
       {
           cout<<"No"<<endl;
       }
   }

    return 0;
}

Keplers Law CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	  Scanner scan=new Scanner(System.in);
	  int a=scan.nextInt();
	  for(int i=0;i<a;i++)
	  {
	     float t1=scan.nextInt();
	     float t2=scan.nextInt();
	     float r1=scan.nextInt();
	     float r2=scan.nextInt();
         if (((t1 * t1) /( r1 * r1 * r1)) == ((t2 * t2 )/ (r2 * r2 * r2)))
	     {
	         System.out.println("Yes");
	     }
	     else
	     {
	         System.out.println("No");
	     }
	  }
	}
}

Keplers Law CodeChef Solution in Python

# cook your dish here
t=int(input())
while(t!=0):
    t1,t2,r1,r2=map(int,input().split())
    ra1=t1**2/t2**2
    ra2=r1**3/r2**3
    if ra1==ra2:
        print("Yes")
    else:
        print("NO")
    t=t-1
Keplers Law CodeChef Solution Review:

In our experience, we suggest you solve this Keplers Law CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Keplers Law Problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get Keplers Law CodeChef Solution.

Conclusion:

I hope this Keplers Law CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More CodeChef Solutions >>

Olympics Ranking CodeChef Solution

Problem Difficulties CodeChef Solution

Chef and Bulb Invention CodeChef Solution

Array Filling CodeChef Solution

Special Triplets CodeChef Solution

Leave a Reply

Your email address will not be published.