Cod sursa(job #623162)

Utilizator Antonius74Antonius Cezar Hegyes Antonius74 Data 19 octombrie 2011 13:14:53
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <cstdio>
#include <vector>
#include <string.h>
using namespace std;

int main()
{
	freopen ("fractii.in","r", stdin);     
	freopen ("fractii.out","w", stdout); 

	int n, anz_prim = 0, anz = 0;
	scanf ("%d", &n);
	char primzahlen[n+1];
	memset(primzahlen, 0, sizeof(primzahlen));
	primzahlen[1] = 1;
	
	for (int i = 4; i < n + 1; i += 2)         
		primzahlen[i] = 1;
	
	for (int i = 3; i < n + 1; i += 2) 
		if (!primzahlen[i])
			for (int j = i * i; j <= n + 1; j += i)
				primzahlen[j] = 1; 
			
	for (int i = 1; i <= n; i++)
		if (!primzahlen[i])
			anz_prim++;
	
	for (int i = anz_prim - 1; i > 0; i--)
		anz += i;
	
	anz += anz_prim * (n - anz_prim);
	
	printf ("%d \n", anz*2+1);
	
	return 0;
}