Solutions of Equation composition count -----------

Allison ran into a problem, to help you solve. For indeterminate equation a1 + a2 + ⋯ + ak-1 + ak = g (x) a1 + a2 + ⋯ + ak-1 + ak = g (x)

Which k≥1k≥1

And k∈N * k∈N *

,xx

Is a positive integer, g (x) = xxmod1000g (x) = xxmod1000

(Ie xxxx

Divided by 10001000

The remainder), x, kx, k

Is the given number. All we ask is that the number of positive integer solutions group indeterminate equation. For example, when k = 3, x = 2k = 3, x = 2

When the solution of the equation are: ⎧⎩⎨a1 = 1a2 = 1a3 = 2 ⎧⎩⎨a1 = 1a2 = 2a3 = 1 ⎧⎩⎨a1 = 2a2 = 1a3 = 1 {a1 = 1a2 = 1a3 = 2 {a1 = 1a2 = 2a3 = 1 {a1 = 2a2 = 1a3 = 1

Input format and only one row, two positive integers separated by a space, followed by k, xk, x

. Output format and only one line, the number of positive integer solutions of the equation group. Data range 1≤k≤1001≤k≤100

,
1≤x<2311≤x<231

,
k≤g(x)k≤g(x)

Sample input: 32
sample output: 3

· Thinking: Board Act *

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 150;
int k, x;
int f[1000][100][N];
int qmi(int a, int b, int p)
{
    int res = 1;
    while (b)
    {
        if (b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
void add(int c[], int a[], int b[]){
 for (int i = 0, t = 0; i < N; i ++){
  t += a[i] + b[i];
  c[i] = t % 10;
  t /= 10;
 }
}
int main(){
 cin >> k >> x;
 int n = qmi(x % 1000, x, 1000);
  for (int i = 0; i < n; i ++)
   for (int j = 0; j <= i && j < k; j ++)
   if (!j)    f[i][j][0] = 1;
   else       add(f[i][j], f[i - 1][j], f[i - 1][j - 1]);
    int *g = f[n - 1][k - 1];
 int i = N - 1;
 while(!g[i])    i --;
 while(i >= 0)   cout << g[i --];
  return 0;
}
Published 106 original articles · won praise 67 · views 5405

Guess you like

Origin blog.csdn.net/qq_45772483/article/details/105078614