Advertisement
a53

CicluHamiltonian

a53
Jan 26th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. typedef int NrMare[1010];
  4. NrMare fact;
  5.  
  6. void AtribMic(NrMare x,int n)
  7. {
  8. x[0]=0;
  9. if(n==0)
  10. x[(x[0]=1)]=0;
  11. else
  12. for(;n;n/=10)
  13. x[++x[0]]=n%10;
  14. }
  15.  
  16. void ProdusMic(NrMare x,int n)
  17. { ///x <- x*n
  18. int i,t=0;
  19. for(i=1;i<=x[0];i++,t/=10)
  20. {
  21. t+=x[i]*n;
  22. x[i]=t%10;
  23. }
  24. for(;t;t/=10)
  25. x[++x[0]]=t%10;
  26. }
  27.  
  28. int Divide(NrMare x,int n)
  29. { ///x = x /n, returneaza x%n
  30. int i,r=0;
  31. for(i=x[0];i>0;i--)
  32. {
  33. r=10*r+x[i];
  34. x[i]=r/n;
  35. r%=n;
  36. }
  37. for(;x[x[0]]==0 && x[0]>1;)
  38. x[0]--;
  39. return r;
  40. }
  41.  
  42. void Afisez(NrMare x)
  43. {
  44. for(int i=x[0];i>0;--i)
  45. cout<<x[i];
  46. }
  47.  
  48. int main()
  49. {
  50. int n;
  51. cin>>n;
  52. AtribMic(fact,1);
  53. for(int i=2;i<n;++i)
  54. ProdusMic(fact,i);
  55. Divide(fact,2);
  56. Afisez(fact);
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement