Cod sursa(job #1101253)

Utilizator hevelebalazshevele balazs hevelebalazs Data 8 februarie 2014 09:33:49
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 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){
    while(!(n%2)) p2+=n/=2;
    while(!(n%3)) p3+=n/=3;
    while(!(n%5)) p5+=n/=5;
    }
void c(int n,int k){
    dec(n-k+1);
    dec(-k);
    }
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;
    }