思路:枚举pow(10,k),然后y = sqrt(x * pow(10,k)),取l = sqrt(y),r = sqrt(y) + 1即可,注意ll问题以及y的范围是
1~1e9
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> PII;
int b[15];
void solve(){
int x;
cin >> x;
for(int i = 0; i < 15; i ++){
int p = x * b[i];
int l = sqrt(p);
int r = l + 1;
for(int j = l; j <= r; j ++){
if(j * j / b[i] == x && j <= INF){
cout << j << '\n';
return;
}
}
}
cout << -1 << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin >> t;
b[0] = 1;
for(int i = 1; i < 15; i ++) b[i] = b[i - 1] * 10;
while(t --){
solve();
}
return 0;
}