E题题解#

解题思路:

从\sqrt{n}开始枚举,每一次枚举都要乘以十倍。

代码如下:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {

ll y, k, t, x; bool b = 1;

cin >> t;
while (t--) {
    cin >> x;
    k = x;
    b = 1;
    for (int i = 0; i <= 9; i++) {
        y = ceil(sqrt(k));
        ll m = pow(y, 2) / pow(10, i);//转化成ll类型
        if (m == x) {//两者相等满足条件
            b = 0;//已找到y记录下来
            break;
        }
        k *= 10;
    }
    if (!b) cout << y;
    else cout << "-1";
    cout << "\n";
}
cin >> x;
return 0;
}