Problem Link
#include <iostream>
using namespace std;
int main()
{
int t, n, k;
cin >> t;
while(t--)
{
cin >> n >> k;
if(n == 1)
{
cout << k << endl;
continue;
}
if(k == 1)
{
for(int j = 0; j < n; j++)
{
cout << "1 ";
}
cout << endl;
continue;
}
if(k == 2)
{
cout << "2 ";
for(int j = 1; j < n; j++)
{
cout << "1 ";
}
cout << endl;
continue;
}
if(k == 3)
{
if(n % 2)
{
cout << "3 ";
for(int j = 1; j < n; j++)
{
cout << "1 ";
}
cout << endl;
}
else
{
cout << "2 ";
for(int j = 1; j < n; j++)
{
cout << "1 ";
}
cout << endl;
}
continue;
}
else
{
long res = 1;
while(res <= k)
{
res = 2 * res;
}
res = res / 2;
cout << res << " ";
if(n % 2 == 0)
{
cout << res - 1 << " ";
}
else
{
cout << res - 2 << " ";
}
for(int j = 2; j < n; j++)
{
cout << "1 ";
}
cout << endl;
}
}
}
#include <iostream>
using namespace std;
int main()
{
int t, n, k;
cin >> t;
while(t--)
{
cin >> n >> k;
if(n == 1)
{
cout << k << endl;
continue;
}
if(k == 1)
{
for(int j = 0; j < n; j++)
{
cout << "1 ";
}
cout << endl;
continue;
}
if(k == 2)
{
cout << "2 ";
for(int j = 1; j < n; j++)
{
cout << "1 ";
}
cout << endl;
continue;
}
if(k == 3)
{
if(n % 2)
{
cout << "3 ";
for(int j = 1; j < n; j++)
{
cout << "1 ";
}
cout << endl;
}
else
{
cout << "2 ";
for(int j = 1; j < n; j++)
{
cout << "1 ";
}
cout << endl;
}
continue;
}
else
{
long res = 1;
while(res <= k)
{
res = 2 * res;
}
res = res / 2;
cout << res << " ";
if(n % 2 == 0)
{
cout << res - 1 << " ";
}
else
{
cout << res - 2 << " ";
}
for(int j = 2; j < n; j++)
{
cout << "1 ";
}
cout << endl;
}
}
}
Comments
Post a Comment