Problem
You are given positive integers and .
You have to construct an array of length such that :
- , where denotes the gcd of all elements of the subarray .
If multiple such arrays exist, print any.
Report if no such array exists.
Note that denotes the subarray .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of single line of input.
- The only line of each test case contains two space-separated integers and — the number of elements and required sum.
Output Format
For each test case, output on a new line space-separated integers, denoting array .
Report if no such array exists.
code of this question ----- take it as only reference
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long j,k;
cin>>j>>k;
long long min_sum_gcd = j*(j+1);
min_sum_gcd/=2;
min_sum_gcd-=1;
if(k<min_sum_gcd)
{
cout<<"-1"<<endl;
return;
}
for(int i=1; i<j; ++i)
cout<<"1"<<" ";
cout<<k-min_sum_gcd<<endl;
}
int main()
{
long long t;
cin >>t;
while(t--)
{
solve();
}
return 0;
}


No comments:
Post a Comment