UVa 382 Perfection (过剩数、完美数和亏数)

本文介绍了一个高效的算法,用于判断一个正整数是否为完美数、盈数或亏数,并提供了完整的C++代码实现。该算法的时间复杂度为O(√n),适用于快速计算指定范围内整数的数论属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

382 - Perfection

Time limit: 3.000 seconds 

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=318

From the article Number Theory in the 1994 Microsoft Encarta: ``If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not tex2html_wrap_inline41 , b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant."

Problem Statement

Given a number, determine if it is perfect, abundant, or deficient.

Input

A list of N positive integers (none greater than 60,000), with 1 < N < 100. A 0 will mark the end of the list.

Output

The first line of output should read PERFECTION OUTPUT. The next N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below. Format counts: the echoed integers should be right justified within the first 5 spaces of the output line, followed by two blank spaces, followed by the description of the integer. The final line of output should read END OF OUTPUT.

Sample Input

15 28 6 56 60000 22 496 0

Sample Output

PERFECTION OUTPUT
   15  DEFICIENT
   28  PERFECT
    6  PERFECT
   56  ABUNDANT
60000  ABUNDANT
   22  DEFICIENT
  496  PERFECT
END OF OUTPUT

完整代码,O(√n)复杂度:

/*0.019s*/

#include<cstdio>
#include<cmath>

int main()
{
	int n,m,i, sum;
	puts("PERFECTION OUTPUT");
	while (scanf("%d", &n), n)
	{
		m = (int)sqrt(n), sum = 1;
		for (i = 2; i <= m ; ++i)
			if (n % i == 0) sum += i + n / i;
		if (m * m == n) sum -= m;
		printf("%5d  ", n);
		if (sum < n) puts("DEFICIENT");
		else if (sum > n) puts("ABUNDANT");
		else puts("PERFECT");
	}
	puts("END OF OUTPUT");
}

完美固定资产管理系统是一个集固定资产管理、跟踪监控于一体的综合性系统。该系统具有以下特点功能: 1. 完整的资产信息管理:系统可以对企业的固定资产进行全面的信息管理,包括资产编号、名称、规格、量、购买日期、购买费用等。同时,系统还可以将这些信息与其他关键信息(如供应商、保修期限等)关联起来,方便企业进行更全面准确的资产管理。 2. 高效的资产跟踪监控:系统通过采用条码、RFID等先进的技术手段,能够对固定资产进行精确的跟踪监控。企业可以实时了解资产的位置、状态使用情况,减少资产丢失滥用的风险。同时,系统还可以设置提醒功能,及时通知企业对到期保修或维护的资产进行处理,提高资产的利用率寿命。 3. 系统化的维护维修管理:完美固定资产管理系统会对企业的维修保养工作进行系统化管理。系统可以根据资产的维护要求、保养规程维修记录进行自动化的提醒安排。同时,系统还可以生成维修工单相关报表,提供据支持决策依据,提高企业的维修效率质量。 4. 准确的财务管理分析支持:系统能够进行准确的资产减值核算、折旧计算财务分析,帮助企业做好资产财务管理工作。系统还可以生成相关的报表图表,提供对资产投资利用情况的全面分析评估,为企业的决策提供参考。 总之,完美固定资产管理系统通过集中管理综合控制,提高了企业对固定资产的管理效率质量,帮助企业降低了成本、提高了资产价值使用寿命,为企业的可持续发展提供有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值