Pagini recente » Cod sursa (job #3244911) | Cod sursa (job #907641) | Cod sursa (job #1822755) | Cod sursa (job #1885186) | Cod sursa (job #1126477)
#include <stdio.h>
#include <stdlib.h>
long long solution(int N);
long long solution(int N)
{
long long totalSum = 0;
int i, j;
int aux;
if (N == 1)
{
return 1;
}
else if (N == 2)
{
return 3;
}
else
{
for (i = 2; i < N; i++)
{
for (j = i + 1; j <= N; j++)
{
aux = j % i;
if (aux == 1)
{
totalSum += 2;
}
else if ( (aux != 0) && (j % aux != 0) && (i % aux != 0) )
{
totalSum += 2;
}
}
}
}
// add also all fractions containing "1" and "1/1"
totalSum += ((N - 1)* 2 + 1);
return totalSum;
}
int main(void)
{
FILE* fr = NULL;
FILE* fw = NULL;
int nrInt;
fr = fopen ("fractii.in", "r");
fw = fopen ("fractii.out", "w");
fscanf(in,"%ld",&nrInt);
fprintf(fw,"%lld",solution(nrInt));
fclose(fr);
fclose(fw);
return 0;
}