Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=4704
Test instructions
Given a number n to decompose it, Si represents the number of schemes to split n into the number of I
Seek sum (SI) 1<=i<=n;
Analysis:
Partition principle, n a stick, n-1 a seam,
Divided into 1 parts is C (n-1,0);
Divided into 2 parts is C (n-1,1);
Divided into 3 parts is C (n-1,2);
...
Divided into n parts is C (n-1,n-1);
ans = SUM (C (n-1,i)) (0<=i<=n-1)
=2^ (n-1);
Due to modulo and 2 and mod coprime, you can use Fermat theorem to power down
The code is as follows:
#include <iostream> #include <cstring> #include <cstdio>using namespace std;typedef long Long ll;const int mod = 1e9+7;const int maxn = 1e5+10;char A[MAXN]; ll Quick_mod (ll a,ll b,ll m) { ll ans = 1; while (b) { if (b&1) { ans = ans * a% m; b--; } b>>=1; A = A * a% m; } return ans;} ll Change (char *s, ll m) { ll ans = 0; int len = strlen (s); for (int i = 0; i < len; i++) { ans = (ans * + a[i]-' 0 ')%m; } return ans;} int main () { while (~scanf ("%s", a)) { int m = mod-1; LL n = Change (a,m); printf ("%i64d\n", Quick_mod (2, (n-1+m)%m,mod)); } return 0;}
HDU 4704 Sum (partition principle + Fermat theorem)