#P9888. Shortest path
Shortest path
Shortest path
Problem Description
Forever-chicken has recently been studying a lot of single-source shortest path algorithms, such as Dijkstra's algorithm, Bellman-Ford algorithm, and so on. To test the accuracy and efficiency of these algorithms, he generated his own directed graph with vertices(numbered from to ) using the following method:
- For each vertex , there is a directed edge from to .
- For each vertex , there is a directed edge from to .
- For each vertex , there is a directed edge from to . Now he wants to know the length of the shortest path from vertex to vertex . Can you help him with this?
Input
Each test contains multiple test cases. The first line of input contains a single integer -- the number of test cases. Each test case consists of an integer , representing the number of vertices of the graph.
Output
For each test case, output a positive integer representing the distance from vertex to vertex .
Sample Input
4
7
114514
1919810
2147483648
Sample Output
3
19
20
31
Source
2023“钉耙编程”中国大学生算法设计超级联赛(9)