Cod sursa(job #38750)

Utilizator razyelxrazyelx razyelx Data 26 martie 2007 00:46:36
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <fstream.h>
#include <math.h>
int main(){
	long long n,i,s2=0,s=1,ok,d,p,aux;
	ifstream f("fractii.in");
	ofstream g("fractii.out");
	f>>n;
	for(i=2;i<=n;i++){
		d=2;ok=0;s2=1;
		while(d<=i/2&&!ok)
			if(i%d==0)ok=1;
			else d++;
		if(ok){
			d=2;aux=i;
			while(aux>1){
				p=0;ok=0;
				while(aux%d==0){aux/=d;p++;ok=1;}
				if(ok==1)s2*=(d-1)*pow(d,p-1);
				d++;
			}
			s+=2*s2;
		}else
			s+=2*(i-1);
	}
	g<<s;
	return 0;
}