Pagini recente » Cod sursa (job #2898179) | Cod sursa (job #1860230) | Cod sursa (job #2549777) | Cod sursa (job #1868377) | Cod sursa (job #3238592)
#include<stdio.h>
void era(int max,int a[1000001])
{
for(int i=2;i<=max;i++)
if(a[i]==0)
for(int j=i+i;j<=max;j=j+i)
a[j]=1;
}
int cop(int a,int b)
{
while(b)
{
int r=a%b;
a=b;
b=r;
}
return a;
}
int b[100001],era1[1000001];
int main()
{
FILE*f=fopen("pairs.in","r");
FILE*g=fopen("pairs.out","w");
int a,c,max=0,x,y,s=0;
fscanf(f,"%d",&a);
for(int i=1;i<=a;i++)
{
fscanf(f,"%d",&c);
if(c>1&&c<1000000)
b[i]=c;
if(b[i]>max)
max=b[i];
}
era(max,era1);
c++;
int t,t1;
for(int i=1;i<a;i++)
for(int j=1+i;j<=a;j++)
{
x=b[i];
y=b[j];
if(x>y)
{
t=x;
t1=y;
}
else
{
t=y;
t1=x;
}
if(era1[x]==0&&era1[y]==0)
s++;
else if(((era1[x]==0&&era1[y]==1)||(era1[x]==1&&era1[y]==0))&&t%t1!=0)
s++;
else if(x==y+1||x==y-1)
s++;
else
if(cop(x,y)==1)
s++;
}
fprintf(g,"%d",s);
}