Page Contents
Codechef Keplers Law KEPLERSLAW 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

Solution
Program: Keplers Law KEPLERSLAW Solution in C++
#include <bits/stdc++.h> using namespace std; int main() { int T; cin>>T; while(T--){ int t1,t2,r1,r2; 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; } } }
Program: Keplers Law KEPLERSLAW Solution in Java
import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int t1=sc.nextInt(); int t2=sc.nextInt(); int r1=sc.nextInt(); int r2=sc.nextInt(); if(((Math.pow(t1,2))/(Math.pow(r1,3)))==((Math.pow(t2,2))/(Math.pow(r2,3)))) System.out.println("YES"); else System.out.println("NO"); } } }
Program: Keplers Law KEPLERSLAW Solution in Python
t=int(input()) for i in range(t): t1,t2,r1,r2=map(int,input().split()) if t1**2/r1**3==t2**2/r2**3: print("YES") else: print("NO")
January Long Challenge 2022 Solution
- TCS Examination EXAMTIME Solution Codechef
- Chef and Fixed Deposits MINFD Solution Codechef
- Crying Colours CRYCOLR Solution Codechef
- Power Sum POWSUM Solution Codechef
- Sum and OR SUMANDOR Solution Codechef
- Tree Master TRMT Solution Codechef
- Array Partition ARRPART Solution Codechef
- Keplers Law KEPLERSLAW Solution
- Covid Spread COVSPRD Solution
- Prime in a binary string PINBS Solution
- Retrieve back the Array XORED Solution
- Chef and Riffles RIFFLES Solution
- Sequence Master MASTER Solution
- Generating Cycles GENECYC Solution
December Long Challenge 2021 Solution
- List of Lists LISTLIST Solution Codechef
- Valleys and Hills VANDH Solution Codechef
- Rock Paper Scissors ROPASCI Solution Codechef
- Squares Counting GRIDSQRS Solution Codechef
- Pyramid Traversal PYRAMIDMOVES Solution Codechef
- Increasing String INCREAST Solution Codechef
- Utkarsh and Placement tests UTKPLC Solution Codechef
- Check Mate CHECKMATE Solution Codechef