Perfection
来源:互联网 发布:转换成淘宝客链接 编辑:程序博客网 时间:2024/05/22 00:42
http://acm.hdu.edu.cn/showproblem.php?pid=1323
Perfection
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2078 Accepted Submission(s): 1245
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.
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 ABUNDANT60000 ABUNDANT 22 DEFICIENT 496 PERFECTEND OF OUTPUT
#include <cstdio>#include <iostream>#include <string>using namespace std;int prim[10000];string ans[60010];int sum[60010];void get_prim(void){ prim[0]=2; int j=1; for(int i=3,k;i<60010;i+=2){ for(k=0;k<j;k++) if(i%prim[k]==0)break; if(k==j)prim[j++]=i; } // printf("%d\n",prim[j-1]); // for(int i=0;i<50;i++)printf("%d\n",prim[i]);}int Pw(int x,int y){ int a=1; for(int i=0;i<x;i++) a*=y; return a;}void get_sum(void){ for(int i=2;i<60010;i++){ //int i=10007; int yin[100],pw[100]; int x=i,j=0,yin_i=0,pw_i=0; while(x>0){//printf("%d\n",prim[j]); if(x<=prim[j])break; if(x%prim[j]==0){ yin[yin_i++]=prim[j]; int cnt=1; while(x%Pw(cnt,prim[j])==0)cnt++; pw[pw_i++]=cnt-1; x/=Pw(cnt-1,prim[j]); } j++; } if(x==prim[j]){yin[yin_i++]=x;pw[pw_i++]=1;} int cnt=1; for(int ii=0;ii<yin_i;ii++){ int x=1,y=1; for(int jj=0;jj<pw[ii];jj++){ x*=yin[ii]; y+=x; } cnt*=y; } cnt=cnt-i; sum[i]=cnt; }}void get_ans(void){ for(int i=2;i<60010;i++) if(i>sum[i])ans[i]="DEFICIENT"; else if(i==sum[i])ans[i]="PERFECT"; else ans[i]="ABUNDANT";}int main(){ get_prim(); get_sum(); get_ans(); // printf("%d",sum[6]); int x; printf("PERFECTION OUTPUT\n"); while(scanf("%d",&x)&&x){ printf("%5d ",x); cout<<ans[x]<<endl; } printf("END OF OUTPUT\n"); return 0;}
0 0
- Perfection
- Blue Perfection
- HDU1323:Perfection
- poj_1528 Perfection
- hdu1323-Perfection
- hd1323 Perfection
- poj1528 Perfection
- HDU1323 Perfection
- Say No to Perfection
- fjnu 1319 Perfection
- 魔盒 Perfection CMS 系统
- poj 1528 Perfection
- zoj 1284 Perfection
- poj 1528 Perfection
- poj 1528 Perfection
- POJ 1528 perfection
- POJ 1528 Perfection
- UVa 382-Perfection
- mapreduce查询mysql表中记录数
- POJ 题目3237 Tree(Link Cut Tree边权变相反数,求两点最大值)
- 排序算法(Java语言)——希尔排序
- studio 2010快捷键
- 强名称程序集(strong name assembly)——为程序集赋予强名称
- Perfection
- hdu5407数学
- 02-线性结构4. Pop Sequence (25)
- 数组的练习
- 虚拟地址转译成物理地址 双机模式手动查找
- Mathematical relationships among map scale, raster data resolution, and map display resolution
- Hardwood Species POJ 2418
- C#与C++的命名空间
- Activity声明周期在不同场景的调用