Equal Beauty CodeChef SnackDown 2021 Round 1A Question The beauty of an (non-empty) array of integers is defined as the difference between its largest and smallest element. For example, the beauty of the array [2,3,4,4,6] is 6−2=4. An array A is said to be good if it is possible to partition the elements of A into two non-empty arrays B1 and B2 such that B1 and B2 have the same beauty. Each element of array A should be in exactly one array: either in B1 or in B2. For example, the array [6,2,4,4,4] is good because its elements can be partitioned into two arrays B1=[6,4,4] and B2=[2,4], where both B1 and B2 have the same beauty (6−4=4−2=2). You are given an array A of length N. In one move you can: Select an index i (1≤i≤N) and either increase Ai by 1 or decrease Ai by 1. Find the minimum number of moves required to make the array A good. Input Format The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow. Each ...
Min Max LCM CodeChef SnackDown 2021 Round 1A Solution
Question
You are given two positive integers X and K.
You have to output the minimum and maximum value of LCM(i,j) where X≤i<j≤X⋅K.
We define LCM(i,j) for two positive integers i and j as the minimum positive integer y such that both i and j divide y without remainder.
Input Format
First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, two space separated integers X and K.
Output Format
For each testcase, output two space separated integers - the minimum and maximum possible value respectively of LCM(i,j) where X≤i<j≤X⋅K.
Constraints
1≤T≤10^5
1≤X≤10^8
2≤K≤10^8
It is guaranteed that, for each test case, X⋅K≤10^9
Sample Input 1
2
4 3
2 3
Sample Output 1
8 132
4 30
Explanation
Test Case 1: We want to find the minimum and maximum value of LCM(i,j) for 4≤i<j≤12. It is easy to verify that the LCM(4,8)=8 is the minimum possible value whereas LCM(11,12)=132 is the maximum value.
Test Case 2: We want to find the minimum and maximum value of LCM(i,j) for 2≤i<j≤6. The maximum value is obtained for the pair (5,6) whereas the minimum is obtained for the pair (2,4).
Program Code in C++
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll t;
cin>>t;
while(t--){
ll x,y;
cin>>x>>y;
cout<<x*2<<" "<<((x*y)-1)*(x*y)<<endl;
}
return 0;
}
Comments
Post a Comment