Codeforces 630H Benches

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

n条从北向南的路和n条从东向西的路,共n^2个交点,共5把椅子,放在交点,然后每条路上最多只能有一把椅子

求放椅子的方法数 方法比较笨,每次循环放一把椅子


#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define maxn 110
using namespace std;
int main()
{
    int n;
    long long sum;
    while(~scanf("%d",&n))
    {
        sum=1;
        int flag1=0,flag2=0,flag3=0,flag4=0;
        for(int i=0;i<5;++i)
        {
            sum*=(n-i)*(n-i);
            if(!flag1&&sum%2==0)
            {
                flag1=1;
                sum=sum/2;
            }
            if(!flag2&&sum%3==0)
            {
                flag2=1;
                sum=sum/3;
            }
            if(!flag3&&sum%4==0)
            {
                flag3=1;
                sum=sum/4;
            }
            if(!flag4&&sum%5==0)
            {
                flag4=1;
                sum=sum/5;
            }
        }
        printf("%I64d\n",sum);
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值