Captivating process
Time limit4sMemory limit1024 MB
Given functions f and g on 1 to N, for each query (x, y) decide whether applying both functions in lockstep ever makes the two values equal.
- Level
Hard8 of 10
- Topics
- Graph, Number theory, Math
- Solved
- No attempts yet
Problem
Yulia wrote the number on the blackboard, and Zakhar wrote . Once every minute, they erase their numbers at the same time and write new numbers. If Yulia's number is , it becomes . If Zakhar's number is , it becomes .
They stop when their numbers match. This can happen right away if , later, or never. For each pair and , determine whether the process ever ends.
Input
The first line contains two integers and ().
The second line contains integers .
The third line contains integers .
Each of the following lines contains the starting numbers and . All values are integers from 1 to .
Output
For each query , print YES if the process starting from and ends, and NO otherwise.