Advertisement
a53

StarsAndBars1

a53
Apr 20th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include<iostream>
  2. #define NMax 10000
  3. using namespace std;
  4. typedef short Huge[NMax+3];
  5. int n, k;
  6. void AtribValue(Huge H,short X)
  7. {
  8. H[0] = 0;
  9. while (X)
  10. {
  11. ++H[0];
  12. H[H[0]] = X % 10;
  13. X /= 10;
  14. }
  15. }
  16. void Mult(Huge H,short X)
  17. {
  18. short i,T=0;
  19. for (i=1;i<=H[0];i++)
  20. {
  21. H[i]=H[i]*X+T;
  22. T=H[i]/10;
  23. H[i]=H[i]%10;
  24. }
  25. while (T)
  26. { H[++H[0]]=T%10;
  27. T/=10;
  28. }
  29. }
  30.  
  31. void Divide(Huge A,short X)
  32. {
  33. short i,R=0;
  34. for (i=A[0];i;i--)
  35. {
  36. A[i]=(R=10*R+A[i])/X;
  37. R%=X;
  38. }
  39. while (!A[A[0]] && A[0]>1) A[0]--;
  40. }
  41.  
  42. void Afisez(Huge H)
  43. {
  44. for(short i=H[0];i>0;--i)
  45. cout<<H[i];
  46. cout<<'\n';
  47. }
  48.  
  49. void BinComb(unsigned int n,unsigned int k)
  50. {
  51. Huge res;
  52. AtribValue(res,1);
  53. if(k>n-k)
  54. k=n-k;
  55. for(unsigned int i=0;i<k;++i)
  56. {
  57. Mult(res,n-i);
  58. Divide(res,i+1);
  59. }
  60. Afisez(res);
  61. }
  62.  
  63. int main()
  64. {
  65. int n;
  66. cin>>n>>k;
  67. n=n+k-1;
  68. k--;
  69. BinComb(n,k);
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement