Cod sursa(job #1213541)

Utilizator mariusbsUnibuc Serban mariusbs Data 28 iulie 2014 13:40:20
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("fractii.in");
ofstream out("fractii.out");
int prime(int p, int q){
	if(p<q)
		swap(p,q);
	if(p%q==0)
		return 0;
	int i;
	for(i=2;i<=q;i++)
		if(p%i==0 && q%i==0)
			return 0;
	return 1;
}
int main(){
int n,p,q,s=0;
in>>n;
in.close();
s=n*n;
for(p=2;p<=n;p++)
	for(q=2;q<=n;q++)
		if(!prime(p,q))
			s--;
	
out<<s<<"\n";
out.close();
return 0;
}