【1564】判断一个数是否是完全数

描述:

如果一个大于2的整数的不包含它自身的约数之和恰好等于它本身,则称其为完全数。如:6123,所以,6是个完全数。
Perfect number is defined as follows:the sum of it’s common divisor which does not includes it’s maximum equals itself.

输入:

输入一个大于2的整数n

输出:

编程判断n是不是完全数,如果是输出“Yes”,否则输出“No”

输入样例:

28

输出样例:

Yes


#include<iostream>
using namespace std;
int main()
{
	int n,i,a=0;
	cin>>n;
	for(i=1;i<n;i++)
	{
		if (n%i==0)
		a=a+i;
	}
	if (a==n)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return (0);
 } 


猜你喜欢

转载自blog.csdn.net/qq_40560275/article/details/78322164
今日推荐