CodeForces_1658B

这篇博客介绍了如何证明当n为偶数时,gcd(1×p1,2×p2,...,n×pn)的最大值为2^n,并给出了构造方法。对于奇数n,结果为0。代码中包含了计算gcd的函数和一个初始化 gcd 结构的函数,适合竞赛或算法题目的解题参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

链接

思路

g c d ( 1 × p 1 , 2 × p 2 , . . . , n × p n ) gcd(1\times p_1,2\times p_2,...,n\times p_n) gcd(1×p1,2×p2,...,n×pn) 最大值为 2 2 2

证明参考:CF官网证明

n n n 为偶数的时。

构造方法为:奇数与偶数匹配,偶数与奇数匹配,答案数量为 ( n 2 ! ) 2 (\frac{n}{2}!)^2 (2n!)2

n n n 为奇数时,答案为 0 0 0

代码

// #pragma GCC optimize(3)
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#define endl '\n'
#define fi first
#define se second
#define PI acos(-1)
#define LL long long
#define INF 0x3f3f3f3f
#define lowbit(x) (-x&x)
#define PII pair<int, int>
#define ULL unsigned long long
#define PIL pair<int, long long>
#define mem(a, b) memset(a, b, sizeof a)
#define rev(x) reverse(x.begin(), x.end())
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

using namespace std;

const int N = 1e3 + 10, mod = 998244353;

int n;
int ans[N];

int fac(int x) {
	int res = 1;
	for (int i = 1; i <= x; i ++ ) res = (LL)res * i % mod;
	return res;
}

void init() {
	for (int i = 1; i <= 1000; i ++ ) {
		if (i & 1) ans[i] = 0;
		else ans[i] = (LL)fac(i / 2) % mod * fac(i / 2) % mod;
	}
}

void solve() {
	init();
	
	int tt = 1;
    cin >> tt;
    while (tt -- ) {
    	cin >> n;
    	cout << ans[n] << endl;
    }
}

int main() {
	IOS;
	
	solve();
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值