1656:Combination

Through a 1656: Combination

1656:Combination


Time limit: 1000 ms Memory Limit: 524288 KB
Submissions: 89 by number: 49

 

Description [title]

 

From the original title: BZOJ 2982

 

LMZ have n

Different groups of friends, his every night to choose m a for [crab], but also requires selection of not the same every night. So how many such nights LMZ can continue it? Of course, LMZ the year 10007 days, so he wanted to know the answer MOD 10007

Value.

 

[Enter]

 

A first line integer t

, Expressed t

Set of data;

 

Next t

Two lines each integers n- , m

Such as the meaning of the questions.

 

[Output]

 

t

Row, a per row, is ( n- m ) MOD 10007

s answer.

 

[Sample input]

 

4
5 1
5 2
7 3
4 2

 

[Sample Output]

 

5
10
35
6

 

【prompt】

 

Data range and tips:

 

For all data, . 1 T 200 is , . 1 m n- 2 × 10 . 8

 

This question is nothing but gold itself is God ♂ odd title

 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=10007;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline ll power(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=res*a%mod; a=a*a%mod; b>>=1;
    }
    return res;
}
inline ll C(ll n,ll m)
{
    ll n0=1,m0=1;
    for(ll i=n-m+1;i<=n;i++) n0=n0*i%mod;
    for(ll i=1;i<=m;i++) m0=m0*i%mod;
    return n0*power(m0,mod-2)%mod;
}
inline ll Lucas(ll n,ll m)
{
    if(m==0) return 1;
    return C(n%mod,m%mod)*Lucas(n/mod,m/mod)%mod;
}
int main()
{
    int t;
    t=read();
    ll n,m;
    while(t--)
    {
        n=(ll)read();
        m=(ll)read();
        printf("%lld\n",Lucas(n,m));
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/smartljy/p/11418627.html