Problem 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

题意也比较容易理解:找一个数的约数之和是不是和这个数相等,

或者是大于,还是小于。

如果相等,后面接:PERFECT

如果约数和小于这个数,后面接:DEFICIENT

如果约数和大于这个数,后面接:ABUNDANT

然后。。。就写吧。水题

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String strNum = sc.nextLine();
String strsNum[] = strNum.split(" ");
int[] num = new int[strsNum.length-1]; for(int i=0;i<num.length;i++){
num[i]=Integer.parseInt(strsNum[i]);
}
System.out.println("PERFECTION OUTPUT");
for(int i=0;i<num.length;i++){
strNum = "ABUNDANT";
if(isTrue(num[i])==-1){
strNum = "DEFICIENT";
}
if(isTrue(num[i])==0){
strNum = "PERFECT";
}
System.out.printf("%5d",num[i]);
System.out.println(" "+strNum);
}
System.out.println("END OF OUTPUT"); } private static int isTrue(int i) {
int sum=0;//约数之和
for(int k=1;k<=i/2;k++){
if(i%k==0){
sum=sum+k;
}
}
if(sum<i){
return -1;
}
if(sum==i){
return 0;
}
return 1;
} }

HDOJ 1323 Perfection(简单题)的更多相关文章

  1. HDOJ 1303 Doubles(简单题)

    Problem Description As part of an arithmetic competency program, your students will be given randoml ...

  2. BZOJ 2683: 简单题

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] ...

  3. 【BZOJ-1176&2683】Mokia&简单题 CDQ分治

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  4. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

  5. Bzoj2683 简单题

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1071  Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...

  6. 这样leetcode简单题都更完了

    这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...

  7. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

  8. HDU 1753 大明A+B(字符串模拟,简单题)

    简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...

  9. 团体程序设计天梯赛-练习集L1-014. 简单题

    L1-014. 简单题 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 这次真的没骗你 —— 这道超级简单的题目没有任何输入. ...

随机推荐

  1. Git学习资料整理

    Git作为一个优秀的版本控制系统,是我们开发人员必须要学会使用的一个工具,接触git一年多以来,也看了不少相关资料,今天把我所看过的一些学习资源整理一下. Git入门当然首推廖雪峰廖老师的教程:Git ...

  2. C语言单元測试

    C语言单元測试 对于敏捷开发来说,单元測试不可缺少,对于Java开发来说,JUnit非常好,对于C++开发,也有CPPUnit可供使用,而对于传统的C语言开发,就没有非常好的工具可供使用,能够找到的有 ...

  3. VSS Get Latest Version 没有提示recursive的对话框解决

    今天按照VSS使用时,当“Get Latest version”时,不小心勾选了 “Only show this dialog when the Shift key is down”,因此当我再“Ge ...

  4. php中运用GD库实现简单验证码

    昨天学习了运用php的GD库进行验证码的实现. 首先可以用phpinfo()函数看一下GD库有没有安装,我用的wampserver是自动给安装的. 主要的步骤是: 1.生成验证码图片 2.随机生成字符 ...

  5. 数据结构笔记01:编程面试过程中常见的10大算法(java)

    以下是在编程面试中排名前10的算法相关的概念,我会通过一些简单的例子来阐述这些概念.由于完全掌握这些概念需要更多的努力,因此这份列表只是作为一个介绍.本文将从Java的角度看问题,包含下面的这些概念: ...

  6. Debian 桌面美化

    Debian 桌面美化 安装 gnome-tweak-tool aptitude install gnome-tweak-tool 登陆gnome-look下载主题包 gnome-look上有很多主题 ...

  7. 配置Windows下编译运行C/C++过程

    1.首先确定电脑安装了VS或者VC++的IDE: 2.修改环境变量 在系统属性-高级-环境变量-用户变量中: 编辑PATH增加cl编译器的路径D:\Program Files\Microsoft Vi ...

  8. SVN Git 设置忽略目录 大全

    eclipse中SVN设置 用svn控制版本,svn本身是不会识别哪些该传,哪些不该传,这就导致有些关于路径的东西(比如拓展jar的路径)也被上传了,而当别人下载后,那个路径对于这个人可能完全不存在, ...

  9. hdu 5105

    题意: y=|a*x^3+b*x^2+c*x+d|    求y的最大值? 题目是bc上的,之前写的时候,没考虑0的情况(太笨了).... 水题吧.... AC代码: #include <iost ...

  10. 问题: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable 解决方案

    在Job中添加相应的输入类型,例如: job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.clas ...