Cod sursa(job #1324536)

Utilizator A63N7pTudor Nazarie A63N7p Data 22 ianuarie 2015 15:24:47
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
/*
 * 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 3 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, see <http://www.gnu.org/licenses/>.
*/

#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

int v[1000005];

ifstream in;
ofstream out;

long long int getAnswer(int);

int main(int argc, char *argv[])
{
	in.open("fractii.in");
	out.open("fractii.out");

	int n;
    in >> n;
    out << getAnswer(n) << endl;

    in.close();
    out.close();
    return 0;
}

long long int getAnswer(int n)
{
    long long int nr = 0;
    for (int i = 2; i <= n; i++) {
        v[i] = i - 1;
    }
    for (int i = 2; i <= n; i++) {
        for(int j = 2 * i; j <= n; j += i) {
            v[j] = v[j] - v[i];
        }
    }
	for(int i = 1; i <= n; i++) {
           nr += v[i];
	}
    nr *= 2;
    nr++;
    return nr;
}