对于给定的非负整数r和n(r≤n),请编写程序计算组合数C(r,n) = n! r! (n-r)!。 (本题目用于测试的所有用例,都保证结果小于231-1)
示例1
输入
2,3
输出
3
说明
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * calculate combination Number * @param r int整型 * @param n int整型 * @return int整型 */ public int combination (int r, int n) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * calculate combination Number * @param r int整型 * @param n int整型 * @return int整型 */ int combination(int r, int n) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # calculate combination Number # @param r int整型 # @param n int整型 # @return int整型 # class Solution: def combination(self , r , n ): # write code here
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * calculate combination Number * @param r int整型 * @param n int整型 * @return int整型 */ function combination( r , n ) { // write code here } module.exports = { combination : combination };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # calculate combination Number # @param r int整型 # @param n int整型 # @return int整型 # class Solution: def combination(self , r , n ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * calculate combination Number * @param r int整型 * @param n int整型 * @return int整型 */ func combination( r int , n int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * calculate combination Number * @param r int整型 * @param n int整型 * @return int整型 */ int combination(int r, int n ) { // write code here }
2,3
3