Nu exista pagina, dar poti sa o creezi ...
Cod sursa(job #52180)
Utilizator | Data | 18 aprilie 2007 00:35:49 | |
---|---|---|---|
Problema | Fractii | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.73 kb |
#include <stdio.h>
#include <string.h>
char v[200000];
int prim[200000];
int ciur(int n)
{
int i,j,p=0;
memset(v,1,100005);
v[0]=0; v[1]=1;
for(i=2; i<=n; i++)
if (v[i])
{
prim[p++]=i;
v[i]=i-1;
for (j=i+i; j<=n; j+=i)
v[j]=0;
}
return p;
}
int main()
{
int n,s=0,i,j,p;
FILE *in=fopen("fractii.in","r");
fscanf(in,"%d",&n);
fclose(in);
p=ciur(n);
for (i=2; i<n/2+1; i++)
{
for (j=0; j<p; j++)
if (i*prim[j]<=n)
if (i%prim[j]==0)
v[i*prim[j]]=v[i]*prim[j];
else
v[i*prim[j]]=v[i]*(prim[j]-1);
}
for (i=2; i<=n; i++)
s+=v[i];
s*=2;
s++;
FILE *out=fopen("fractii.out","w");
fprintf(out,"%d\n",s);
fclose(out);
return 0;
}