ZOJ 1284 Perfection
来源:互联网 发布:数据分类汇总步骤文字 编辑:程序博客网 时间:2024/05/20 06:52
查看原题
题意
如果一个数的所有真约数等于它本身,即完全数
如果大于它本身,则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;}
阅读全文
0 0
- zoj 1284 Perfection
- ZOJ 1284 Perfection
- zoj 1284 || poj 1528 Perfection
- ZOJ 1284 Perfection (因子和)
- nyist 月老的烦恼(一)||zoj 1284 Perfection
- 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
- poj 1528 Perfection
- 自定义安全性高的验证机制
- vim常见使用命令
- 2017 年最佳开源网络监控工具
- Android:用GSON 五招之内搞定任何JSON数组
- iOS10 新的通知框架 UserNotifications
- ZOJ 1284 Perfection
- CTF安卓逆向练习第四弹
- 【JFinal】Field 'xxx' doesn't have a default value
- maven3 下载配置
- Anemometer安装
- Git使用教程
- 最近的一些交互工作
- SVN
- Android:用GSON 五招之内搞定任何JSON数组