Cod sursa(job #219598)

Utilizator Bit_MasterAlexandru-Iancu Caragicu Bit_Master Data 7 noiembrie 2008 18:19:33
Problema Fractii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.6 kb
#include <stdio.h>
#include <math.h>
int n,nr,i,j,k;          
bool gasit;        
int main()          
{
    freopen("fractii.in","r",stdin);          
    freopen("fractii.out","w",stdout);          
    scanf("%d",&n);          
    for (i = 2; i <= (n-1); i++)          
		for (j = i + 1; j <= n; j++)          
	    {        
        gasit = false;        
        if ((i%2!=0) || (j%2!=0))      
        {        
            if (i < j)        
            {      
                if (j%i == 0)      
                    gasit = true;      
                else for (k = 3; k <= sqrt(j); k+=2)        
                        if ((i%k == 0) && (j%k == 0))        
                            {        
                                gasit = true;        
                                break;        
                            }        
                        else {}        
            }      
            else       
            {      
                if (i%j == 0)    
                    gasit = true;      
                else for (k = 3; k <= sqrt(i); k+=2)        
                        if ((i%k == 0) && (j%k == 0))        
                            {        
                                gasit = true;        
                                break;        
                            }        
                        else {}        
            }      
        }        
        else gasit = true;        
        if (!gasit)        
            nr++;        
	    }   
    nr = nr * 2 + n * 2 - 1;  
    printf("%d",nr);          
    return 0;          
}