Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #define mod 1000000007
- using namespace std;
- unsigned long long int factor(int n){
- if(n<2) return 1;
- else if(n > 1) return (n*factor(n-1) % mod);
- }
- void factroial(unsigned long long int fact[]){
- fact[1] = 1;
- for(int i = 2; i < 1001; i++){
- //unsigned long long int k = (fact[i-1] * i) % mod;
- //fact[i] = k;
- fact[i] = factor(i);
- }
- }
- int main(){
- unsigned long long int fact[1001];
- factroial(fact);
- int t; cin >> t;
- while(t--){
- /*
- for(int i = 1; i < 1001; i++){
- cout << fact[i] << ' ';
- }
- cout << endl;
- cout << fact[5];
- */
- int n, r;
- cin >> n >> r;
- if(r > n) cout << 0 << endl;
- else{
- cout << (fact[n] / ((fact[r] * fact[n-r])% mod) % mod) << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment