Cod sursa(job #669072)
| Utilizator | Data | 26 ianuarie 2012 00:58:17 | |
|---|---|---|---|
| Problema | Fractii | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <fstream>
using namespace std;
bool a[1000000];
int main()
{
int n;
float phi[1000000];
ifstream in("fractii.in");
in >> n;
in.close();
a[1] = 1;
for (int i = 1; i <= n; ++i)
phi[i] = i;
for (float i = 2; i <= n; ++i)
{
if (!a[int(i)])
{
phi[int(i)]=i-1;
for (float j = 2*i; j <= n; j+=i)
{
a[int(j)] = 1;
phi[int(j)]*=((i-1)/i);
}
}
}
int total=0;
for (int i = 2; i<=n;++i)
total+=int(phi[i]);
ofstream out("fractii.out");
out << 2*total + 1;
out.close();
return 0;
}
