Cod sursa(job #795959)

Utilizator boss1999agagagtrate boss1999 Data 9 octombrie 2012 21:56:01
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<stdio.h>
#define ll long long
using namespace std;
long long n,i,j,f,v[1000001],x,y,k,l,p,o,m,m1,m2,m3;
int main()
{
freopen("fractii.in","r",stdin);
freopen("fractii.out","w",stdout);
scanf("%lld",&n);
x=1;
for(i=2;i<=n;i++)
{
if(v[i]==0)
{
v[i]=i-1;
for(j=i*i;j<=n;j=j+i)
v[j]=i;
}
else
{
f=v[i];
j=i;
v[i]=f;
v[i]--;
j=j/f;
while(j%f==0)
{
v[i]=v[i]*f;
j=j/f;
}
if(j>1)
v[i]=v[i]*v[j];
}
x=x+2*v[i];
}
if(x!=0)
printf("%lld",x);
return 0;
}