You are given a 1×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

10 5

Output

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


 Solution



import java.util.*;
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner s = new Scanner(System.in);
int n;
long k;
n=s.nextInt();
k=s.nextLong();
if(n==2)
System.out.print(k*k);
else
System.out.print(k);
}
}




if you have any problem in this code, take a screen shot and contact with Rishabh Chaubey.

Post a Comment

Previous Post Next Post