➤ Problem Link : MARBLES
👉 Hint : Efficient approach for finding combinations
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int ll Comb(ll n,ll r) { ll l=min(r-1,n-r-1); ll res=1; for(ll i=0;i<=l;i++) res=res*(n-i)/(i+1); return res; } int main() { int t; cin>>t; while(t--) { ll n,k; cin>>n>>k; cout<<Comb(n-1,k-1)<<endl; } }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!