Răspuns:
La punctul a):
unsigned sum(unsigned long x)
{
unsigned s=0,d;
if(x==1)
return 1;
for(d=1;d*d<=x;d++)
{
if(x%d==0)
s+=d+x/d;
}
return s;
}
Explicație:
La b):
#include <iostream>
using namespace std;
unsigned sum(unsigned long x)
{
unsigned s=0,d;
if(x==1)
return 1;
for(d=1;d*d<=x;d++)
{
if(x%d==0)
s+=d+x/d;
}
return s;
}
int main()
{
unsigned n,i,nrprime=0;
cin>>n;
unsigned v[n];
for(i=0;i<n;i++)
{
cin>>v[i];
if(sum(v[i])==v[i]+1)
nrprime++;
}
cout<<nrprime;
return 0;
}