Pagini recente » Cod sursa (job #2753611) | Cod sursa (job #2859351) | Cod sursa (job #296590) | Cod sursa (job #877052) | Cod sursa (job #248010)
Cod sursa(job #248010)
#include stdio.h
#define NMax 1000001
char is[NMax];
unsigned int n;
unsigned long long tot[NMax];
void ciur() {
unsigned int i,j;
for (i=2; i=n; i++) {
if (is[i]==0) i==nr prim
for (j=ii; j=n; j+=i)
is[j]=1; j nu e nr prim
}
}
unsigned int totient(unsigned int x) {
unsigned int i,j=0,k, l=1,pow=1;
if (is[x]==0) return x-1; daca x nr prim, return x-1
k=x;
if (k%2==0) { x == 2^j k, k=1
while (k1 && k%2==0) {
j++; k=2;
}
return (1(j-1))tot[k]; return 2^(j-1) totient[k]
}
for (i=3; k%i!=0; i+=2) {;}
while (k1 && k%i==0) {
j++; k=i;
}
for (l=1; lj; l++)
pow = i;
return ((unsigned int)(i-1))pow((unsigned int)tot[k]);
}
int main() {
unsigned int i;
FILE fin = fopen(fractii.in,r);
FILE fout = fopen(fractii.out,w);
fscanf(fin,%d,&n);
ciur();
tot[1]=1;
tot[0]=1;
for (i=2; i=n; i++) {
tot[i] = totient(i);
tot[0] += 2tot[i];
}
fprintf(fout,%lldn,tot[0]);
fclose(fin);
fclose(fout);
return 0;
}