Cod sursa(job #3137457)
| Utilizator | Data | 13 iunie 2023 00:30:40 | |
|---|---|---|---|
| Problema | Fractii | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
const int dim=1e6;
int PHI[dim];
long long int n;
void phi(int n)
{
for(int i=0;i<=n;i++)
PHI[i]=i;
for(int i=2;i<=n;i++)
{
if(PHI[i]==i)
{
for(int j=i;j<=n;j+=i)
PHI[j]-=PHI[j]/i;
}
}
}
ll dp[dim];
int main()
{
fin>>n;
phi(n);
dp[1]=1;
for(ll i=2;i<=n;i++)
dp[i]=dp[i-1]+2*PHI[i];
fout<<dp[n];
}
