题目描述
佳佳碰到了一个难题,请你来帮忙解决。
对于不定方程a1+a2+…+ak-1+ak=g(x),其中k≥2且k∈N,x是正整数,g(x)=x^x mod 1000(即x^x除以1000的余数),x,k是给定的数。我们要求的是这个不定方程的正整数解组数。
举例来说,当k=3,x=2时,分别为(a1,a2,a3)=(2,1,1)'(1,2,1),(1,1,2)。
输入输出格式
输入格式:输入文件equation.in有且只有一行,为用空格隔开的两个正整数,依次为k,x。
输出格式:输出文件equation.out有且只有一行,为方程的正整数解组数。
输入输出样例
说明
对于40%的数据,ans≤10^16;对于100%的数据,k≤100,x≤2^31-1,k≤g(x)。
_NOI导刊2010提高(01)
隔板法:
C(x-1,k-1) ;
然后高精度就行了;
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #include<cstring> #include<string> #include<cmath> #include<map> #include<set> #include<vector> #include<queue> #include<bitset> #include<ctime> #include<deque> #include<stack> #include<functional> #include<sstream> //#include<cctype> //#pragma GCC optimize(2) using namespace std; #define maxn 900005 #define inf 0x7fffffff //#define INF 1e18 #define rdint(x) scanf("%d",&x) #define rdllt(x) scanf("%lld",&x) #define rdult(x) scanf("%lu",&x) #define rdlf(x) scanf("%lf",&x) #define rdstr(x) scanf("%s",x) typedef long long ll; typedef unsigned long long ull; typedef unsigned int U; #define ms(x) memset((x),0,sizeof(x)) const long long int mod = 1e9 + 7; #define Mod 1000000000 #define sq(x) (x)*(x) #define eps 1e-3 typedef pair<int, int> pii; #define pi acos(-1.0) //const int N = 1005; #define REP(i,n) for(int i=0;i<(n);i++) typedef pair<int, int> pii; inline ll rd() { ll x = 0; char c = getchar(); bool f = false; while (!isdigit(c)) { if (c == '-') f = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f ? -x : x; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); } int sqr(int x) { return x * x; } /*ll ans; ll exgcd(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1; y = 0; return a; } ans = exgcd(b, a%b, x, y); ll t = x; x = y; y = t - a / b * y; return ans; } */ const int W = 10000000; int x, k; struct bigint { int a[25], len; bigint() { ms(a); len = 0; } bigint operator +(const bigint &rhs)const { bigint c; int x = 0; c.len = max(len, rhs.len); for (int i = 1; i <= c.len; i++) { c.a[i] = a[i] + rhs.a[i] + x; x = c.a[i] / W; c.a[i] %= W; } for (; x; x /= W)c.a[++c.len] = x % W; return c; } void print() { cout << a[len]; for (int i = len - 1; i >= 1; i--) { for (int j = 10; a[i] * j < W; j *= 10) putchar(48); cout << a[i]; } } }c[1003][1003]; int qpow(int x, int y) { int res = 1; while (y) { if (y % 2)res = 1ll * res*x % 1000; x = x * x % 1000; y >>= 1; } return res; } int main() { //ios::sync_with_stdio(0); rdint(k); rdint(x); x %= 1000; x = qpow(x, x); for (int i = 0; i < x; i++) { for (int j = 0; j <= i; j++) { if (!j || j == i)c[i][j].a[c[i][j].len = 1] = 1; else c[i][j] = c[i - 1][j] + c[i - 1][j - 1]; } } c[x - 1][k - 1].print(); return 0; }