Pagini recente » Cod sursa (job #1038178) | Cod sursa (job #2593606) | Cod sursa (job #2565458) | Cod sursa (job #2802609) | Cod sursa (job #28410)
Cod sursa(job #28410)
#include<fstream.h>
int e[100],n;
float pr[100];
long long int s=1,p;
int main()
{
int i,j;
ifstream f("fractii.in");
f>>n;
f.close();
for(i=1;i<=n;i++)
{
e[i]=1;
pr[i]=1;
}
for(i=2;i<=n/2;i++)
if(e[i]==1)
for(j=2;j*i<=n;j++)
e[i*j]=0;
for(i=2;i<=n;i++)
{
if(e[i]==1)
{
pr[i]=i-1;
for(j=2;j*i<=n;j++)
{
pr[i*j]*=i-1;
pr[i*j]/=i;
}
}
else
pr[i]*=i;
s+=2*pr[i];
}
ofstream g("fractii.out");
g<<s<<"\n";
g.close();
return 0;
}