#include <bits/stdc++.h>
using namespace std;
int i,j,s1,s2,dem,n;
bool ktnt(int a)
{
if (a < 2) return false;
for (j=2;j <= int(a/2);j++)
if (a%j == 0) return false;
return true;
}
bool ktshh(int a)
{
if (a < 1) return false;
s1=0;
for (j=1;j <= int(a/2);j++)
if (a%j == 0) s1=s1+j;
if (s1 == a) return true;
else return false;
}
int main()
{
n=0;
while ((n < 2) || (n > 1000))
{
cout << "n = ";
cin >> n;
}
dem=0;
for (i=1;i<=n;i++)
if (ktnt(i) == true) dem++;
cout << "Co " << dem << " so nguyen to tu 1 den " << n << endl;
s2=0;
for (i=1;i<=n;i++)
if (ktshh(i) == true) s2=s2+i;
if (s2 == 0) cout << "Khong co so hoan hao trong khoang tu 1 den " + n << endl;
else cout << "Tong cac so hoan hao tu 1 den " << n << " la: " << s2 << endl;
system("pause");
}