HDU5187:zhx's contest

该博客详细解析了HDU5187: zhx's contest的竞赛题目,阐述了问题的思路,即通过组合数学计算在特定条件下放置数字的方案数。博主指出,正确解法需要使用大整数运算,并提醒读者开启大整数支持以避免WA错误。

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

HDU5187:zhx's contest

题目大意

传送门
在这里插入图片描述

思路

我们考虑先单增再单减,那我们假设 n n n放在第 i i i位,那么我们就需要在前面 i − 1 i-1 i1放,就是从 n − 1 n-1 n1中选 i − 1 i-1 i1,就是 C ( n − 1 , i − 1 ) C(n-1,i-1) C(n1,i1),然后 i i i后面的数我们就不用选了,所以这个就是 ∑ i = 2 n − 1 C ( n − 1 , i − 1 ) \sum_{i=2}^{n-1}C(n-1,i-1) i=2n1C(n1,i1),化简之后,就是 2 n − 1 − 2 2^{n-1}-2 2n12,然后先单减再单增也是一样的,于是便是 2 n − 4 2^n-4 2n4,又因为还有一直单增和一直单减的,有两个,所以最后结果就是 2 n − 2 2^n-2 2n2,这道题特别变态,你要开KaTeX parse error: Expected group after '_' at position 1: _̲_int128才能过,不然你就会一直 W A WA WA,听取蛙 ( W A ) (WA) (WA)声一片

代码

#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;

#define Int register int
#define int __int128

int quick_pow (int a,int b,int c)
{
	int res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % c;
		a = a * a % c;
		b >>= 1;
	}
	return res % c;
}

void read (int &x)
{
	x = 0;char c = getchar();int f = 1;
	while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}
	while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + c - '0';c = getchar();}
	x *= f;return ;
}

void write (int x)
{
	if (x < 0){x = -x;putchar ('-');}
	if (x > 9) write (x / 10);
	putchar (x % 10 + '0');
}

signed main()
{
	unsigned long long n,mod;
	while (scanf ("%llu %llu",&n,&mod) != EOF)
	{
		int ans = quick_pow (2,n,mod) - 2;
		write ((ans % mod + mod) % mod),putchar ('\n');
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值