Cod sursa(job #219548)

Utilizator Bit_MasterAlexandru-Iancu Caragicu Bit_Master Data 7 noiembrie 2008 12:31:41
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <stdio.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 = 0;      
            if ((i%2!=0) || (j%2!=0))    
            {      
                if (i > j)      
                    {    
                        if (i%j == 0)    
                            gasit = 1;    
                        else for (k = 3; k <= (i/2); k+=2)      
                                if ((i%k == 0) && (j%k == 0))      
                                {      
                                    gasit = 1;      
                                    break;      
                                }      
                                else {}      
                    }    
                else     
                {    
                    if (j%i == 0)  
                        gasit = 1;    
                    else for (k = 3; k <= (j/2); k+=2)      
                            if ((i%k == 0) && (j%k == 0))      
                            {      
                                gasit = 1;      
                                break;      
                            }      
                            else {}      
                }    
            }      
        else gasit = 1;      
        if (!gasit)      
            nr++;      
        } 
	nr = nr * 2 + n * 2 - 1;
    printf("%d",nr);        
    return 0;        
  }