Cod sursa(job #3258791)

Utilizator Antonio8Mincu Antonio Alexandru Antonio8 Data 23 noiembrie 2024 17:28:14
Problema Fractii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
const int VMAX = 1000006;
int e[VMAX + 1];
void ciur_eratostene(){
    for(int i = 1; i <= VMAX; i++)
        e[i] = i;
    for(int d = 2; d <= VMAX; d++){
        if(e[d] == d){
            for(int m = d; m <= VMAX; m += d){
                e[m] = e[m] / d * (d - 1);
            }
        }
    }
}
int main(){
    ciur_eratostene();
    int n;
    fin >> n;
    long long s = 1;
    for(int i = 2; i <= n; i++)
        s += 2 * e[i];
    fout << s;
    return 0;
}