Cod sursa(job #402827)

Utilizator andreea1coolBobu Andreea andreea1cool Data 24 februarie 2010 10:36:41
Problema Pascal Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.67 kb
#include<stdio.h>
#include<math.h>
   long int functie(long int n,long int p)
{
	long int s=0;
	while(n)
	{
	    s=s+n/p;
	    n=n/p;
	}
	return s;
}
 long int patru(long int n)
 {
     long int s=0;
     long int i;
     for(i=1;i<=n;i++)
     {
         long int t=i;
         while(t%2==0)
         {
             s++;
             t=t/2;
         }
     }
     return s;
 }

int main()
{
    freopen("pascal.in","r",stdin);
    freopen("pascal.out","w",stdout);
    long int r,j,n,k1=0,k2=0,k3=0,d,p,c=0,i,q,s,t;
    scanf("%ld%ld",&r,&d);
    long k13, k12;
    if(d==2||d==3||d==5)
    {
    k1=functie(r,d);
    }else
    {
        if(d==4)
        {
            k1=functie(r, 2);
        }else
        {
            if(d==6)
            {
                k12=functie(r,2);
                k13=functie(r, 3);
            }
        }
    }
	for(j=0;j<=r;j++)
	{
		p=r-j;
		if(d==2||d==3||d==5)
		{
            k2=functie(p,d);
            k3=functie(j,d);

            if(k1-k2-k3>0)
            {
                c++;
            }
        }
        else
        {
            if(d==4)
            {
                k2=functie(p,2);
                k3=functie(j,2);

                if((k1-k2-k3)/2>0)
                {
                    c++;
                }
            }

             else
             {
                 long k22=functie(p, 2);
                 long k23=functie(p, 3);
                 long k32=functie(j, 2);
                 long k33=functie(j, 3);

                    if(k12-k22-k32>0 && k13-k23-k33>0)
                    {
                        c++;
                    }
             }
        }
        k2=0;
        k3=0;


    }
    printf("%ld",c);
    return 0;
}