# 南邮数据结构、算法实践周提高题2(Number Games)

A positive integer is considered prime if it is evenly divisible only by itself and 1.
Also, by convention, 1 is not itself a prime.
Thus, the sequence of primes begins:2, 3, 5, 7, 11, 13, 17, ...
A positive integer is called perfect if it is the sum of its proper divisors.
For example, 28 is a perfect number because 28 = 1+2+4+7+14.
Your assignment is to write a program that will input a sequence of integers, one per line,
and output the properties of each integer in the following format:
If the number is neither prime nor perfect, output "Dull".
If the number is prime but not perfect, output "Prime".
If the number is perfect but not prime, output "Perfect".
If the number is both prime and perfect, output "This program doesn't work".
All inputs will be positive integers. The end of input will be marked by the number 0 (no output should be generated for 0).

#include<iostream.h>
#include<math.h>
bool isPrime(int n){
if(n==1){
return false;
}else{
for(int i=2;i<=sqrt(n);i++){
if(n%i==0)
return false;
}
return true;
}
}
bool isPerfect(int n){
int sum=0;
for(int i=1;i<=n/2;i++){
if(n%i==0){
sum+=i;
}
}
if(sum==n)
return true;
else
return false;
}
void Judge(int n){
if(isPrime(n)==1 && isPerfect(n)==1){
cout<<"This program doesn't work."<<endl;
}else if(isPrime(n)==1 && isPerfect(n)==0){
cout<<"Prime."<<endl;
}else if(isPrime(n)==0 && isPerfect(n)==1){
cout<<"Perfect."<<endl;
}else{
cout<<"Dull."<<endl;
}
}
int main(){
int *x=new int[50];
int i=0;
cin>>x[i];
while(x[i]!=0){
cin>>x[++i];
}
for(int j=0;j<i;j++){
Judge(x[j]);
}
return 0;
}

10-28 160

06-17 627

09-02 3652

12-27 1776

01-23 3993

07-19

06-15 5007

07-03 3042

12-01 4706

#### 排序算法（二）简单选择排序验证性实验

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。