forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP15.cpp
More file actions
47 lines (47 loc) · 878 Bytes
/
P15.cpp
File metadata and controls
47 lines (47 loc) · 878 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
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<math.h>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#define MAXN 1000000
#define LL long long
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
LL gcd(LL a,LL b)
{
LL temp;
if(a<b)
{
temp = a;
a = b;
b = temp;
}
if(b==0) return 1;//本程序不会出现此情况
while(a%b)
{
temp = b;
b = a%b;
a = temp;
}
return b;
}
int main()
{
LL res1=1LL,res2=1LL,g;
for(int i=40,j=20;i>20;i--,j--)//等价限制条件:j>0
{
res1*=i;
res2*=j;
g = gcd(res1,res2);//防止数据过大
res1/=g;
res2/=g;
}
printf("There are %I64d routes through a 20×20 grid.\n",res1);
}