题目描述

We consider a positive integer perfect, if and only if it is equal to the sum of its positive divisors less than itself.
For example, 6 is perfect because 6 = 1 + 2 + 3.
Could you write a program to determine if a given number is perfect or not?

输入描述:

The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
Each test case contains a line with a positive integer N (2 ≤ N ≤ 10^5).

输出描述:

For each test case, print the case number and determine whether or not the number is perfect.
If the number is perfect, display the sum of its positive divisors less than itself. The ordering of the
terms of the sum must be in ascending order. If a number is not perfect, print "Not perfect.".

输入例子:
3
6
8
28
输出例子:
Case 1: 6 = 1 + 2 + 3
Case 2: Not perfect.
Case 3: 28 = 1 + 2 + 4 + 7 + 14

-->

示例1

输入

3
6
8
28

输出

Case 1: 6 = 1 + 2 + 3
Case 2: Not perfect.
Case 3: 28 = 1 + 2 + 4 + 7 + 14
解题思路:测试数据不大,暴力水过!
AC代码一:
 #include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int t,n,sum,k,s[maxn];
int main(){
while(~scanf("%d",&t)){
for(int i=;i<=t;++i){
sum=k=;
scanf("%d",&n);
for(int j=;j<=n/;++j)
if(n%j==){sum+=j;s[k++]=j;}
printf("Case %d: ",i);
if(sum!=n)printf("Not perfect.\n");
else{
printf("%d = %d",n,s[]);
for(int j=;j<k;++j)
printf(" + %d",s[j]);
printf("\n");
}
}
}
return ;
}

AC代码二:也可以先打表找出10^5内所有的完数,一共只有4个完数为6,28,496,8128,这样也可以简单过!

 #include<cstdio>
int t,n;
int main(){
while(~scanf("%d",&t)){
for(int i=;i<=t;++i){
scanf("%d",&n);
printf("Case %d: ",i);
if(n==)printf("6 = 1 + 2 + 3\n");
else if(n==)printf("28 = 1 + 2 + 4 + 7 + 14\n");
else if(n==)printf("496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248\n");
else if(n==)printf("8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064\n");
else printf("Not perfect.\n");
}
}
return ;
}

2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会部分题解

    题目链接 2018 ACM 国际大学生程序设计竞赛上海大都会 下午午休起床被同学叫去打比赛233 然后已经过了2.5h了 先挑过得多的做了 .... A题 rand x*n 次点,每次judge一个点 ...

  2. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

  3. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  4. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

  5. 2018 ACM 国际大学生程序设计竞赛上海大都会赛

    传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)

    题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...

  7. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D

    A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...

  8. 2018 ACM 国际大学生程序设计竞赛上海大都会 F - Color it (扫描线)

    题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点.求最后剩余白色点数. 分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白 ...

  9. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)

    题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...

随机推荐

  1. LOJ#539. 「LibreOJ NOIP Round #1」旅游路线

    n<=100,m<=1000的图,在此图上用油箱容量C<=1e5的车来旅行,旅行时,走一条边会耗一单伟油,在点i时,若油量<ci,则可以把油以pi的价格补到ci,pi<= ...

  2. NIST的安全内容自动化协议(SCAP)以及SCAP中文社区简介

    https://blog.csdn.net/langkew/article/details/8795530?utm_source=tuicool&utm_medium=referral

  3. Arctic Network POJ - 2349

    The Department of National Defence (DND) wishes to connect several northern outposts by a wireless n ...

  4. 学习日常笔记<day09>Http协议

    1 Http协议入门 1.1 什么是http协议 http协议: 对浏览器客户端 和  服务器端 之间数据传输的格式规范 1.2 查看http协议的工具 1)使用火狐的firebug插件(右键-> ...

  5. spring面试相关点

    刚刚开通博客,因为最近在进行各种面试,遇到各种面试问题,用这个机会整理几篇文章方便日后需要 springmvc 和springboot spring boot只是一个配置工具,整合工具,辅助工具. s ...

  6. MongoDB小结14 - find【查询条件$lt $lte $gt $gte】

    $lt $lte $gt $gte 以上四个分别表示为:< . <= . > . >= . 通常的做法是将他们组合起来,以便查找一个范围. 比如,查询年龄在18到25岁(含)的 ...

  7. [Jexus系列] 一、安装并运行 Jexus

    注意,本教程使用的jexus版本为5.8.3专业版,操作系统为 Ubunutu 16.04 64位 一.创建默认站点 不熟悉vim的可以看这个: vim超简单入门教程 sudo mkdir -p /v ...

  8. phpunit 单元测试框架-代码覆盖率

    "phpize not found" 的解决办法: apt-get install php5-dev http://jeffreysambells.com/2010/04/08/r ...

  9. 【转】学习JavaScript闭包

    原文: http://www.cnblogs.com/Lau7/p/7942100.html#undefined ------------------------------------------- ...

  10. [Maid] Write Tasks in Markdown with Maid

    Maid enables you to write your tasks in Markdown. Create a maidfile.md or a README.mdthen add Header ...