Skip to content

Commit 66ef847

Browse files
committed
70차 1번 제출
1 parent dfaa21d commit 66ef847

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

live6/test70/문제1/이지은.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map(Number);
7+
8+
function combination(n, r) {
9+
if (r > n || r < 0) return 0;
10+
r = Math.min(r, n - r);
11+
let result = 1;
12+
for (let i = 0; i < r; i++) {
13+
result *= n - i;
14+
result /= i + 1;
15+
}
16+
return result;
17+
}
18+
19+
function solution(input) {
20+
const [n, m] = input;
21+
22+
if (n > m) return 0;
23+
24+
const remainingFruits = m - n;
25+
const result = combination(remainingFruits + n - 1, n - 1);
26+
return result;
27+
}
28+
29+
console.log(solution(input));

0 commit comments

Comments
 (0)