#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main()
{
ll a[24], t, n;
int i, j = 1;
a[0] = 1;
for(i=1;i<21;i++)
{
a[i] = a[i-1] * i;
}
cin >> t;
while(t--)
{
cin >> n;
vector<ll>v;
for(i=20;i>=0;i--)
{
if(n >= a[i])
{
v.push_back(i);
n = n - a[i];
}
}
reverse(v.begin(), v.end());
if(n != 0)
cout << "Case " << j++ << ": " << "impossible" << "\n";
else
{
cout << "Case " << j++ << ": ";
for(i=0;i<v.size();i++)
{
cout << v[i] << "!";
if(i != v.size()-1)
cout << "+";
}
cout << "\n";
}
}
return 0;
}
#define ll unsigned long long int
using namespace std;
int main()
{
ll a[24], t, n;
int i, j = 1;
a[0] = 1;
for(i=1;i<21;i++)
{
a[i] = a[i-1] * i;
}
cin >> t;
while(t--)
{
cin >> n;
vector<ll>v;
for(i=20;i>=0;i--)
{
if(n >= a[i])
{
v.push_back(i);
n = n - a[i];
}
}
reverse(v.begin(), v.end());
if(n != 0)
cout << "Case " << j++ << ": " << "impossible" << "\n";
else
{
cout << "Case " << j++ << ": ";
for(i=0;i<v.size();i++)
{
cout << v[i] << "!";
if(i != v.size()-1)
cout << "+";
}
cout << "\n";
}
}
return 0;
}
Comments
Post a Comment