#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
string ending;
vector<int> ans;
void print() {
bool firstnotzero = false;
for(int i = ans.size() - 1; i >= 0; i--) {
if(ans[i]) {
firstnotzero = true;
}
if(firstnotzero) {
cout << ans[i];
}
else if(i == 0) {
cout << 0;
}
}
cout << endl;
}
void find() {
int len = ending.length();
int ansBits = 0;
ans.resize(len);
int carry = 0;
while(len - 1 - ansBits >= 0) {
for(ans[ansBits] = 0; ans[ansBits] <= 9; ans[ansBits]++) {
int resultBit = carry;
for(int i = 0; i <= ansBits; i++) {
for(int j = 0; j <= ansBits - i; j++) {
int k = ansBits - i - j;
resultBit += ans[i] * ans[j] * ans[k];
}
}
if(resultBit % 10 == ending[len - 1 - ansBits] - '0') {
carry = resultBit / 10;
break;
}
}
ansBits++;
}
}
int main() {
int cases;
cin >> cases;
while(cases--) {
cin >> ending;
ans.clear();
find();
print();
}
return 0;
}
1203. The Cubic End
最新推荐文章于 2024-09-18 18:23:55 发布