2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)

题目描述

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 theterms of the sum must be in ascending order. If a number is not perfect, print "Not perfect.".

示例1

输入

3
6
8
28

输出

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

AC代码二:也可以先打表找出10^5内所有完数,一共就4个完数:6,28,496,8128,同样水过!

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

原文地址:https://www.cnblogs.com/acgoto/p/9452519.html

时间: 2024-08-02 22:33:02

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

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

题目链接 2018 ACM 国际大学生程序设计竞赛上海大都会 下午午休起床被同学叫去打比赛233 然后已经过了2.5h了 先挑过得多的做了 .... A题 rand x*n 次点,每次judge一个点位端点的共线向量数判断是否大于给定x 强行rand 500次 代码 #include<bits/stdc++.h> using namespace std; inline int read() { int x = 0,f = 1; char c = getchar(); while(c <

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

传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:00时长: 5小时 比赛情况 实录 难度差不多介于省赛和区域赛之间吧.开题A是计算几何,有点思路后就先放下去写签到题,B读错题WA一发,K直接套模板,然后就接着看A.之前写过类似题,没注意数据范围就头铁地交了发n3的代码,TE后才发现数据范围是之前那道十多倍,就听学长的先看D.推十分钟公式无果后打算直

2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A Fruit Ninja

传送门 题解:给你一堆点问你能不能找出一条直线,使其穿过的点大于n*x. 题解:想起某道CF题目,给你一堆点问你能不能找出两条直线使其穿过所有的点.当时就是在一定时限内随机找了两个点,再枚举每个点是否满足,如果超过该时限仍然不满足则直接返回no.这题也是一样的做法,直接随机两个点,再枚举过去.因为x为0.1到0.9,所以如果所给数据满足条件,那么它有极大概率能够跑出结果.4发只有一次超时 #include<bits/stdc++.h> //CLOCKS_PER_SEC #define se s

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

题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a matrix from two matrices with entries in a field, or, more generally, in a ring or even a semiring. The matrix product is designed for representing the

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

题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点.求最后剩余白色点数. 分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白色点数即列数-区间覆盖的总长度.这就转化成了扫描线的问题. #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn =1e4+5; struct Circle{ LL x,y,r; }p[m

第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安站

 第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安赛区总结报告 报告人:田思明 队名:ACpioneer 队长:陈志阳,队员:顾振兴,田思明 西安区域赛告下帷幕,我和陈志阳,顾振兴组成的ACpioneer队最终获得了一块宝贵的铜牌.首先要感谢陈志阳和顾振兴两位杰出队友的努力训练和出色表现,我作为一个新人跟着他们学到了很多很多,也十分珍惜和他们在一起的训练,比赛时光,其次要感谢陈志老师,不辞辛劳陪我们5队和6队前往西安参加比赛,还要感谢集训队所有曾经帮过我们的所有队员们,记得cdy

《ACM国际大学生程序设计竞赛题解Ⅰ》——基础编程题

这个专栏开始介绍一些<ACM国际大学生程序设计竞赛题解>上的竞赛题目,读者可以配合zju的在线测评系统提交代码(今天zoj貌似崩了). 其实看书名也能看出来这本书的思路,就是一本题解书,简单暴力的通过题目的堆叠来提升解决编程问题的能力. 那么下面开始探索吧. zoj1037: BackgroundFor years, computer scientists have been trying to find efficient solutions to different computing p

第39届ACM国际大学生程序设计竞赛大陆地区赛站奖励方案

搬砖: 为了更好地吸引优秀选手参加第39届ACM国际大学生程序设计竞赛,全球赞助商的经费用于参赛队服和赛事的承办活动,中国赛区赞助商提供的经费用于优秀参赛队的奖励(包括奖金.奖牌.奖杯.获奖证书及奖品等), 竞赛命题,参赛手册,竞赛宣传方面的费用支出.每个赛区的具体奖励方式如下: 设冠军.亚军.季军三座奖杯,分别颁发奖金5000.3500.2000元人民币: 设15名金奖(包括冠.亚.季军)和30名银奖, 铜奖数量为参赛队数的30%: 获金奖的队(未获奖杯的队)每队颁发奖金1000元人民币; 获

2016年中国大学生程序设计竞赛(合肥)-重现赛1008 HDU 5968

异或密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 19    Accepted Submission(s): 9 Problem Description 晨晨在纸上写了一个长度为N的非负整数序列{ai }.对于这个序列的一个连续子序列{al,al+1,…,ar }晨晨可以求出其中所有数异或的结果 alxoral+1xor...xo