Advertisement
erfanul007

LOJ 1189

Nov 3rd, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4. long long int fac[25],ans[10005],t,x,i,j,k;
  5. fac[0] = 1;
  6. for (i=1;i<=20;i++){
  7. fac[i]=fac[i-1]*i;
  8. }
  9. scanf("%lld", &t);
  10. for (i=1;i<=t;i++){
  11. scanf("%lld",&x);
  12. j=20;
  13. k=0;
  14. while(j>=0){
  15. if(fac[j]<=x) {
  16. x=x-fac[j];
  17. k++;
  18. ans[k]=j;
  19. }
  20.  
  21. j--;
  22. }
  23. if(x==0) {
  24. printf("Case %lld: ",i);
  25. for(j=k;j>0;j--){
  26. if(j==1)
  27. printf("%lld!\n",ans[j]);
  28. else
  29. printf("%lld!+",ans[j]);
  30. }
  31. }
  32. else {
  33. printf("Case %d: impossible\n",i);
  34. }
  35. }
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement