Yatin created an interesting problem for his college juniors. Can you solve it?
Given rooms, where each room has a one-way door to a room denoted by , where . Find a positive integer such that, if a person starts from room , , and continuously moves to the room it is connected to (i.e. ) , the person should end up in room after steps;
Note: The condition should hold for each room.If there are multiple possible values of modulo (), find the smallest one.If there is no valid value of K, output
Constraints:
Input Format
Output Format
Given array
If a person starts from
Path would be , so person took 4 steps to reach room 1
Path would be , so person took 4 steps to reach room 1
and so on for other rooms.
Similarly, it would give a value 4 for each case, And this is the smallest valid value, so for this case