#P5676. Repeatable Game Plays
Repeatable Game Plays
Repeatable Game Plays
Little z is bored and wants to play games. He has (N) new games, where the (i)-th game has an apparent fun level (w_i). However, Little z is very choosy: he will only play a game if its fun level is an integer multiple of his current excitement level. After playing game (i), his excitement level becomes (e_i). Initially, his excitement level is (1).
A game is said to be repeatable if it is possible to play it twice. In other words, there must exist a sequence of game plays satisfying the following conditions:
- Starting with an excitement level of (1), Little z plays game (i) (which is always allowed since (1) divides every (w_i)). After playing, his excitement level becomes (e_i).
- There exists a sequence of plays (possibly involving other games) beginning from (e_i) that brings his excitement level to some (d) such that (d) divides (w_i) (i.e. (w_i \bmod d = 0)), allowing him to play game (i) a second time.
Your task is to count the number of games that can possibly be played twice.
inputFormat
The first line contains an integer (N) (the number of games). Each of the following (N) lines contains two integers (w_i) and (e_i) representing the apparent fun level and the post-play excitement level of the (i)-th game, respectively.
outputFormat
Output a single integer representing the number of games that can possibly be played twice.
sample
3
2 2
2 3
4 4
2