1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <string>
#include <vector>
typedef std::vector<unsigned int> int_v;
void fpR(unsigned int s, unsigned int p, int_v& r){
if (p == 0){
return;
}
std::string b = std::to_string(s*s);
for (unsigned int i = 0; i < b.size(); i++){
if (b[i] == '0'){
b.erase(i, 1);
}
}
if (b.size() == 8){
b.erase(0, 2);
b.erase(b.begin()+4, b.end());
r.push_back(std::stoi(b, nullptr, 10));
}
else if (b.size() == 7){
b.erase(0, 2);
b.erase(b.begin()+4, b.end());
r.push_back(std::stoi(b, nullptr, 10));
}
else if (b.size() == 6){
b.erase(0, 2);
r.push_back(std::stoi(b, nullptr, 10));
}
else if (b.size() == 5){
b.erase(0, 1);
r.push_back(std::stoi(b, nullptr, 10));
}
else if (b.size() == 4){
r.push_back(std::stoi(b, nullptr, 10));
}
else {
fpR(s+101, p, r);
}
fpR(std::stoi(b, nullptr, 10), p--, r);
}
|