文章

160

粉丝

0

获赞

626

访问

24.4k

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

#include<iostream>
using namespace std;

int m,n;

bool check(int n)
{
	int copy=n;
	int sum=0;
	while(copy)
	{
		int x=copy%10;
		sum+=x*x*x;
		copy/=10;
	}
	if(sum==n)
		return true;
	return false;
}

int main()
{
	while(cin>>m>>n)
	{
		int cnt=0;
		if(m==0&&n==0)
			break;
		for(int i=m;i<=n;i++)
		{
			if(check(i))
			{
				cout<<i<<" ";
				cnt++;
			}
		}
		if(cnt==0)
			cout<<"no";
		puts("");
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发