C - Beautiful Tables Gym - 101733C ——令人懵逼的水题

Victor usually spends free time with reading books, solving riddles and puzzles.

Yesterday he decided to come up with his own puzzle. One should fill the table of size n × n with integers from 1 to n in a such way that the sum of the numbers in each row and the sum of numbers in each column is divisible by n. Each integer from 1 to n can be used arbitrary number of times.

Help Victor to determine the number of distinct tables satisfying the requirements of the puzzle. Two table are considered to be distinct if they differ in at least one cell. As the number Victor wants to compute may be pretty big, you only need to find its remainder modulo 109 + 7.

Input
The only input line contains a single integer n (1 ≤ n ≤ 1000), the number of row and the number of columns of the table.

Output
Print the number of appropriate tables modulo 1 000 000 007.

Examples
Input
2
Output
2
Input
3
Output
81
想不到,想到就很简单了。我们考虑每一行,第一个数可以放n个,第二个可以放n个,一直放到n-1,最后一个数无论怎样都能补到n的倍数= =!因为它是二维的,所以最后一行也要贡献出来补齐,所以是n^(n-1)*(n-1)。

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll qpow(ll a,ll b)
{
    ll ret=a;
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*ret)%mod;
        ret=(ret*ret)%mod;
        b>>=1;
    }
    return ans;
}
int main()
{
    int t;
    ll n,m;
    scanf("%lld",&n);
    ll ans=qpow(n,(n-1)*(n-1));
    printf("%lld\n",ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值