-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.cpp
More file actions
38 lines (31 loc) · 620 Bytes
/
t.cpp
File metadata and controls
38 lines (31 loc) · 620 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std;
long long factorial(long long num1, long long num2)
{
long long result = 1, temp = 2;
for (int i = num2 + 1; i <= num1; i++)
{
result *= i;
if (temp <= num1 - num2 && result % temp == 0)
{
result /= temp;
temp++;
}
}
return result;
}
int main()
{
long long n, r;
cin >> n >> r;
// long long fN = factorial(n), fR = factorial(r), fNR = factorial(n - r);
if (n < r)
{
cout << 0 << endl;
}
else
{
cout << factorial(n, r) << endl;
}
return 0;
}