ZOJ 1284 Perfection
2017-06-13 09:11
295 查看
查看原题
如果大于它本身,则abundant
否则deficient
注意输入输出,要求对齐
题意
如果一个数的所有真约数等于它本身,即完全数如果大于它本身,则abundant
否则deficient
注意输入输出,要求对齐
思路
代码
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int temp[1000]; int isPerfect(int n){ int sum=0; for(int i=1;i<=n/2;i++){ if(n%i==0){ sum+=i; } } if(sum==n){ return 1; } else if(sum>n){ return 2; } else{ return 0; } } int main(int argc, char *argv[]) { int step=0; while(cin>>temp[++step]){ if(temp[step]==0){ break; } } cout<<"PERFECTION OUTPUT"<<endl; for(int i=1;i<=step;i++){ if(temp[i]==0){ cout<<"END OF OUTPUT"<<endl; break; } printf("%5d ",temp[i]);//注意这里 if(isPerfect(temp[i])==1){ cout<<"PERFECT"<<endl; } else if(isPerfect(temp[i])==2){ cout<<"ABUNDANT"<<endl; }else{ cout<<"DEFICIENT"<<endl; } } return 0; }
相关文章推荐
- UVALive5429 UVA382 POJ1528 HDU1323 ZOJ1284 Perfection【整除+水题】
- nyist 月老的烦恼(一)||zoj 1284 Perfection
- zoj 1284 Perfection
- zoj 1284 || poj 1528 Perfection
- ZOJ 1284 数论
- ZOJ 1284
- ZOJ-1284
- zoj 1284||poj 1528||hdu 1323(筛选法求因子和)
- [水]ZOJ1284 POJ1528
- zoj 1284
- zoj 2081 Mission Impossible——最近令我满纠结的一题--。
- zoj-1005倒水问题
- zoj 3805 Machine
- zoj 1457 Prime Ring Problem
- ZOJ 1372 / POJ 1287 Networking ( kruskal+prim )
- ZOJ-1008-Gnome Tetravex
- ZOJ 3666 Alice and Bob (SG博弈)
- ZOJ-2850-Beautiful Meadow【暴力】【4th浙江省赛】
- 单源最短路径 ZOJ 1091 Knight Moves
- ZOJ 2207 Team Rankings