Cod sursa(job #135802)
| Utilizator | Data | 14 februarie 2008 16:29:29 | |
|---|---|---|---|
| Problema | Fractii | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.46 kb |
#include<fstream>
#include<stdlib.h>
using namespace std;
int prime(int a,int b)
{ int k;
for(k=2;k<=a;k++)
if((a%k==0)&&(b%k==0)) return 0;
else return 1;
}
int main()
{int N,P,Q,contor;
ifstream f("fractii.in");
f>>N;
f.close();
contor=2*N;
for(P=2;P<=N;P=P+2)
for(Q=3;Q<=N;Q=Q+2)
if (prime(P,Q)) contor++;
for(P=3;P<=N;P=P+2)
for(Q=1;Q<=N;Q++)
if (prime(P,Q)) contor++;
ofstream g("fractii.out");
g<<contor;
g.close();
return 0;
}
