原题入口

poj 1528 Perfection

题目描述

Perfection
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 12561 Accepted: 5870

Description
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 1/-1, 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.”
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

Source
Mid-Atlantic 1996

解题代码

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;int main()
{cout << "PERFECTION OUTPUT" << endl;int nNum;while((cin >> nNum) && nNum){cout << setw(5) << setfill(' ') << right << nNum << "  ";// 先输出数字const int nLoopLimit = (int)sqrt((double)nNum);int nSum = 0;if (nNum == 1){cout << "DEFICIENT" << endl;continue;}for (int nDivisor = 1; nDivisor <= nLoopLimit; ++nDivisor){if (nNum % nDivisor != 0)continue;nSum += nDivisor;if (nDivisor * nDivisor != nNum && nDivisor != 1)nSum += (nNum / nDivisor);if (nSum > nNum)break;}if (nSum == nNum)cout << "PERFECT" << endl;else if (nSum < nNum)cout << "DEFICIENT" << endl;elsecout << "ABUNDANT" << endl;}cout << "END OF OUTPUT" << endl;return 0;
}

解题过程

  • 题意:题目要求找到完美数字,开头啰里啰嗦的讲了一大堆数论里面的知识,然后最后给出了完美数字的解释,总结来说就是一个数字的因子(不包括自身)相加如果等于这个数本身,那么这个数字就被称作完美数字,如果最后的和小于数字本身,那么称为“DEFICIENT”,如果和大于数字本身,称为“ABUNDANT”。

  • 思路:这个问题只需要简单遍历就好,注意范围的选取会让你的速度加快

  • 槽点:今天的问题同样槽点不断,在AC之前我贡献了一次WA,3次PE,我也是醉了:

    • 先说加快计算时间的技巧,还是减少遍历的范围,既然是求因子相加,那么遍历到sqrt(n)就可以,对于因子k的另一个因子就是n/k。
    • 说说我伤心的WA,就是因为没有考虑到n==1时的情况,这个时候属于”DEFICIENT”,还有些文章是误导的,需要注意
    • 再说说那3次PE,这是我第一次提交得到PE的结果,还在这里贡献了3次,其实第一次读这个题的时候我就有心里准备,这个提的输出格式太严了
    • 第一次我认为是最后的”END OF OUTPUT”最后不应该有回车换行,去掉回车后提交,PE。
    • 第二次我认为不应该把”PERFECTION OUTPUT”放在一开始输出,应该放在读取数据之后输出,改后提交,PE。
    • 第三次我也不知道是咋回事,PE,好伤心。
    • 最后问题出在输出的数字后面应该有两个空格,而不是一个,/(ㄒoㄒ)/~~。

提交结果

poj解题报告——poj 1528 Perfection相关推荐

  1. 解题报告 poj 3207

    1.        题目 POJ 3207 2.        题目实质 平面上,一个圆,圆的边上按顺时针放着n个点.现在要连m条边,比如a,b,那么a到b可以从圆的内部连接,也可以从圆的外部连接.问 ...

  2. 解题报告 poj 2109

    话说,那个题的中文翻译是:开一个高精度数 p 的 n 次方根 k . #include <cstdio> #include <cmath>int main() {double ...

  3. poj解题报告——2325

    题目读了好长时间,郁闷. 题意:给定一个数N,求一个数M,要求:将M的各个位的数相乘得到N,M最小.思路:用到高精度除法,将给定的数从9开始试除,接着试除8,7,6,5,4,3,2.若结果 N仍大于一 ...

  4. poj解题报告——2386

    题意:给你一个row*col的矩阵表示一块田地,上面的'W'代表积水,'.'表示干地,问这块田地里面的积水能汇聚成几片水洼. #include<iostream> #include< ...

  5. uscao 线段树成段更新操作及Lazy思想(POJ3468解题报告)

    线段树成段更新操作及Lazy思想(POJ3468解题报告) 标签: treequerybuildn2cstruct 2011-11-03 20:37 5756人阅读 评论(0) 收藏 举报  分类: ...

  6. POJ 2800 垂直直方图 解题报告

    POJ 2800 垂直直方图 解题报告 编号:2800   考查点:简单计算题 思路: 用gets()读入4行数据,然后按字符统计,显示的时候有点小处理即可. 提交情况: 感觉POJ的测试数据有点骗人 ...

  7. POJ 2745 显示器 解题报告

    POJ 2745 显示器 解题报告 编号:2745   考查点:模拟 思路:抽象出来,计算器显示是7个笔画,然后建立数组表示各笔画被覆盖情况,不过这个是我看了书之后实现的,方法果真经典. 提交情况:比 ...

  8. Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)

    http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何求 ...

  9. POJ 2054 Color a Tree解题报告

    题干 Bob is very interested in the data structure of a tree. A tree is a directed graph in which a spe ...

最新文章

  1. 如何找出R中加载的软件包版本?
  2. 组合数学(全排列)+DFS CSU 1563 Lexicography
  3. ACE_Proactor网络通信示例
  4. 一位产品总监打算这样管国家:首先得让大家交得起税。
  5. SVN提交代码后不刷新状态解决办法
  6. 如何让Latex公式字体变小
  7. javascript 高级程序设计_重读《JavaScript高级程序设计》
  8. KVM虚拟机PCI设备直通
  9. git pull没有更新成功_关于git pull时出现的问题及解决反思
  10. 博客目录 Blog directory
  11. signature=fd45b8c9a90eebce5d855f07302ab4ee,Private Use Area
  12. 程序批量将文本文件中的某字符替换
  13. 计算机教育思维,计算机教育中计算思维的培育
  14. pulseaudio-点点滴滴
  15. MATLAB程序设计与应用 2.4 MATLAB常用内部函数
  16. 阿里云服务器购买完整流程
  17. Arduino重置-复位
  18. [分享] 冒险岛079私服搭建
  19. SCAU计算机网络综合性实验
  20. 垃圾3D打印机Makerbot Replicator Z18 常见报错

热门文章

  1. Python 调试器 - ipdb
  2. 中文乱码字幕视频观看的免费网站
  3. 搜索引擎有“破绽” seo可趁虚而入
  4. 从Map中 取出第一个key/第一个value的方法
  5. 程序员阿BEN的SOHO生活
  6. 基于stm32之w5500以太网应用
  7. GEE|时间序列分析(四)
  8. Javascript 实现gb2312和utf8编码的互换
  9. 软件开发投标技术力量_开发者社区的力量
  10. 再见 Docker,是时候拥抱下一代容器工具 Containerd 了!