Cod sursa(job #2926468)

Utilizator Nico7777777Nicola Andrei George Nico7777777 Data 17 octombrie 2022 20:13:23
Problema Fractii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <iostream>
#include <fstream>
#include <bitset>
#include <vector>
using namespace std;
ifstream f("fractii.in");
ofstream g("fractii.out");
typedef long long LL;
vector<int> era;
int n;
void ciur(vector<int>& eratostene, int n){
    char ciurul[n+1];
    for(int i = 1; i <=n; i++) ciurul[i] = 0;
    for(int i = 2; i <= n; i++)
        if( !ciurul[i] ){
            eratostene.push_back(i);
            for(int j = i * i; j <= n; j += i )
                ciurul[j] = '1';
        }
}
inline LL putere(int p, int e){
    LL rez = 1;
    while(e>1)
        rez*=p, e--;
    return rez;
}
LL totient(int nr){
    vector<int> puteri;
    LL totientul = 1;
    int i = 0, exponent;
    while(nr > 1){
        exponent = 0;
        if(nr % era[i] == 0){
            while(nr % era[i] == 0){
                exponent++;
                nr /= era[i];
            }
        }
        puteri.push_back(exponent);
        i++;
    }
    for(int cnt = 0; cnt < i; cnt++)
        if( putere[ i ] )
            totientul *= putere(era[cnt], puteri[cnt]) * (era[cnt] - 1);
    return totientul;
}
int main()
{
    f >> n;
    ciur(era, n);
    long long rez = 1;
    for(int i = 2; i < n; i++)
        rez += 2*totient(i);
    ///cout<<"merge totientul";
    g << rez;
    f.close(); g.close();
    return 0;
}