Advertisement
Saleh127

UVA 623

Oct 22nd, 2020
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. ll fact[500000];
  7.  
  8. ll gunn(ll x,ll fact[],ll sizee)
  9. {
  10. ll c=0,r;
  11.  
  12. for(ll i=0;i<sizee;i++)
  13. {
  14. r=fact[i]*x+c;
  15. fact[i]=r%10;
  16. c=r/10;
  17. }
  18. while(c)
  19. {
  20. fact[sizee]=c%10;
  21. c/=10;
  22. sizee++;
  23. }
  24. return sizee;
  25. }
  26.  
  27. void factorial(ll n)
  28. {
  29. fact[0]=1;
  30. ll sizee=1;
  31. for(ll i=2;i<=n;i++)
  32. {
  33. sizee=gunn(i,fact,sizee);
  34. }
  35.  
  36. for(ll i=sizee-1;i>=0;i--)
  37. {
  38. cout<<fact[i];
  39. }
  40. cout<<endl;
  41. }
  42.  
  43. int main()
  44. {
  45. ios_base::sync_with_stdio(0);
  46. cin.tie(0);cout.tie(0);
  47.  
  48. ll a;
  49. while(cin>>a)
  50. {
  51. cout<<a<<"!"<<endl;
  52. factorial(a);
  53. }
  54. return 0;
  55. }
  56.  
Advertisement
RAW Paste Data Copied
Advertisement