文章

76

粉丝

0

获赞

448

访问

18.0k

头像
水仙花数 题解:
P1034 中南大学机试题
发布于2026年1月31日 09:08
阅读数 222

#include<iostream>

using namespace std;

bool check(int x) {
	int a = x / 100;
	int b = x / 10 % 10;
	int c = x % 10;
	return x == a * a * a + b * b * b + c * c * c;
}

int main() {
	
	while (true) {
		int m, n;
		cin >> m >> n;
		if (m == 0 && n == 0) break;
		
		bool flag = false;
		for (int i = m; i <= n; i ++ ) {
			if (check(i)) {
				cout << i << ' ';
				flag = true;
			}
		}
		if (!flag) cout << "no" << endl;
		else cout << endl;
	
	}

	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发