All pastes #77895 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-07-03 15:07 UTC
rendered paste body
#include <stdio.h>
#include <memory.h>

#define MAX 200090

long int Tot[MAX]; /* Calculated Euler totients */
long int SumTot[MAX];

int main()
{
	long int n,
			i, j;

	scanf("%ld", &n);

	/* Initialize */
	memset(SumTot, 0, (n+1)*sizeof(long int));
	Tot[0] = Tot[1] = 0;
	for (i=2; i<=n; i++)
		Tot[i] = i;

	/* Apply Sieve to non-primes alone */
	for (i = 2; i<=n; i++){
		if (Tot[i] == i) {
			for (j = i; j <= n; j += i) {
				Tot[j] = Tot[j]*(i-1)/i;
			}
		}
		SumTot[i] = SumTot[i-1] + Tot[i];
	}

	printf("%ld\n", SumTot[n]-1);

	
	return 0;
}