Solve( 4, 3, 2); // 2
Solve(32,12, 4); //1352025675
function Solve(pN,pA,pB)
{
//始発駅と終着駅の分を引く
var RestN = pN - 2;
var RestA = pA - 2;
var RestB = pB - 2;
var Answer = nCr(RestN , RestA);
Answer *= nCr(RestA , RestB);
document.write('N=' , pN , ',A=' , pA , ',B=' , pB , ' だと' , Answer , '通り<br>');
}
//nCrを求める
function nCr(pN,pR)
{
var BunsiSet = new Array();
var BunboSet = new Array();
for(var I = pN ; pN - pR + 1 <= I ; I--) {
var SoinsuuSet = ExecSoinsuuBunkai(I);
for(var EachSoinsuu of SoinsuuSet) BunsiSet.push(EachSoinsuu);
}
for(var I = pR ; 2 <= I ; I--) {
var SoinsuuSet = ExecSoinsuuBunkai(I);
for(var EachSoinsuu of SoinsuuSet) BunboSet.push(EachSoinsuu);
}
for(var EachBunbo of BunboSet){
var wkInd = BunsiSet.indexOf(EachBunbo);
BunsiSet.splice(wkInd,1);
}
var WillReturn = 1;
for(var EachVal of BunsiSet){
WillReturn *= EachVal;
}
return WillReturn;
}
//素因数分解した結果を配列で返す
function ExecSoinsuuBunkai(pVal)
{
var WillReturn = new Array();
var CopiedVal = pVal;
for(var I = 2; I <= pVal ; I++){
while(CopiedVal % I == 0){
WillReturn.push(I);
CopiedVal /= I;
}
}
return WillReturn;
}