codeforces_630H. Benches

来源:互联网 发布:自动生成条码软件 编辑:程序博客网 时间:2024/05/16 01:43
H. Benches
time limit per test
0.5 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.

The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.

Help the park administration count the number of ways to place the benches.

Input

The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.

Output

Output one integer — the number of ways to place the benches.

Examples
input
5
output
120

这道题我掉了个大坑,就是long long 的溢出问题,本来以为下面的代码必过,然而痛苦了好一阵子

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std;int main(){    int n,i;    scanf("%d",&n);    long long ans=1;    for(i=1;i<=5;i++)    {        ans*=n*n;        n--;    }    ans/=120;    printf("%lld\n",ans);    return 0;}
明白溢出问题后,就修改了乘法过程。

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std;int main(){    int n;    scanf("%d",&n);    long long ans;    ans=n*(n-1)/2*(n-2)/3*(n-3)/4*(n-4)/5;    printf("%lld\n",ans*ans*120);    return 0;}


0 0
原创粉丝点击