Cod sursa(job #3251)

Utilizator alextheroTandrau Alexandru alexthero Data 22 decembrie 2006 20:18:38
Problema Pascal Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <stdio.h>

int r,d;
int an[8];

int putere(int x,int y) {
    int j1=0;
    while((y>1) && (x%y==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;
    int mijl=(r+1)/2;
    int mijll=(r+1)/2+(r+1)%2;
    for(int i=2;i<=mijll;i++) {
        an[2]=an[2]+putere(2,r-i+2)-putere(2,i-1);
        an[3]=an[3]+putere(3,r-i+2)-putere(3,i-1);
        an[5]=an[5]+putere(5,r-i+2)-putere(5,i-1);
        if((d==2) && (an[2]>=1)) cate++;
        else if((d==3) && (an[3]>=1)) cate++;
        else if((d==4) && (an[2]>=2)) cate++;
        else if((d==5) && (an[5]>=1)) cate++;
        else if((d==6) && (an[2]>=1) && (an[3]>=1)) cate++;
        if(i==mijl) cate*=2;
    }        
    printf("%d\n",cate);
    return 0;
}