- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M (long long)1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- LL factorial[M+3];
- void findFact(){
- factorial[0] = 1;
- for(int i = 1; i < S; i++){
- factorial[i] = factorial[i-1] * i;
- factorial[i] %= M;
- }
- }
- LL modInverse(LL a, LL p){
- if(p == 0)return 1LL;
- else if(p%2)return ((a%M)*(modInverse(a, p-1)%M))%M;
- else{
- LL x = modInverse(a, p/2);
- return (x%M*x%M)%M;
- }
- }
- int main(){
- memset(factorial, 1LL, sizeof(factorial));
- findFact();
- int t, cs = 0;
- LL n, k;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d", &n, &k);
- LL y = factorial[n];
- LL z = (factorial[n-k]%M*factorial[k]%M)%M;
- LL ans = modInverse(z, M-2LL);
- ans = (y%M*ans%M)%M;
- printf("Case %d: %lld\n", ++cs, ans);
- }
- return 0;
- }
Sunday, February 28, 2016
LightOJ - 1067 - Combinations
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment