poj 1528 Perfection

简介:

这道题很水,主要就是注意一下当 n==1 时候的情况就可以了。。。

AC的代码:

#include<iostream>
#include <math.h>

int main()
{
	printf("PERFECTION OUTPUT\n");

	int n,i;
	while(scanf("%d",&n) && n!=0)
	{
		printf("%5d  ",n);

		if(n==1)
		{
			printf("DEFICIENT\n");
			continue;
		}

		int sum=1,limit=(int)sqrt((double)n);
		for(i=2;i<=limit;i++)
		{
			if(n%i==0)
				sum+=i+n/i;
		}

		if(sum==n)
			printf("PERFECT\n");

		else if(sum>n)
			printf("ABUNDANT\n");

		else
			printf("DEFICIENT\n");
	}
	printf("END OF OUTPUT\n");

	return 0;
}


相关文章
|
算法框架/工具
POJ 2262 Goldbach's Conjecture
POJ 2262 Goldbach's Conjecture
151 0
poj 3723 Conscription
点击打开链接poj 3723 思路:kruskal + 最小生成树 分析: 1 首先我们应该区分开男孩和女孩,只要将男孩的编号加上女孩的个数n,这样就可以做到男孩和女孩的编号是不同的。
863 0
|
机器学习/深度学习 消息中间件
POJ 2244
/* 大致题意:n个城市,先把1号断电,继而每隔m断电使标号为2的最后被限电; 转化为(n-1)个城市,最后断电的为标号为1的城市,求最小的m */ #include bool is_joseph(int m,int n) { int i,j; int s=0;...
633 0
|
测试技术
poj-1218 THE DRUNK JAILER 喝醉的狱卒
自己去看看原题; 题目大意: 就是一个狱卒喝醉了,他第一趟吧所有的监狱都带开,第二趟把能把二整除的监狱关闭,第三趟操作能把三整除的监狱; 求最后能逃跑的罪犯数 输入第一个数是代表 测试数据组数 每个数据代表狱卒来回的次数 当作开关问题即可 #include using names...
1029 0
|
10月前
|
算法
Highways(POJ—2485)
Highways(POJ—2485)
|
算法
poj 2485 Highways
点击打开链接poj 2485 思路:最小生成树+prime+最大边 分析:只要按照prime的算法的思路求出最大的边即可 代码: #include #include #include #include using namesp...
797 0
poj 3664
http://poj.org/problem?id=3664 进行两轮选举,第一轮选前n进入第二轮,第二轮选最高   #include #include using namespace std; struct vote { int a,b; int c; ...
748 0
|
存储
大数加法-poj-1503
poj-1503-Integer Inquiry Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking vari
1128 0