Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int main()
- {
- unsigned long long fact[22];
- fact[0]=1;
- for(int i=1;i<=20;i++)fact[i]=fact[i-1]*i;
- ll test;
- cin>>test;
- for(ll c=1;c<=test;c++)
- {
- ll x,i;
- cin>>x;
- stack<ll>s;
- i=20;
- while(i>=0)
- {
- if(fact[i]<=x)
- {
- s.push(i);
- x-=fact[i];
- }
- i--;
- }
- if(x==0)
- {
- printf("Case %lld: ",c);
- while(s.size()!=1)
- {
- x=s.top();
- printf("%d!+",x);
- s.pop();
- }
- x=s.top();
- s.pop();
- printf("%lld!\n",x);
- }
- else
- {
- printf("Case %lld: impossible\n",c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement