Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- long long int fac[25],ans[10005],t,x,i,j,k;
- fac[0] = 1;
- for (i=1;i<=20;i++){
- fac[i]=fac[i-1]*i;
- }
- scanf("%lld", &t);
- for (i=1;i<=t;i++){
- scanf("%lld",&x);
- j=20;
- k=0;
- while(j>=0){
- if(fac[j]<=x) {
- x=x-fac[j];
- k++;
- ans[k]=j;
- }
- j--;
- }
- if(x==0) {
- printf("Case %lld: ",i);
- for(j=k;j>0;j--){
- if(j==1)
- printf("%lld!\n",ans[j]);
- else
- printf("%lld!+",ans[j]);
- }
- }
- else {
- printf("Case %d: impossible\n",i);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement