Cod sursa(job #2132572)
Utilizator | Data | 15 februarie 2018 21:07:45 | |
---|---|---|---|
Problema | Fractii | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");
int phi[1000000];
int suma(int n){
int s = 1;
for(int i = 2; i <= n; i++){
phi[i] = i - 1;
}
for(int i = 2; i <= n; i++){
s += 2*phi[i];
for(int j = 2*i; j <= n; j += i){
phi[j] -= phi[i];
}
}
return s;
}
int main(){
int n;
fin >> n;
fout << suma(n);
}