Cod sursa(job #3154947)

Utilizator DumitrescuADumitrescuA DumitrescuA Data 6 octombrie 2023 22:25:30
Problema Pascal Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <fstream>
using namespace std;

ifstream cin("pascal.in");
ofstream cout("pascal.out");

#define INF 100000000

int min_d(int n,int d){
    int j,d1,min1,cnt;
    min1=INF;
    j=2;
    while(n>1){
        if(n%j==0){
            d1=j;cnt=0;
            while(d1<=n){
                cnt+=n/d1;
                d1*=j;
            }
            min1=min(min1,cnt);
            while(n%j==0)
                n/=j;
        }
        j++;
    }
    return min1;
}

int max_d(int n,int d){
    int j,d1,min1,cnt;
    min1=-1;
    j=2;
    while(n>1){
        if(n%j==0){
            d1=j;cnt=0;
            while(d1<=n){
                cnt+=n/d1;
                d1*=j;
            }
            min1=max(min1,cnt);
            while(n%j==0)
                n/=j;
        }
        j++;
    }
    return min1;
}


int main()
{
    int n,d,cnt,rasp=0,i;
    cin>>n>>d;
    cnt=min_d(n,d);
    for(i=0;i<n;i++){
        if(cnt>max_d(n-i,d)-max_d(i,d))
            rasp++;
    }
    cout<<rasp;
    return 0;
}