Balls and boxes#9890

Balls and boxes (Editorial)

Let's consider the first ball. It can be placed in one of the available boxes. Thus, there are options for placing the first ball. Similarly, each subsequent ball can also be placed in one of the boxes (there are options for each ball).

Therefore, the total number of ways to distribute all the balls into the boxes is the product k \cdot k \cdot ... \cdot k = k^n.

Example

Let's say we have two balls numbered and , as well as two boxes numbered and . In this case, the balls can be distributed into the boxes in the following four ways:

Algorithm implementation

Read the input data.

scanf("%lld %lld", &n, &k);

Compute res = k^n.

res = 1;
for (i = 1; i <= n; i++)
  res = res * k;

Print the answer.

printf("%lld\n", res);