Cod sursa(job #268439)

Utilizator shnakoVlad Schnakovszki shnako Data 1 martie 2009 11:55:42
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <stdio.h>
FILE *f, *g;
long a1=0, b1, c1, sw, n, r, d, a, b, c, t, j, h, k;
int main(void)
{
f=fopen("pascal.in", "r");
g=fopen("pascal.out", "w");
fscanf (f, "%ld%ld", &r, &d);
if (r%2)
	{
   sw=0;
	n=r/2+1;
   }
else
	{
   sw=1;
	n=r/2;
   }
for (j=1;j<=n;j++)
	{
   a=0;
   b=0;
   c=0;
	for (h=r-j+1;h<=r;h++)
   	{
      t=h;
      while (t%2==0)
      	{
         a++;
         t/=2;
         }
      while (t%3==0)
      	{
         b++;
         t/=3;
         }
      while (t%5==0)
      	{
         c++;
         t/=5;
         }
      }
   for (h=1;h<=j;h++)
   	{
      t=h;
      while (!t%2)
      	{
         a1++;
         t/=2;
         }
      while (!t%3)
      	{
         b1++;
         t/=3;
         }
      while (!t%5)
      	{
         c1++;
         t/=5;
         }
      }
   a=a-a1;
   b=b-b1;
   c=c-c1;
   if (d==2&&a)
      {
   	k++;
      continue;
      }
   if (d==3&&b)
      {
   	k++;
      continue;
      }
   if (d==4&&a>=2)
      {
   	k++;
      continue;
      }
   if (d==5&&c)
      {
   	k++;
      continue;
      }
	if (d==6&&a&&b)
      {
   	k++;
      continue;
      }
   }
if (sw)
	fprintf(g, "%ld", 2*k-1);
else
	fprintf(g, "%ld", 2*k);
fcloseall();
return 0;
}