Coloring grids
Practice
2.6 (79 votes)
Mathematics
Basic math
Very Easy
Mathematics
Problem
91% Success 19269 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a \(1 \times n\) grid and \(k\) colors. Your task is to determine the number of ways to color each cell by adhering to the following condition:

For any vertical line that divides the grid into two non-empty parts, the number of distinct colors on the right side must be equal to the number of distinct colors on the left side. Note that you can only divide the grid so that every cell either completely belongs to the left or right.

Input format

The first line of the input contains two integers \(n\) and \(k\) .

Output format

Print the number of ways to color each cell by following the mentioned condition.

Constraints

\(n,k \le 10^9\)

Sample input #2

189232688 48695377

Sample output #2

48695377

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
1 votes
Tags:
Very-Easy
Points:10
1 votes
Tags:
Very-Easy
Points:10
15 votes
Tags:
Basic MathAlgorithmsMathamaticsMath