Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long double comb(long double n, long double k)
  6. {
  7. long double ans = 1;
  8. long double lim = n - k;
  9. long double j = 1;
  10. long double q = 1;
  11. for(long double i = k + 1; i <= n; i++)
  12. {
  13. ans *= i;
  14. if(j <= lim)
  15. {
  16. ans /= j;
  17. j++;
  18. }
  19. while(ans >= 1 && q <= n)
  20. {
  21. ans *= 0.5;
  22. q++;
  23. }
  24. }
  25. while(j <= lim)
  26. {
  27. ans /= j;
  28. j++;
  29. }
  30. while(q <= n)
  31. {
  32. ans *= 0.5;
  33. q++;
  34. }
  35. return ans;
  36. }
  37.  
  38. int main()
  39. {
  40. int x, y;
  41. cin >> x >> y;
  42. x--;
  43. y--;
  44. long double a = comb(x + y, y);
  45. cout << a << "\n";
  46. return 0;
  47. }
  48. /**
  49.  
  50. **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement