2018 Yandex.Algorithm - Qualification Round C. Beautiful Tables 数学

这篇博客探讨了一种数学问题,涉及构造n×n的格子表,使得每行每列的数字之和都能被n整除。作者提供了一个C++代码实现,用于快速计算满足条件的表格数量,并给出了输入输出示例。问题的关键在于理解并应用模运算和快速幂算法来解决大规模数值计算的问题。
摘要由CSDN通过智能技术生成

C. Beautiful Tables

在这里插入图片描述

code

/*SiberianSquirrel*/
/*CuteKiloFish*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1), eps = 1e-8;
/*const int MOD = 998244353, r = 119, k = 23, g = 3;
const int MOD = 1004535809, r = 479, k = 21, g = 3;*/
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int M = 1e7 + 10, N = 2e6 + 10;
int sgn(double x) {
    if(fabs(x) < eps) return 0;
    return x < 0? -1: 1;
}
//inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
//double Rand() {return (double)rand() / RAND_MAX;}

int n;

ll quick_pow(ll ans, ll p, ll res = 1) {
    for(; p; p >>= 1, ans = ans * ans % MOD)
        if(p & 1) res = res * ans % MOD;
    return res % MOD;
}

void init() {}

void solve(ll res = 0) {
    res = quick_pow(n, (n - 1) * (n - 1));
    cout << res % MOD;
}


int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(nullptr);
// srand(time(0));
#ifdef ACM_LOCAL
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    init();
    int o = 1;
//	cin >> o;
    while(o --) {
        cin >> n;
        solve();
    }
    return 0;
}

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值