Cod sursa(job #1101256)

Utilizator hevelebalazshevele balazs hevelebalazs Data 8 februarie 2014 09:39:06
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>
#define fr(i,a,b) for(int i=a;i<b;++i)
int p2,p3,p5;
int r,d,d2,d3,d5,s;
void dec(int n,int p){
    while(!(n%2)) p2+=p,n/=2;
    while(!(n%3)) p3+=p,n/=3;
    while(!(n%5)) p5+=p,n/=5;
    }
void c(int n,int k){
    dec(n-k+1,1);
    dec(k,-1);
    }
int main(){
    freopen("pascal.in","r",stdin);
    freopen("pascal.out","w",stdout);
    scanf("%i%i",&r,&d);
    while(!(d%2)) d2++,d/=2;
    while(!(d%3)) d3++,d/=3;
    while(!(d%5)) d5++,d/=5;
    int r2=(r+2)/2;
    fr(i,1,r2) {
        c(r,i);
        s+=(p2>=d2)&&(p3>=d3)&&(p5>=d5);
        }
    s<<=1;
    if(!(r%2)&&r)--s;
    printf("%i",s);
    return 0;
    }