P4451 [国家集训队]整数的lqp拆分

拆分整数$n$,$a_1+a_2..a_m=n$。求$\sum \prod F_{a_i}$

考虑$dp[i]$为$n$拆分的值。

$G=F*G+1,F=\frac{x}{1-x-x^2}$

二次剩余搞下即可。

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int e2 = 59713600;

int qpow(int a, int x)
{
int res = 1;
while (x)
{
if (x & 1)
res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
x >>= 1;
}
return res;
}
int main()
{
int x = 0;
char c = getchar();
while (c < '0' || c > '9')
{

c = getchar();
}
while (c >= '0' && c <= '9')
x = (1ll * x * 10 % (mod - 1) + c - '0') % (mod - 1), c = getchar();
cout << 1ll * (qpow(e2 + 1, x) - qpow(mod - e2 + 1, x) + mod) % mod * qpow(4, mod - 2) % mod * e2 % mod << endl;
}