Pagini recente » Cod sursa (job #7216) | Cod sursa (job #1645612) | Cod sursa (job #1632883) | Cod sursa (job #1351629) | Cod sursa (job #1477485)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#define lm 1000001
#define pb push_back
using namespace std;
int n;
bool l[lm];
int Euclid (int a,int b)
{
if(!b)
return a;
return Euclid (b,a%b);
}
int main()
{
ifstream f("fractii.in");
ofstream g("fractii.out");
f>>n;
for (int i=2; i<=n; i++)
if(!l[i])
{
for (int j=i+i; j<=n; j+=i)
{
l[j]=true;
}
}
int res=n;
for (int i=2; i<=n; i++)
{
for (int j=2; j<=n; j++)
{
if(i!=j)
{
if(!l[j] && !l[i])
res++;
else
if(Euclid(i,j)==1)
res++;
}
}
res++;
}
g<<res;
return 0;
}