Cod sursa(job #2015166)

Utilizator NToniBoSSNicolae Tonitza NToniBoSS Data 25 august 2017 13:35:34
Problema Pascal Scor 40
Compilator c Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>
#include <stdlib.h>
int st[5000001],dr[5000001];
int main()
{
    int r,d,ct=0,i,x,nr,nr1,j,nr2;
    freopen("pascal.in","r",stdin);
    freopen("pascal.out","w",stdout);
    scanf("%d%d",&r,&d);
    if(d==4) d=2,ct=1;
    if(d==6) d=3;
    for(i=1; i<=r; i++){
        x=i;
        while(x%d==0)
            st[i]++,dr[i]++,x/=d;}
    for(i=1; i<=r; i++)
        st[i]=st[i-1]+st[i];
    for(i=r-1; i>0; i--)
        dr[i]=dr[i+1]+dr[i];
    nr=0;
    for(i=1; i<=r; i++)
    {
        nr1=dr[i+1];
        nr2=st[r-i];
        if(ct==1) nr1/=2,nr2/=2;
        if(nr1-nr2>0) nr++;
    }
    printf("%d\n",nr);

    return 0;
}