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.
The only input line contains a single integer n (1 ≤ n ≤ 1000), the number of row and the number of columns of the table.
Print the number of appropriate tables modulo 1 000 000 007.
2
2
3
81
题意:
n*n的矩阵,拿1-n中的数随意填,可多次。
条件是行和 列和 可整出n.
算法:
n^((n-1)*(n-1));
别看了,真的就一个公式,当时看题时知道时推公式,死活搞半天,看题解woc。
推理过程:n*n的矩阵,只要前n-1行,n-1列随意填(每个空有n种填法),第n行和n列就确定了。。。
代码:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
typedef long long ll;
ll b;
const ll a=1000000007;
int main()
{
scanf("%lld",&b);
ll sum=1;
for(int i=1;i<=(b-1)*(b-1);i++)
{
sum*=b;
sum%=a;
}
printf("%lld\n",sum);
return 0;
}