Cod sursa(job #1479287)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 30 august 2015 23:01:28
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int NMax = 5e6 + 5;

int a[NMax], b[NMax], c[NMax];

inline void preproc(int r){
    for(int i = 1; i <= r; i++){
        if(i % 2 == 0){
            a[i] = a[i / 2] + 1;
        }
        if(i % 3 == 0){
            b[i] = b[i / 3] + 1;
        }
        if(i % 5 == 0){
            c[i] = c[i / 5] + 1;
        }
    }
}

int main(){
    int r, d, sol, pow_2, pow_3, pow_5;
    fin >> r >> d;
    preproc(r);
    sol = pow_2 = pow_3 = pow_5 = 0;
    for(int i = 1; i <= r; i++){
        pow_2 += a[r - i + 1] - a[i];
        pow_3 += b[r - i + 1] - b[i];
        pow_5 += c[r - i + 1] - c[i];
        if(d == 2 && pow_2 > 0) sol++;
        if(d == 3 && pow_3 > 0) sol++;
        if(d == 4 && pow_2 > 1) sol++;
        if(d == 5 && pow_5 > 0) sol++;
        if(d == 6 && pow_2 > 0 && pow_3 > 0) sol++;
    }
    fout << sol;
    return 0;
}