Cod sursa(job #3241039)

Utilizator AndrijaMladAndrija Mladenovikj AndrijaMlad Data 25 august 2024 10:47:48
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <bits/stdc++.h>

using namespace std;

const int maxn=5e6+10;
const int mod=998244353;
const int logn=61;

int pw2[maxn];
int pw3[maxn];
int pw5[maxn];

signed main()
{
    freopen("pascal.in","r",stdin);
    freopen("pascal.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,d;
    cin>>n>>d;
    pw2[0]=pw3[0]=pw5[0]=0;
    for(int i=1;i<=n;i++)
    {
        if(i%2==0)
        {
            pw2[i]+=(1+pw2[i/2]);
        }
        if(i%3==0)
        {
            pw3[i]+=(1+pw3[i/3]);
        }
        if(i%5==0)
        {
            pw5[i]+=(1+pw5[i/5]);
        }
    }
    for(int i=1;i<=n;i++)
    {
        pw2[i]+=pw2[i-1];
        pw3[i]+=pw3[i-1];
        pw5[i]+=pw5[i-1];
    }
    ///cout<<pw2[2]<<endl;
    int ans=0;
    for(int j=0;j<n;j++)
    {
        int c2=pw2[n]-pw2[j]-pw2[n-j];
        int c3=pw3[n]-pw3[j]-pw3[n-j];
        int c5=pw5[n]-pw5[j]-pw5[n-j];
        if(d==2)
        {
            if(c2>0)
            {
                ans++;
            }
        }
        if(d==3)
        {
            if(c3>0)
            {
                ans++;
            }
        }
        if(d==4)
        {
            if(c2>=2)
            {
                ans++;
            }
        }
        if(d==5)
        {
            if(c5>0)
            {
                ans++;
            }
        }
        if(d==6)
        {
            if(c2>0 && c3>0)ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}