# 南邮数据结构、算法实践周提高题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;
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

#### 南邮数据结构实验4：各种内排序算法

12-27 1776

#### 南邮数据结构试验---各种内排序算法实现及比较

01-23 3993

#### 数据结构中的各种排序算法实现的程序下载

07-19

06-15 5007

#### 各种内排序算法的实现及性能比较（实验四）

07-03 3042

#### 南邮算法分析与设计实验4 密码算法

12-01 4706

#### 排序算法（二）简单选择排序验证性实验 ©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 点击重新获取   扫码支付 1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。 余额充值