Company: Philips
Difficulty: medium
Pass the Ball Back to the Starter A group of N players, numbered 1 through N , are playing a passing game. At the beginning of the game the ball is held by player P . On every move the player currently holding the ball must pass it to another player, subject to one condition: A player K1 can pass the ball to a player K2 only if K1 divides K2 or K2 divides K1 . At most X moves are allowed. A game is considered complete if, after at least one move and at most X moves, the ball ends up with the player who started it. Two games are different if their sequences of passes differ. Report the number of distinct ways to complete the game, taken modulo 1000000007 . (inferred — the source states no modulus, but the count grows exponentially with X and overflows every fixed-width integer type well inside the stated limits, so a modulus is required for the answer to be representable.) Input Format The input consists of three lines: Line 1: an integer N , the number of players. Line 2: an integer P