Pagini recente » Cod sursa (job #1194447) | Cod sursa (job #65832) | Cod sursa (job #1323814) | Cod sursa (job #1072651) | Cod sursa (job #27488)
Cod sursa(job #27488)
/***************************************************************************
* Copyright (C) 2007 by Nistor Andrei *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <fstream>
#include <iostream>
using namespace std;
int N;
unsigned long long k = 1;
void citire() {
fstream in ( "fractii.in", ios::in );
in >> N;
in.close();
}
void tipar() {
fstream out ( "fractii.out", ios::out );
out << k;
out.close();
}
unsigned long phi ( unsigned long n ) {
unsigned long phi = 1, p;
for ( p = 2; p * p <= n; p += 2 ) {
if ( n % p == 0 ) {
phi *= p - 1;
n /= p;
while ( n % p == 0 ) {
phi *= p;
n /= p;
}
}
if ( p == 2 )
p--;
}
return ( n == 1 ) ? phi : phi * ( n - 1 );
}
int main ( int argc, char *argv[] ) {
citire();
long int i;
for ( i = 2; i <= N; ++i )
k+=2*phi(i);
tipar();
return 0;
}