Powers Everywhere!
Practice
3.8 (483 votes)
Binary search algorithm
Implementation
Data structures
Easy
Ready
Mathematics
Problem
4% Success 4231 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Today Omar is studying a math lecture, then he decides to solve its exercises. After finishing the study, Omar now thinks in the following question. There are many special numbers that could be in the formula \(b ^ e\) where b indicates the base number, e indicates the power number. But there are also many numbers that couldn't be formed in this formula so the question is to find the minimum absolute difference between a given number N and the nearest special number.

Note: for a special number, \(b,e\) integers \(> 1\).

Can you help Omar in this exercise ?

Input:

Given an integer T, number of test cases.
For each test case:
In the first line: given an integer Q, the number of queries.
Then next Q lines follow, each line has an integer N.

Output:

For each test case: answer the Q queries, every result in a separate line.

Constraints:

\(1 \le T \le 25\).
\(1 \le Q \le 10 ^ 5\).
\(1 \le N \le 10 ^ 9\).

Note: In large Input files: use faster input, output methods.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
OpenOpenOpenMath BasicBasic MathEasyMathematicsMath
Points:20
46 votes
Tags:
Brute-force searchOpenEasyMathamatics
Points:20
Editorial

No editorial available for this problem.