Advertisement
Farjana_akter

Untitled

Feb 13th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long int a[30];
  5. int main()
  6. {
  7. long long int i,n,j,k,l,b[20],c,d,t;
  8. a[0]=1;
  9. for(i=1;i<=20;i++)
  10. {
  11. a[i]=a[i-1]*i;
  12. }
  13. cin>>t;
  14. for(l=1;l<=t;l++)
  15. {
  16. cin>>n;
  17. j=0;
  18. int flag=0;
  19. cout<<"Case "<<l<<": ";
  20. for(i=20,j=0;i>=0;i--)
  21. {
  22. if(n>a[i])
  23. {
  24. b[j++]=i;
  25. n-=a[i];
  26. }
  27. else if(n==a[i])
  28. {
  29.  
  30. b[j++]=i;
  31. flag=1;
  32. break;
  33. }
  34. }
  35. if(flag==0)
  36. cout<<"impossible"<<endl;
  37. else
  38. {
  39. for(k=j-1;k>0;k--)
  40. cout<<b[k]<<"!+";
  41. cout<<b[k]<<"!"<<endl;
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement