Answer to Question #325913 in Python for Anil

Question #325913

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.


1
Expert's answer
2022-04-10T12:36:26-0400
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)")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS