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. 淘宝数据库OceanBase SQL编译器部分 源代码阅读--Schema模式

    淘宝数据库OceanBase SQL编译器部分 源代码阅读--Schema模式 什么是Database,什么是Schema,什么是Table,什么是列,什么是行,什么是User?我们能够能够把Data ...

  2. JavaScript数组的学习

    1数组的创建 var arr1 = new Array(); var arr2=[1,2,3]; 2数组常用的方法: push,pop,shift,unshift,splice,slice,sort, ...

  3. java JNI 的实现(1)-又进一步加深对JVM实现的理解

    目录 概述 主要优点 主要缺点 JNI实现的简单例子 开发工具 简略步骤 1,在eclipse的 'java类' 中声明一个 'native方法'; 2,使用 'javah' 命令生成包含'nativ ...

  4. C# 导出word文档及批量导出word文档(1)

         这里用到了两个dll,一个是aspose.word.dll,另外一个是ICSharpCode.SharpZipLib.dll,ICSharpCode.SharpZipLib.dll是用于批量 ...

  5. mysql UNIX时间戳与日期的相互转换

    UNIX时间戳转换为日期用函数: FROM_UNIXTIME() select FROM_UNIXTIME(1156219870); 日期转换为UNIX时间戳用函数: UNIX_TIMESTAMP() ...

  6. thinkphp3.23整合phpexcel

    HINKPHP3.2.3整合PHPexcel实现数据的导入导出.可以上传excel文件后批量导入到数据库,兼容.xls和.xlsx格式:数据库里的数据可以按照搜索条件和分页导出为excel文件.最近接 ...

  7. PHPCMS v9修改栏目或者单页没有权限

    问题: 普通管理员没有权限修改栏目,只有超级管理员才有权限修改,凡是非超级管理员,设置栏目权限后只能添加栏目,不能对栏目进行修改和删除操作,提示您没有权限操作该项这使系统的一个BUG.   一.对于普 ...

  8. REDIS学习(1)环境搭建

    1.下载 稳定版本的.tar.gz 包,解压到/usr/local/src/. 2 .cd 到文件夹下,不需要 configure 直接 make编译 ,成功之后,cd /usr/local/redi ...

  9. 【行为型】Chain of responsibility模式

    职责链模式将对象的请求处理组成链式结构,并将请求按链式结构逐个传递下去,直接被其中的某个处理者处理为止.由此可知,职责链模式的适用场合是对指定请求,可以有多个请求处理者(或称为请求响应者),但用户并不 ...

  10. 11061160顾泽鹏homework-01

    我的Github地址是buaa11061160 教材:中文版 代码大全 (第二版) 斯蒂夫·迈克康奈尔 设计思路: 输入了一串数组a[0].a[1]..... 从a[0]开始向后扫,在以数字a[i]结 ...