Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- long long int a[30];
- int main()
- {
- long long int i,n,j,k,l,b[20],c,d,t;
- a[0]=1;
- for(i=1;i<=20;i++)
- {
- a[i]=a[i-1]*i;
- }
- cin>>t;
- for(l=1;l<=t;l++)
- {
- cin>>n;
- j=0;
- int flag=0;
- cout<<"Case "<<l<<": ";
- for(i=20,j=0;i>=0;i--)
- {
- if(n>a[i])
- {
- b[j++]=i;
- n-=a[i];
- }
- else if(n==a[i])
- {
- b[j++]=i;
- flag=1;
- break;
- }
- }
- if(flag==0)
- cout<<"impossible"<<endl;
- else
- {
- for(k=j-1;k>0;k--)
- cout<<b[k]<<"!+";
- cout<<b[k]<<"!"<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement