Cod sursa(job #2500320)

Utilizator alexradu04Radu Alexandru alexradu04 Data 27 noiembrie 2019 18:42:28
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("pascal.in");
ofstream fout("pascal.out");

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;
}