Cod sursa(job #3245)

Utilizator alextheroTandrau Alexandru alexthero Data 22 decembrie 2006 19:29:04
Problema Pascal Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <stdio.h>

int r,d;
int an[8];

int putere(int x,int y) {
    int j1=0;
    while((y>1) && (y%x==0)) { 
        y/=x;
        j1++;
    }
    return j1;
}

int main() {
    freopen("pascal.in","r",stdin);
    freopen("pascal.out","w",stdout);

    scanf("%d %d\n",&r,&d);

    an[2]=0;
    an[3]=0;
    an[5]=0;
    int cate=0;
    for(int i=1;i<=r;i++) {
        an[2]=an[2]+putere(2,r-i+1)-putere(2,i);
        an[3]=an[3]+putere(3,r-i+1)-putere(3,i);
        an[5]=an[5]+putere(5,r-i+1)-putere(5,i);
        if(d==2) if(an[2]>=1) cate++;
        else if(d==3) if(an[3]>=1) cate++;
        else if(d==4) if(an[2]>=2) cate++;
        else if(d==5) if(an[5]>=1) cate++;
        else if(d==6) if((an[2]>=1) && (an[3]>=1)) cate++;
    }        
    printf("%d\n",cate);
    return 0;
}