Files
python/TangDou/KaoShi/水仙花数.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
445 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
//是不是水仙花数
bool isSXH(int n) {
int s = 0, m;
m = n;
while (m) {
int a = m % 10;
s += a * a * a;
m /= 10;
}
return s == n;
}
/**
* 测试用例:1000
输出:
153
370
371
407
*/
int main() {
int n;
cin >> n;
for (int i = 2; i <= n; i++)
if (isSXH(i)) cout << i << endl;
return 0;
}