题目大意
思路
我们考虑先单增再单减,那我们假设 n n n放在第 i i i位,那么我们就需要在前面 i − 1 i-1 i−1放,就是从 n − 1 n-1 n−1中选 i − 1 i-1 i−1,就是 C ( n − 1 , i − 1 ) C(n-1,i-1) C(n−1,i−1),然后 i i i后面的数我们就不用选了,所以这个就是 ∑ i = 2 n − 1 C ( n − 1 , i − 1 ) \sum_{i=2}^{n-1}C(n-1,i-1) ∑i=2n−1C(n−1,i−1),化简之后,就是 2 n − 1 − 2 2^{n-1}-2 2n−1−2,然后先单减再单增也是一样的,于是便是 2 n − 4 2^n-4 2n−4,又因为还有一直单增和一直单减的,有两个,所以最后结果就是 2 n − 2 2^n-2 2n−2,这道题特别变态,你要开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');
}
}