You're decorating a room with balloons for your friend's birthday party. There are balloons of K different colors, and you have access to infinite amount of balloons of any color. You want to arrange N balloons in a row, with the only condition that no two adjacent balloons can be of the same color, because your friend will dislike it.
How many ways are there to arrange the balloons?
Since the answer can be very large, print it modulo 10^9+7.
m = 10**9 + 7
k = int(input("Enter a number of different colors (K): "))
n = int(input("Enter a number of balloons (N): "))
c = k
for i in range(1,n):
c = (c * (k-1)) % m
print(f"The number of ways to arrange {n} ballons of {k} colors is {c} (in modulo 10^9+7)")
Comments
Leave a comment