Cod sursa(job #109397)

Utilizator crawlerPuni Andrei Paul crawler Data 25 noiembrie 2007 10:45:21
Problema Pairs Scor 20
Compilator cpp Status done
Runda preONI 2008, Runda 1, Clasa a 10-a Marime 1.47 kb
#include <cstdio>
#include <algorithm>

using namespace std;

int n, v[100100];

int prime(int a,int b)
{
    int k=0;    
    while ((a&1)==0 && (b&1)==0) a>>=1, b>>=1, ++k;
    while (a!=b)
    {
               if ((a&1)==0) a>>=1; else
               if ((b&1)==0) b>>=1; else
               if (a>b) a=(a-b)>>1; else b=(b-a)>>1;          
    }
    return (a<<k)==1;
}

#define DIM 10000
char buf[DIM];
int poz;

#define buffer fread(buf,1,DIM,stdin), poz=0
#define cit(x)                                                \
{                                                             \
x = 0;                                                        \
while (buf[poz] < '0') { ++poz; if(poz == DIM) buffer;  }     \
while (buf[poz] >= '0')                                       \
      {                                                       \
           x = x*10 + buf[poz]-'0';  ++poz;                   \
           if(poz == DIM) buffer;                             \
      }                                                       \
}



int main()
{
	freopen("pairs.in","r",stdin);
	freopen("pairs.out","w",stdout); 
	buffer;
	unsigned long long cnt=0;
	
	//scanf("%d", &n);
	cit(n)
	
	
	for (int i=1;i<=n;++i)
	   //scanf("%d", v+i);
	    cit(v[i])
	    
	sort(v+1,v+n+1);
    
	for (int i=1;i<n;++i)    
	 for (int j=i+1;j<=n;++j)
	  if (prime(v[i],v[j])) ++cnt;
      
	printf("%llu\n", cnt);  


	return 0;
}


 //by Crawler