Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<list>
- #include<string>
- #include<cstring>
- #include<sstream>
- #include<cctype>
- #include<string.h>
- #include<algorithm>
- #include<cmath>
- #include<stack>
- #include<fstream>
- #include<cstdlib>
- #include<vector>
- #include<map>
- #include<set>
- #include<utility>
- #include<iomanip>
- #include<queue>
- using namespace std;
- #define LL long long int
- #define uLL unsigned long long int
- #define S(a) scanf("%d",&a)
- #define S2(a,b) scanf("%d%d",&a,&b)
- #define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)
- #define SLL(a) scanf("%lld",&a)
- #define SLL2(a,b) scanf("%lld%lld",&a,&b)
- #define SLL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
- #define SC(a) scanf("%c",&a)
- #define P(a) printf("%d",a)
- #define PS(a) printf("%s",a)
- #define PLL(a) printf("%lld",a)
- #define PCASE(kk) printf("Case %d: ",kk++)
- #define PCASENL(kk) printf("Case %d:\n",kk++)
- #define NL puts("")
- #define pb(a) push_back(a)
- #define mp(a,b) make_pair(a,b)
- #define pi (2.0*acos(0.0))
- #define pii pair<int,int>
- #define SQR(a) (a*a)
- template<typename T>inline T POW(T B,T P)
- {
- if(P==0) return 1;
- if(P&1) return B*POW(B,P-1);
- else return SQR(POW(B,P/2));
- }
- template <typename T>inline T ModInv (T b,T m)
- {
- return BigMod(b,m-2,m);
- }
- template<typename T>inline T ABS(T a)
- {
- if(a<0)return -a;
- else return a;
- }
- template<typename T>inline T gcd(T a,T b)
- {
- if(a<0)return gcd(-a,b);
- if(b<0)return gcd(a,-b);
- return (b==0)?a:gcd(b,a%b);
- }
- template<typename T>inline T lcm(T a,T b)
- {
- if(a<0)return lcm(-a,b);
- if(b<0)return lcm(a,-b);
- return a*(b/gcd(a,b));
- }
- template <class T> inline T BMOD(T p,T e,T m)
- {
- T ret=1;
- while(e)
- {
- if(e&1) ret=(ret*p)%m;
- p=(p*p)%m;
- e>>=1;
- }
- return (T)ret;
- }
- //for(__typeof(pp.begin()) i=pp.begin(); i!=pp.end(); i++ )
- //knight and king move....
- //int Dx[]={-2,-1,1,2,1,2,-2,-1};
- //int Dy[]={-1,-2,2,1,-2,-1,1,2};
- //int dx[]={-1,1,0,0};
- //int dy[]={0,0,-1,1};
- //int dx[]= {-1,-1,0,0,1,1};
- //int dy[]= {-1,0,-1,1,0,1};
- //////////////////////////////////////////////////
- LL n;
- LL fact[30];
- vector< pair<LL,LL> >v;
- int main()
- {
- fact[0]=1LL;
- LL x=1LL;
- for(int i=1; i<=20; i++)
- {
- fact[i]=i*fact[i-1];
- // cout<<i<<" "<<fact[i]<<endl;
- x+=fact[i];
- if(x>1000000000000000000LL)
- {
- // P(i),NL;
- break;
- }
- }
- // cout<<x<<endl;
- // cout<<"......"<<endl;
- for(int i=1; i<=524288; i++)
- {
- LL tt=i;
- LL res=0;
- for(int j=0; j<=19; j++)
- {
- if((tt&(1LL<<j)))
- {
- res+=fact[j];
- }
- }
- // cout<<i<<" "<<res<<endl;
- if(res>1000000000000000000LL)break;
- v.pb(mp(res,tt));
- }
- sort(v.begin(),v.end());
- // cout<<"...... "<<v[524900].first<<endl;
- int t,tc=1;
- S(t);
- while(t--)
- {
- // LL n;
- SLL(n);
- LL lo=0,hi=v.size(),mid;
- LL ans=-1;
- while(lo<=hi)
- {
- mid=(lo+hi)/2;
- // cout<<lo<<" "<<hi<<" "<<" "<<mid<<" "<<v[mid].first<<endl;
- if(v[mid].first==n)
- {
- ans=mid;
- break;
- }
- if(v[mid].first<n)
- {
- lo=mid+1;
- }
- else
- {
- hi=mid-1;
- }
- }
- PCASE(tc);
- if(ans==-1)printf("impossible\n");
- else
- {
- LL ss=v[ans].second;
- int fl=0;
- for(int i=0; i<=19; i++)
- {
- if((ss&(1LL<<i)))
- {
- if(!fl)
- {
- printf("%d!",i),fl=1;
- }
- else printf("+%d!",i);
- }
- }
- NL;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement