Cod sursa(job #177370)

Utilizator bogdanhm999Casu-Pop Bogdan bogdanhm999 Data 12 aprilie 2008 20:03:46
Problema Pascal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <stdio.h>

long r,t,i,d,p2,p3,p5,pd2,pd3,pd5,x,sol;

int main(){
    freopen("pascal.in","r",stdin);
    freopen("pascal.out","w",stdout);
    
    scanf("%ld %ld",&r,&d);
    t=r+1;
    p2=0;p3=0;p5=0;
    if (d==2)
       pd2=1;
    if (d==3)
       pd3=1;
    if (d==4)
       pd2=2;
    if (d==5)
       pd5=1;
    if (d==6){
       pd2=1;pd3=1;
    }
    for (i=1;i<t;++i){
        x=r-i+1;
        while (x%2==0){
              p2++;
              x/=2;
        }
        while (x%3==0){
              p3++;
              x/=3;
        }
        while (x%5==0){
              p5++;
              x/=5;
        }
        x=i;
        while (x%2==0){
              p2--;
              x/=2;
        }
        while (x%3==0){
              p3--;
              x/=3;
        }
        while (x%5==0){
              p5--;
              x/=5;
        }
        if (p2>=pd2&&p3>=pd3&&p5>=pd5)sol++;
    }
    printf("%ld\n",sol);
    
return 0;
}