Cod sursa(job #173838)

Utilizator robbyRobertino robert robby Data 8 aprilie 2008 10:15:54
Problema Indep Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <stdio.h>
int a[501],v[1001];
int prim(int x,int y)
{
  int r;
  r=x%y;
  while (r)
    {
      x=y;
      y=r;
      r=x%y;
    }
  return y-1;
}

FILE *f,*g;
int main()
{
  int n,i,j,ce,k;
  long s=0;
  f=fopen("indep.in","rt");
  g=fopen("indep.out","wt");
  fscanf(f,"%d\n",&n);
  k=1;
  for (i=1;i<=n;i++)
    {fscanf(f,"%d\n",&a[i]);if (a[i]==1&&k) {s++;k=1;}}
  for (i=1;i<=n;i++)
    for (j=i+1;j<=n;j++)
     if (!prim(a[i],a[j]))
      {
	for (ce=1;ce<=1000;ce++)
	  v[ce]=0;
	k=n-j;
	v[a[i]]=1;
	v[a[j]]=1;
	if (a[i]==a[j])
	  k--;
	for (ce=j+1;ce<=n;ce++)
	  if (v[a[ce]])
	    k--;
	   else
	    v[a[ce]]=1;
	s+=1<<k;
      }
  fprintf(g,"%ld\n",s);
  fclose(f);
  fclose(g);
  return 0;
}