- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define M 1000003
- ll fact[M];
- ll bigmod(ll p, ll q){
- if(q == 1) return p%M;
- if(q%2 == 0){
- ll a = bigmod(p, q/2);
- return ((a%M)*(a%M))%M;
- }
- else{
- ll a = bigmod(p, q-1);
- return (a*p)%M;
- }
- }
- void pre(){
- fact[0] = 1;
- for(int i = 1; i <M; i++){
- fact[i] = (i*(fact[i-1]%M))%M;
- //if(fact[i]<=0)printf(" fact[%d] = %lld \n", i, fact[i]);
- }
- }
- int main(){
- pre();
- int ts;
- cin>>ts;
- for(int k = 1; k <= ts; k++){
- int n, r;
- scanf("%d%d", &n, &r);
- if(n<r){
- printf("Case %d: 0\n", k);
- continue;
- }
- else if(n == r || r == 0){
- printf("Case %d: 1\n", k);
- continue;
- }
- ll s = bigmod((fact[n-r]*fact[r])%M,M-2)%M;
- ll p = (fact[n]*s)%M;
- printf("Case %d: %lld\n", k,p);
- }
- return 0;
- }
Thursday 27 July 2017
Lightoj 1067 - Combinations
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
Problem link: Problem Analysis: It is actually a basic Bisection problem , as we can see here we can not actually find a formula fo...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
No comments:
Post a Comment