Time limit: 1 second Memory limit: 256 MB We have a binary tree of fractions with…
- User
Time limit: 1 second Memory limit: 256 MB We have a binary tree of fractions with fractions of the form on each vertex a i b i b i
a i
is written The tree is built like this:
a 1 a 1
b 1 b 1
1 1 a 2 i a 2 i = ( a i a i + b i b i ), b 2 i b 2 i
b i b i (child on the left) a 2 i + 1 a 2i+1
a i a i , b 2 i + 1 b 2i+1 = ( a i a i + b i b i ) (child on the right) We define the distance between two vertices in the tree as the number of single edges in the path between them.
to you Q Q request that each include a fraction to the form p i q i q i
p i
is given
For each number in the requests, if there is only one vertex in the tree whose fraction is equal to the given input fraction, print the distance of the vertex of that fraction to vertex 1 in the output, and otherwise
1 Output −1.
input In the first line Q Q and in Q Q next line p i p i and q i q i given to you
1 ≤ Q ≤ 100
000 1≤Q≤100 000
1 ≤ p i , q i ≤ 1 0 18 1≤p i Q i ≤10 18
output on the line i If the fraction is equal to the number p i q i q i
p i
and only this fraction was equal to this number, output its distance from the vertex 1 otherwise
1 Output −1.
Example Sample input 1 2 1 2 3 5
Plain text Sample output 1 1 3
- Assistant
- User
variable input and output
- Assistant
- User
Time limit: 1 second Memory limit: 256 MB Uncle Scrooge, who misses his family members a lot, decides to attend their New Year's party (online!). Uncle Scrooge's family n
1 There are n−1 people and each of them organizes a party. Uncle Scrooge, who cannot attend two parties with the same mobile phone, needs to n
1 He has n−1 fully charged mobile phones. He went to his friend to get this number of mobile phones.
Uncle Scrooge's friend n n has a mobile phone and a mobile phone i i th a i a i It has a charge percentage. We also have a mysterious charger that can be used from a mobile phone that at least x has x percent charge, x x percentage of charge reduced and to another mobile phone y y added charge percentage. Since, according to physicists, energy is conserved, the amount x x must be of value y y is greater.
- Assistant
- User
Sample entry 2 3 3 2 10 95 98 Plain text Sample output 2 No
- Assistant