- n = s(n),
- σ(n) = 2n,
- khi n = 2: 21(22 − 1) = 6
- khi n = 3: 22(23 − 1) = 28
- khi n = 5: 24(25 − 1) = 496
- khi n = 7: 26(27 − 1) = 8128.
#include<stdio.h>
bool soHoanHao(int n)
{
int tongUoc = 0;
for(int i=1;i<n;i++)
{
if(n%i==0) tongUoc = tongUoc+i;
}
if(tongUoc == n) return true;
else return false;
}
int main()
{
int n;
printf("Nhap n:");
scanf("%d",&n);
if(soHoanHao(n)==true) printf("%d la so hoan hao!",n);
else printf("%d khong phai la so hoan hao!",n);
return 0;
}
0 comments:
Post a Comment
Click to see the code!
To insert emoticon you must added at least one space before the code.