I. Pudding Store

Problem - I - Codeforces

这道题对前三个进行特判,然后  > 3 的部分就是这样找规律找出来的。 

下面是打表代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define int long long
using namespace std;

constexpr int mod = 998244353;

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n = 4;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		a[i] = i + 1;
	int ans = 0;
	bool flag = true;
	do
	{
		flag = true;
		int idx = 1;
		while (idx <= n)
		{
			int sum = 0;
			for (int i = 0; i < idx; i++)
			{
				sum += a[i] * 2;
			}
			if (sum % idx != 0)
				flag = false;
			idx++;
		}
		if (flag)
		{
			for (int i = 0; i < n; i++)
				cout << a[i] << " \n"[i == n - 1];
			ans++;
		}

	} while (next_permutation(a.begin(), a.end()));
	cout << ans << "\n";
	return 0;
}

下面是 ac 代码

小于 4 的时候就按个特判就行

规律就是 > 4 的时候是 6 * (2 ^ (n - 3) )

#include <iostream>
#include <algorithm>
#include <cstring>
#define int long long
using namespace std;

constexpr int mod = 998244353;

int q_m(int a, int q, int mod)
{
	int ans = 1;
	while (q > 0)
	{
		if (q & 1)
			ans = a * ans % mod;
		q >>= 1;
		a = a * a % mod;
	}
	return ans;
}

void solve()
{
	int n;
	cin >> n;
	if (n == 1 || n == 2) cout << n << "\n";
	else cout << 6 * q_m(2, n - 3, mod) % mod << "\n";
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值