Cod sursa(job #680065)

Utilizator vladhVlad Harbuz vladh Data 14 februarie 2012 01:16:09
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include<fstream>
using namespace std;
unsigned gcd(unsigned const a, unsigned const b){
	return (a < b) ? gcd(b, a) : ((a % b == 0) ? b : gcd(b, a % b));
}
int main(){
	ifstream in("fractii.in");
	ofstream out("fractii.out");
	unsigned n,i,j,s=0;
	in>>n;
	s+=n*2-1;
	for(i=2;i<=n;i++)
		for(j=2;j<=n;j++)
			if((!i%j && !j%1) || gcd(i,j)==1)
				s++;
	out<<s;
	return 0;
}