January Long 2022 - I (Rated for Div 3)
Keplers Law
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 () and Semimajor Axes () 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 , denoting the number of test cases. The description of test cases follows.
- Each test case consists a single line of input, containing four space-separated integers .
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
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 :
- Test Case :
- Test Case :
Solution in C++ :
Covid Spread
A disease is spreading through ChefLand!
The disease spreads as follows:
- At the end of day , a single person is infected with the disease.
- During the next days, the number of infected people doubles each day, until the disease has spread to all people in ChefLand.
- From day onwards, the number of infected people triples each day, until the disease has spread to all people in ChefLand.
You are given the population of ChefLand and a day . How many people in ChefLand are infected at the end of day ?
Input Format
- The first line of input contains a single integer , denoting the number of test cases. The description of test cases follows.
- Each test case consists of a single line containing two space-separated integers and — the population of ChefLand and the day for which you need to find the number of infected people, respectively.
Output Format
- For each test case, print one line containing a single integer — the number of infected people in ChefLand at the end of day .
Constraints
Subtasks
Subtask 1 (30 points):
Subtask 2 (70 points): Original constraints
Sample Input 1
4
100 3
2000 10
6000 11
10 11
Sample Output 1
8
1024
3072
10
Explanation
Test Case 1:
- At the end of day , the number of infected people is .
- At the end of day , the number of infected people is .
- At the end of day , the number of infected people is .
Test Case 2: Following the rules in the statement, it can be seen that at the end of day , the total number of infected people is .
Test Case 3: Note that starting at day , the number of infected people triples each day, .
Test Case 4: At the end of day , the number of infected people is . Since there are only people in ChefLand (which is less than ), at the end of day all people in ChefLand are infected and thus the number of infected people is for all days from day onwards, including day .
Solution in C++ :
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t,i,s=1;
cin>>t;
while(t--){
long long int a,b,s=1;
cin>>a>>b;
for(int i=1;i<=b&&s<a;i++){
if(i<11) s*=2;
else s*=3;
}
if(s>=a) s=a;
cout<<s<<endl;
}
return 0;
}
Prime in a binary string
You are given a binary string of length . Your task is to check if there exists a substring of which is the binary representation of a prime number.
Formally, check if there exist integers and such that , and the substring , when treated as a binary integer, is prime.
Print "Yes"
if such a substring exists, and "No"
if it doesn't.
Input Format
- The first line of input contains a single integer , denoting the number of test cases. The description of test cases follows.
- Each testcase consists of a single line of input, containing a binary string .
Output Format
For each test case, output a single line containing one string — "Yes"
or "No"
, 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
- The sum of over all tests does not exceed
Subtasks
Subtask 1 (30 points):
Subtask 2 (70 points):
- Original constraints
Sample Input 1
3
1
111
101101
Sample Output 1
No
Yes
Yes
Explanation
Test case : There is only one substring, namely "1"
, and it isn't prime.
Test case : The substrings of the given string are "1"
, "11"
, "111"
, "1"
, "11"
, "1"
. Of these, "111"
which represents in binary, and "11"
which represents in binary, are primes.
Test case : One of the substrings of the string is "1101"
, which is the binary representation of — a prime.
Solution in C++ :
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int c=0,p=-1;
string s; cin>>s;
int n=s.length();
if(n==1) {cout<<"NO"<<endl;continue;}
for(int i=0;i<=n;i++) if(s[i]=='1') {c++;p=i+1;}
if(c==0 ||(c==1&&p==n)) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}