找找规律,实际上是二分查找的过程,只要找到了mid与输入的n相同的话,直接输出left和right就可以了。
代码如下:
#include <iostream>
using namespace std; long long getroot(int n)
{
long long root = ;
while(root* <= n)
root *= ;
return root;
} int main()
{
int T;
cin>>T;
while(T --)
{
long long n,root;
cin>>n;
root = getroot(n);
long long left = , right = *root - ;
long long mid = (left + right)/;
while(mid != n)
{
if(mid > n) right = mid - ;
if(mid < n) left = mid + ;
mid = (right + left)/;
} cout<<left<<" "<<right<<endl; }
return ;
}