题解 | 变种水仙花
变种水仙花
https://www.nowcoder.com/practice/c178e3f5cc4641dfbc8b020ae79e2b71
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool F(int a){
string s=to_string(a);
int t = s.length()-1;
int n=0;
while (t) {
n+=stoi(s.substr(0,t))*stoi(s.substr(t));
t--;
}
if (n==a) {
return true;
}else {
return false;
}
}
int main() {
vector<int> vec;
for (int i=10000; i<=99999; i++) {
if (F(i)) {
vec.push_back(i);
}
}
for(auto u:vec)
cout<<u<<" ";
return 0;
}
// 64 位输出请用 printf("%lld")
