Cod sursa(job #623152)

Utilizator Antonius74Antonius Cezar Hegyes Antonius74 Data 19 octombrie 2011 12:46:39
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <cstdio>
using namespace std;

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

	int n, anz = 0, a;
	float tot;
	scanf ("%d", &n);

	for (int i = 2; i <= n; i++)
	{
		tot = i;
		a=i;
		if (a%2==0)
		{
			tot*=1.0-1.0/2;
				while (a%2==0)				
					a/=2;
		}
		for (int j=3;j<=n;j+=2)
			if (a%j==0)
			{
				tot*=1.0-1.0/j;
				while (a%j==0)				
					a/=j;
			}
		anz+=(int)tot;
	}
	
	printf ("%d \n", anz*2+1);
	
	return 0;
}