Advertisement
Saleh127

UVA 10220

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