Pagini recente » Cod sursa (job #650585) | Cod sursa (job #1523099) | Cod sursa (job #779140) | Cod sursa (job #1460479) | Cod sursa (job #2698730)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
const int N = 1000000;
int seen[N+5],Prime[N+5],n,p;
long long sum=1;
void Eratostene()
{
seen[1]=1;
for(int i=2; i*i<=N; i++)
for(int j=i+i; i*j<=N; j+=i)
seen[j]=1;
}
void GetPrime()
{
for(int i=1; i<=N; i++)
{
if(!seen[i])
{
n++;
Prime[n]=i;
}
}
}
int EulerTotient(int k)
{
int p=0,cnt=1,d=Prime[1],ans=1;
while(k>1)
{
p=0;
while(k%d==0)
{
p++;
k/=d;
}
if(p)
{
ans*=(d-1);
for(int i=1; i<p; i++)
ans*=d;
}
cnt++;
d=Prime[cnt];
if(k>1 && d*d>k)
d=k;
}
return ans;
}
void Print()
{
for(int i=2; i<=p; i++)
sum+=EulerTotient(i)*2;
fout<<sum;
}
int main()
{
/*
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
*/
Eratostene();
GetPrime();
fin>>p;
Print();
}