There is a cave of N cells where each cell has a trap or is safe to land. From a cell i, you can jump to cells i+1 or i+2. Also, if number i is special, then you can also jump from cell i to cell i+A where A=numberofprimesin[1,i]. A number i can be special if Ai≥r1r2.
You are given the following:
Note: Here, '#' represents an empty cell and '*' means a trapped cell.
Your task is to determine the minimum number of steps that you have to walk to reach the Nth cell. Initially, you are at cell 1.
Input format
Output format
For each test case, print the minimum number of steps that you have to walk to reach the Nth cell. Print the output in a separate line.
If it is not possible to reach the Nth cell, then print "Noway!" without quotes.
Constraints
1≤T≤500
1≤r1,r2≤10000
1≤N≤100000
Note: For large input files, use faster input methods.
Note: 1-based indexing used below
1st Test Case:
In 3 jumps you can reach Nth cell. You can jump to index=3, then to index=5, then you could use
the special property and jump to index=8.
2nd Test Case:
There is No Way! to reach the Nth cell.
3rd Test Case:
In 5 jumps you can reach Nth cell. You can jump to index=3, then to index=5, then to index=7, then to index=9, and then finally to index=11,