Cod sursa(job #780162)

Utilizator vladvaldezVlad Dimulescu vladvaldez Data 19 august 2012 22:52:35
Problema Pascal Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.84 kb
#include <stdio.h>

FILE *f,*g;
long l,k,n,p,d,i,factor,j,a[10],v[10],r,c1,c2,c3,c4,c5,c6;
int main ()
{
  f=fopen("pascal.in","r");
  g=fopen("pascal.out","w");
fscanf(f,"%ld",&r);
fscanf(f,"%ld",&d);
if (d!=1){
if ((r-1)%2==0)l=r/2;
else l=(r-1)/2+1;
for (j=1;j<=l;j++){

for(k=2;k<=5;k++)v[k]=0;
//pas1
for (i=r;i>r-j;i--){
p=i;
factor=2;
while (p%2==0){
v[2]++;
p=p/2;
}
factor=3;
    while (p%factor==0){
    v[factor]++;
    p=p/factor;
    }
factor=5;
    while (p%factor==0){
    v[factor]++;
    p=p/factor;
    }
//factor=factor+2;
//if (factor>max)max=factor;
}


for(k=2;k<=5;k++)a[k]=0;
//pas2
for (i=1;i<=j;i++){
p=i;
factor=2;
while (p%2==0){
a[2]++;
p=p/2;
}
factor=3;
    while (p%factor==0){
    a[factor]++;
    p=p/factor;
    }
factor=5;
    while (p%factor==0){
    v[factor]++;
    p=p/factor;
    }
//factor=factor+2;
//if (factor>max)max=factor;
}

//dif
for(k=2;k<=5;k++)
{
 if (a[k]!=0)v[k]=v[k]-a[k];
}

if ((r-1)%2==1){
if (d==2) {if (v[2]!=0)c2++;if (j<l && v[2]!=0)c2++;}
 if (d==3) {if (v[3]!=0)c3++;if (j<l && v[3]!=0)c3++;}
 if (d==4) {if (v[2]>1)c4++;if (j<l && v[2]>1)c4++;}
 if (d==5) {if (v[5]!=0)c5++;if (j<l && v[5]!=0)c5++;}
if (d==6) {if(v[3]!=0 && v[2]!=0)c6++;if (j<l && v[3]!=0 && v[2]!=0)c6++;}
}
else {
if (d==2) {if (v[2]!=0)c2++;if (j<=l && v[2]!=0)c2++;}
 if (d==3) {if (v[3]!=0)c3++;if (j<=l && v[3]!=0)c3++;}
 if (d==4) {if (v[2]>1)c4++;if (j<=l && v[2]>1)c4++;}
 if (d==5) {if (v[5]!=0)c5++;if (j<=l && v[5]!=0)c5++;}
if (d==6) {if(v[3]!=0 && v[2]!=0)c6++;if (j<=l && v[3]!=0 && v[2]!=0)c6++;}
}

}

if (d==2) fprintf(g,"%ld",c2);
if (d==3) fprintf(g,"%ld",c3);
if (d==4) fprintf(g,"%ld",c4);
if (d==5) fprintf(g,"%ld",c5);
if (d==6) fprintf(g,"%ld",c6);

fclose(g);
return 0;

}
else fprintf(g,"%ld",r+1);
fclose(g);
return 0;
}