`{"id":"57de44dc-86ea-4b81-ba8d-49aa4ff88858","name":"Modular C(n,r)","description":"You have T test cases and for each test case you have been given n and r values and you need to find nCr mod 10^9+7.","inputFormat":"The first line contains an integer T.\r\nNext T lines contain integers n and r.","outputFormat":"for each query print nCr mod 10^9+7 in a line.","constraints":"1 &lt;= T &lt;= 10^6\r\n1 &lt;= n &lt;= 3000\r\n1 &lt;= r &lt;= n","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.Arrays;\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\r\n\r\n\t\t\r\n\t}\r\n\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n4 3\r\n5 2\r\n10 8","sampleOutput":"4\r\n10\r\n45\r\n\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"910daa87-1899-4fb1-8e06-38ea272e0bd4","name":"Modular C(n,r)","slug":"modular-c-n-r","type":1}],"next":{"id":"7bbe3fe7-4b6b-43bc-a1c8-4a53e4484e5f","name":" No Max No Min","type":1,"slug":"no-max-no-min"},"prev":{"id":"9d5a9f10-abf3-450e-b16d-bb7e06f3e80f","name":"Modular Fast Exponentiation","type":1,"slug":"modular-fast-exponentiation"}}}`

# Modular C(n,r)

You have T test cases and for each test case you have been given n and r values and you need to find nCr mod 10^9+7.

`{"id":"57de44dc-86ea-4b81-ba8d-49aa4ff88858","name":"Modular C(n,r)","description":"You have T test cases and for each test case you have been given n and r values and you need to find nCr mod 10^9+7.","inputFormat":"The first line contains an integer T.\r\nNext T lines contain integers n and r.","outputFormat":"for each query print nCr mod 10^9+7 in a line.","constraints":"1 &lt;= T &lt;= 10^6\r\n1 &lt;= n &lt;= 3000\r\n1 &lt;= r &lt;= n","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.Arrays;\r\nimport java.io.BufferedReader;\r\nimport java.io.IOException;\r\nimport java.io.InputStreamReader;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void main(String[] args) throws NumberFormatException, IOException {\r\n\t\tBufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n\t\t\r\n\r\n\t\t\r\n\t}\r\n\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n4 3\r\n5 2\r\n10 8","sampleOutput":"4\r\n10\r\n45\r\n\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"086949fa-3c5e-40c6-8a9c-f9be4b400318","name":"Number Theory For Experts","slug":"number-theory-for-experts","type":0},{"id":"910daa87-1899-4fb1-8e06-38ea272e0bd4","name":"Modular C(n,r)","slug":"modular-c-n-r","type":1}],"next":{"id":"7bbe3fe7-4b6b-43bc-a1c8-4a53e4484e5f","name":" No Max No Min","type":1,"slug":"no-max-no-min"},"prev":{"id":"9d5a9f10-abf3-450e-b16d-bb7e06f3e80f","name":"Modular Fast Exponentiation","type":1,"slug":"modular-fast-exponentiation"}}}`

Editor

# Modular C(n,r)

medium

You have T test cases and for each test case you have been given n and r values and you need to find nCr mod 10^9+7.

## Constraints

1 <= T <= 10^6 1 <= n <= 3000 1 <= r <= n

## Format

### Input

The first line contains an integer T. Next T lines contain integers n and r.

### Output

for each query print nCr mod 10^9+7 in a line.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}3 4 3 5 2 10 8```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4 10 45 ```

Discussions

Show Discussion

Related Resources