Cod sursa(job #2457245)

Utilizator MaraPMara P MaraP Data 16 septembrie 2019 23:11:20
Problema Pascal Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("pascal.in");

int r,d;
int powers2[5000001],powers3[5000001],powers5[5000001];
int current_power_2=0,current_power_3=0,current_power_5=0;
int nr_solutions=0;
void generate_powers()
{
    for(int i=1;i<=r;i++)
    {
        if(!(i%2))
            powers2[i]=1+powers2[i/2];
        if(!(i%3))
            powers3[i]=1+powers3[i/3];
        if(!(i%5))
            powers5[i]=1+powers5[i/5];
    }
}
void solve()
{
    fin>>r>>d;
    generate_powers();
    for(int i=1;i<=r;i++)
    {
        current_power_2+=powers2[r-i+1]-powers2[i];
        current_power_3+=powers3[r-i+1]-powers3[i];
        current_power_5+=powers5[r-i+1]-powers5[i];
        if(d==2&&current_power_2>0)
            nr_solutions++;
        if(d==3&&current_power_3>0)
            nr_solutions++;
        if(d==4&&current_power_2>1)
            nr_solutions++;
        if(d==5&&current_power_5>0)
            nr_solutions++;
        if(d==6&&current_power_2>0&&current_power_3>0)
            nr_solutions++;
    }
    fout<<nr_solutions;
}
int main()
{
    solve();
    return 0;
}