Pagini recente » Cod sursa (job #1151511) | Cod sursa (job #2552429) | Cod sursa (job #2421261) | Cod sursa (job #1833244) | Cod sursa (job #109405)
Cod sursa(job #109405)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
FILE *f=fopen("pairs.in","r");
FILE *g=fopen("pairs.out","w");
long n,m[100000],k;
char s[1000000];
int valid(long a,long b){
char n1[20],n2[20],p[50],bb[50];
memset(p,0,50);
ltoa(a,n1,10);
ltoa(b,n2,10);
strcpy(p+strlen(p),n1);p[strlen(p)]='.';
strcat(p,n2);
strcpy(bb,p);strrev(bb);
if(!strstr(s,p) && !strstr(s,bb)){
strcat(s,p);s[strlen(s)]=',';
return 1;
}
return 0;
}
void citeste(){
fscanf(f,"%ld",&n);
for(int i=1;i<=n;i++) fscanf(f,"%ld",&m[i]);
}
int cmmdc(long a,long b){
long r;
do{
r=a%b;
a=b;
b=r;
}
while (b!=0);
if(a==1) return 1;
return 0;
}
int main(){
citeste();
for(int i=1;i<n;i++){
for(int j=i+1;j<=n;j++){
if(cmmdc(m[i],m[j]) && valid(m[i],m[j])) k++;
}
}
fprintf(g,"%ld",k);
return 0;
}