AtCoder Beginner Contest 046 - Painting Balls with AtCoDeer

There are N balls placed in a row.
AtCoDeer the deer is painting each of these in one of the K colors of his paint cans.
For aesthetic reasons, any two adjacent balls must be painted in different colors.
Find the number of the possible ways to paint the balls.

-----Constraints-----
 - 1≦N≦1000
 - 2≦K≦1000
 - The correct answer is at most 2^{31}-1.

-----Input-----
The input is given from Standard Input in the following format:
N K

-----Output-----
Print the number of the possible ways to paint the balls.

-----Sample Input-----
2 2

-----Sample Output-----
2

We will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.

Difficulty: EASY

Starter code:

Solutions:
(N, K) = map(int, input().split())
print(K * (K - 1) ** (N - 1))


(n, k) = map(int, input().split())
m = 1
if n == 1:
	print(k)
else:
	m *= k
	for i in range(n - 1):
		m *= k - 1
	print(m)


(n, k) = [int(x) for x in input().split()]
res = k
for i in range(1, n):
	res *= k - 1
print(res)


(n, k) = map(int, input().split())
print(k * (k - 1) ** (n - 1))


(n, k) = map(int, input().split())
ans = k
for i in range(n - 1):
	ans *= k - 1
print(ans)


(N, K) = list(map(int, input().split()))
print(K * pow(K - 1, N - 1))


(n, k) = map(int, input().split())
ans = k * pow(k - 1, n - 1)
print(ans)


import math
(N, K) = map(int, input().split())
print(K * (K - 1) ** (N - 1))


(N, K) = map(int, input().split())
print(K * (K - 1) ** (N - 1) if N > 2 else K)


(N, K) = input().split()
n = int(N)
k = int(K)
print(k * (k - 1) ** (n - 1))


(N, K) = input().split()
N = int(N)
K = int(K)
y = int(K * (K - 1) ** (N - 1))
print(y)


(N, K) = map(int, input().split())
R = 0
R = K * (K - 1) ** (N - 1)
print(R)


(a, b) = map(int, input().split())
print((b - 1) ** (a - 1) * b)


(n, k) = list(map(int, input().split()))
p = k
for i in range(n - 1):
	p *= k - 1
print(p)


def answer(n: int, k: int) -> int:
	return k * (k - 1) ** (n - 1)

def main():
	(n, k) = map(int, input().split())
	print(answer(n, k))

def __starting_point():
	main()
__starting_point()


(N, K) = list(map(int, input().split()))
P = K * (K - 1) ** (N - 1)
print(P)


(n, c) = map(int, input().split())
print(c * (c - 1) ** (n - 1))


(N, K) = (int(i) for i in input().split())
print(K * (K - 1) ** (N - 1))


(n, k) = map(int, input().split())
print((k - 1) ** (n - 1) * k if n != 1 else k)


(N, K) = [int(x) for x in input().split()]
print(K * (K - 1) ** (N - 1))


(n, m) = list(map(int, input().split()))
print(m * pow(m - 1, n - 1))


nk = input().split()
n = int(nk[0])
k = int(nk[1])
p = k * (k - 1) ** (n - 1)
print(p)


(N, K) = map(int, input().split())
cnt = K
for i in range(N - 1):
	cnt *= K - 1
print(cnt)


(n, k) = list(map(int, input().split()))
print(k * pow(k - 1, n - 1))


(x, y) = map(int, input().split())
print(y * (y - 1) ** (x - 1))


import re
import copy

def accept_input():
	(N, K) = list(map(int, input().split()))
	return (N, K)
(N, K) = accept_input()
if K == 1:
	print(N)
else:
	print(K * (K - 1) ** (N - 1))


(n, k) = [int(n) for n in input().split()]
print(k * (k - 1) ** (n - 1))


a = list(map(int, input().split()))
print((a[1] - 1) ** (a[0] - 1) * a[1])


(a, b) = [int(i) for i in input().split()]
print(b * (b - 1) ** (a - 1))


(n, k) = list(map(int, input().split()))
ans = k * (k - 1) ** (n - 1)
print(ans)


(n, k) = map(int, input().split())
print(k * (k - 1) ** max(0, n - 1))


import math
(n, k) = map(int, input().split())
c = k * pow(k - 1, n - 1)
print(c)


import sys
input = sys.stdin.readline

def main():
	(N, K) = [int(x) for x in input().split()]
	print(K * (K - 1) ** (N - 1))

def __starting_point():
	main()
__starting_point()


(a, b) = map(int, input().split())
c = a - 1
d = b - 1
e = d ** c
f = e * b
print(f)


lst = input().split()
N = int(lst[0])
K = int(lst[1])
print(K * (K - 1) ** (N - 1))


(N, K) = map(int, input().split())

def calculate(n, k):
	print(k * pow(k - 1, n - 1))
calculate(N, K)


(n, k) = map(lambda x: int(x), input().split())
print(k * (k - 1) ** (n - 1))


(k, m) = list(map(int, input().split()))
print(m * pow(m - 1, k - 1))


(N, M) = map(int, input().split())
print(M * (M - 1) ** (N - 1))


(N, K) = map(int, input().split())
num = K
if N != 1:
	for i in range(1, N):
		num *= K - 1
print(num)


N = input().split()
print(int(N[1]) * (int(N[1]) - 1) ** (int(N[0]) - 1))


(n, k) = map(int, input().split())
if n == 1:
	print(k)
	return
su = k
for i in range(n - 1):
	su *= k - 1
print(su)


(N, k) = map(int, input().split())
print(k * pow(k - 1, N - 1))


(N, K) = list(map(int, input().split()))
ans = K
for i in range(N - 1):
	ans *= K - 1
print(ans)


a = list(map(int, input().split()))
sum = 0
for i in range(a[0]):
	if i == 0:
		sum = a[1]
	else:
		sum *= a[1] - 1
print(sum)


(n, m) = map(int, input().split())
ans = m * (m - 1) ** (n - 1)
print(ans)


(a, b) = map(int, input().split())
s = b
t = (b - 1) ** (a - 1)
s *= t
print(s)


def resolve():
	(n, k) = list(map(int, input().split()))
	print(k * (k - 1) ** (n - 1))

def __starting_point():
	resolve()
__starting_point()


(n, k) = tuple([int(x) for x in input().split(' ')])
print(k * pow(k - 1, n - 1))


MOD = 10 ** 11

def fast_pow(x, n, MOD):
	res = 1
	while n:
		if n & 1:
			res = res * x % MOD
		x = x * x % MOD
		n >>= 1
	return res
(n, k) = map(int, input().split())
if n == 1:
	print(k)
else:
	print(k * fast_pow(k - 1, n - 1, MOD))


(iN, iK) = [int(_) for _ in input().split()]
print(iK * (iK - 1) ** (iN - 1))


(d, n) = map(int, input().split())
ans = n * (n - 1) ** (d - 1)
print(ans)


(n, k) = map(int, input().split())
print(k * pow(k - 1, n - 1), end='')


(N, K) = [int(_) for _ in input().split()]
print(K * (K - 1) ** (N - 1))


(N, K) = map(int, input().split())
pr = K
for _ in range(1, N):
	pr *= K - 1
print(pr)


NK = input().split(' ')
N = int(NK[0])
K = int(NK[1])
print(K * (K - 1) ** (N - 1))


L = list(map(int, input().split()))
print(L[1] * (L[1] - 1) ** (L[0] - 1))


def si():
	return input()

def ii():
	return int(input())

def fi():
	return float(input())

def lint():
	return list(map(int, input().split()))

def lint_dec():
	return list([int(x) - 1 for x in input().split()])

def lnstr(n):
	return [input() for _ in range(n)]

def lnint(n):
	return [int(input()) for _ in range(n)]

def graph_input(G, m):
	for _ in range(m):
		(a, b) = lint_dec()
		G[a].append(b)
		G[b].append(a)
(N, K) = lint()
print(K * pow(K - 1, N - 1))


import math
(n, k) = map(int, input().split())
print(k * (k - 1) ** (n - 1))


import itertools
(N, K) = map(int, input().split())
print(K * (K - 1) ** (N - 1))


(N, K) = list(map(int, input().split()))
ans = 1
ans = K * (K - 1) ** (N - 1)
print(ans)


(a, b) = map(int, input().split())
print(b * (b - 1) ** (a - 1) if a > 1 else b)


(a, b) = map(int, input().split())
ans = b * pow(b - 1, a - 1)
print(ans)


(N, K) = input().split()
N = int(N)
K = int(K)
print(K * pow(K - 1, N - 1))


(n, k) = list(map(int, input().split()))
if n != 1 and n != 1:
	print(k * (k - 1) ** (n - 1))
if n == 1:
	print(k)


(N, K) = map(int, input().split())
p = pow(K - 1, N - 1) * K
print(p)


l = list(map(int, input().split()))
(n, k) = l
print(k * (k - 1) ** (n - 1))


str_line = input().split(' ')
num = int(str_line[0])
kind = int(str_line[1])
ans = kind
for i in range(num - 1):
	ans *= kind - 1
print(ans)


(N, K) = map(int, input().split())
res = 1
for i in range(N):
	if i == 0:
		res *= K
	else:
		res *= K - 1
print(res)


(n, k) = list(map(int, input('').split()))
out = k * (k - 1) ** (n - 1)
print(out)


(N, K) = (int(T) for T in input().split())
print(K * (K - 1) ** (N - 1))


d = [int(i) for i in input().split()]
print(d[1] * (d[1] - 1) ** (d[0] - 1))


s = input().split()
N = int(s[0])
K = int(s[1])
print((K - 1) ** (N - 1) * K)


x = list(map(int, input().split()))
print(x[1] * (x[1] - 1) ** (x[0] - 1))