Cod sursa(job #1420523)

Utilizator alex.vasiuVasiu Alexandru alex.vasiu Data 18 aprilie 2015 16:57:34
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
//bool p[2000002];
long long int phi[2000001];
void phi1(int x)
{

    for(int i = 1; i <= x; i++)
        phi[ i ] = i;

    for(int i = 2; i <= x; i++)
        if( phi[ i ] == i )
            for(int j = i; j <= x; j += i)
                phi[ j ] = phi[ j ]/i*( i - 1 );
}
int main()
{
    int n;
    f>>n;
    phi1(n);
    g<<phi[n];
    /*int c=0;
    for(int i = 2; i <= n; ++i)
        if(!p[i])
        {
            for(int j = i+i; j <= n; j+=i)
                p[j] = 1;
            c++;
        }
        g<<c;*/
}