2017湖南多校第一场-F(1005): Federation Favorites
2017-03-22 13:14
232 查看
F(1005): Federation Favorites
Submit Page Summary Time Limit: 5 Sec Memory Limit: 128 Mb Submitted: 46 Solved: 23
Description
En route to Rigel 7, Chief Engineer Geordi Laforge and Data were discussing favorite numbers. Geordi exclaimed he preferred Narcissistic Numbers: those numbers whose value is the same as the sum of the digits of that number, where each digit is raised to the power of the number of digits in the number. Data agreed that Narcissistic Numbers were interesting, but not as good as his favorite: Perfect Numbers. Geordi had never heard of a Perfect Number, so Data elaborated, \A positive integer is said to be Perfect if it is equal to the sum of its positive divisors less than itself. For example, 6 is Perfect because 6 = 1 + 2 + 3.” Geordi began thinking about an algorithm to determine if a number was Perfect, but did not have the raw computing ability of Data. He needs a program to determine if a given number is Perfect. Help Geordi write that program.
Input
Input consists of a single entry per line. Each line contains a single positive integer n, where 2 < n < 100; 000 for each case. A line containing -1 denotes the end of input and should not be processed.
Output
For each case, 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 \ is NOT perfect.” where is the number in question. There must be a single space between any words, symbols, or numbers in all output, with the exception of the period at the end of the sentence when a number is not perfect.
Sample Input
6
12
28
-1
Sample Output
6 = 1 + 2 + 3
12 is NOT perfect.
28 = 1 + 2 + 4 + 7 + 14
题目大意:判断一个数是不是完全数(完美数)
解题思路:找出该数的所有因子,直接判断即可
Submit Page Summary Time Limit: 5 Sec Memory Limit: 128 Mb Submitted: 46 Solved: 23
Description
En route to Rigel 7, Chief Engineer Geordi Laforge and Data were discussing favorite numbers. Geordi exclaimed he preferred Narcissistic Numbers: those numbers whose value is the same as the sum of the digits of that number, where each digit is raised to the power of the number of digits in the number. Data agreed that Narcissistic Numbers were interesting, but not as good as his favorite: Perfect Numbers. Geordi had never heard of a Perfect Number, so Data elaborated, \A positive integer is said to be Perfect if it is equal to the sum of its positive divisors less than itself. For example, 6 is Perfect because 6 = 1 + 2 + 3.” Geordi began thinking about an algorithm to determine if a number was Perfect, but did not have the raw computing ability of Data. He needs a program to determine if a given number is Perfect. Help Geordi write that program.
Input
Input consists of a single entry per line. Each line contains a single positive integer n, where 2 < n < 100; 000 for each case. A line containing -1 denotes the end of input and should not be processed.
Output
For each case, 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 \ is NOT perfect.” where is the number in question. There must be a single space between any words, symbols, or numbers in all output, with the exception of the period at the end of the sentence when a number is not perfect.
Sample Input
6
12
28
-1
Sample Output
6 = 1 + 2 + 3
12 is NOT perfect.
28 = 1 + 2 + 4 + 7 + 14
题目大意:判断一个数是不是完全数(完美数)
解题思路:找出该数的所有因子,直接判断即可
#include<iostream> #include<cstdio> #include<string> using namespace std; int fac[500]; int main() { while(true) { int num; scanf("%d",&num); if(num==-1) break; int sum=1; int nFacs = 1; fac[0]=1; for(int i=2;i<=num/2;i++) { if(num % i == 0) { sum += i; fac[nFacs++] = i; } } if(sum==num) { printf("%d = %d",num,fac[0]); for(int i=1;i<nFacs;i++) printf(" + %d",fac[i]); printf("\n"); }else { printf("%d is NOT perfect.\n",num); } } } /* 6 6 = 1 + 2 + 3 28 28 = 1 + 2 + 4 + 7 + 14 496 496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248 8128 8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064 33550336 33550336 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8191 + 16382 + 32764 + 65528 + 131056 + 262112 + 524224 + 1048448 + 2096896 + 4193792 + 8387584 + 16775168 */
相关文章推荐
- 2017湖南多校第一场-B(1002): Bones’s Battery
- 2017湖南多校第一场-A(1001): Assignments
- 2017湖南多校第一场-Generations of Tribbles
- 百度之星 2017初赛第一场 1005 今夕何夕
- 2017湖南多校第一场-Enterprising Escape
- 2017湖南多校第一场-L(1011): Languages
- 2017百度之星资格赛(A)1005 今夕何夕(日期计算)
- 2017 计蒜之道 初赛 第一场 A题B题
- 2017 计蒜之道 初赛 第一场 A题B题
- 2017计蒜之道初赛第一场B
- 计蒜客 2017 初赛第一场 B. 阿里天池的新任务(简单)
- 【2017 ACM/ICPC Asia Regional Shenyang Online 1005】hdu 6198 number number number
- 网易互娱2017实习生招聘在线笔试第一场题目解析
- 2017 7.25多校训练第一场补题
- 2017 国庆湖南 Day4
- HDU 6084 | 2017百度之星资格赛 1005 卡特兰数 + 分块打表
- 2017多校训练Contest3: 1005 RXD and dividing hdu6060
- 2017 多校7 1005 Euler theorem
- HDU 6148 && 2017 百度之星复赛 1005 Valley Numer(数位dp)
- 2017 Multi-University Training Contest - Team 9 1005 FFF at Valentine