Cod sursa(job #1473524)

Utilizator WekTorALLDima Victor WekTorALL Data 19 august 2015 16:08:11
Problema Fractii Scor 100
Compilator java Status done
Runda Arhiva de probleme Marime 1.23 kb
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = null;
		String line = null;
		try {
			br = new BufferedReader(new FileReader("fractii.in"));
		    StringBuilder sb = new StringBuilder();
		    line = br.readLine();
//		    System.out.println(line);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
		    br.close();
		}
		int nmax=Integer.parseInt(line);
		System.out.println(nmax);
		int v[]= new int[nmax+1];
		int i, j;
		long sol=1;
	    for (i = 2; i <= nmax; ++ i)
	        v[i] = i - 1;
//	    for (i = 2; i <= nmax; ++ i)
//	        System.out.print(v[i]+" ");
	    for (i = 2; i <= nmax; ++ i)
	    {
	        sol = (long)(2 * v[i] * 1L + sol);
	        for (j = i * 2; j <= nmax; j += i)
	            v[j] -= v[i];
	    }
	    System.out.println(sol);
	    
	    
	    PrintWriter writer = new PrintWriter("fractii.out", "UTF-8");
	    writer.println(sol);
	    writer.close();
	}
}