Cod sursa(job #3157523)

Utilizator iulia_morariuIulia Ela Morariu iulia_morariu Data 15 octombrie 2023 17:43:26
Problema Pascal Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <bits/stdc++.h>

using namespace std;

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

pair< int, pair<int, int> > c[5000001];

int main(){
    cin.tie(0);ios::sync_with_stdio(0);

    //1.
    int r, d;
    int c2 = 0, c3 = 0, c5 = 0;

    //2.
    fin >> r >> d;

    //3.
    for(int i = 1; i <= 5000000; i++){
        c2 = 0, c3 = 0, c5 = 0;
        int i1 = i;

        while(i1 % 2 == 0){
            c2++;
            i1 /= 2;
        }

        while(i1 % 3 == 0){
            c3++;
            i1 /= 3;
        }

        while(i1 % 5 == 0){
            c5++;
            i1 /= 5;
        }


        c[i].first = c2;
        c[i].second.first = c3;
        c[i].second.second = c5;
    }
/*
    for(int i = 1; i <= 10; i++){
        cout << i << " : " << c[i].first << " " << c[i].second.first << " " << c[i].second.second << endl;
    }
*/
    for(int i = 2; i <= 5000000; i++){
        c[i].first += c[i - 1].first;
        c[i].second.first += c[i - 1].second.first;
        c[i].second.second += c[i - 1].second.second;
    }

    int cnt = 0;
    for(int i = 0; i <= r; i++){
        c2 = c[r].first - c[i].first - c[r - i].first;
        c3 = c[r].second.first - c[i].second.first - c[r - i].second.first;
        c5 = c[r].second.second - c[i].second.second - c[r - i].second.second;

        //cout << "i = " << i << " c2 = " << c2 << " c3 = " << c3 << " c5 = " << c5 << endl;

        if(d == 2 && c2 > 0) cnt++;
        else if(d == 3 && c3 > 0) cnt++;
        else if(d == 4 && c2 > 1) cnt++;
        else if(d == 5 && c5 > 0) cnt++;
        else if(d == 6 && c2 > 0 && c3 > 0) cnt++;
    }
    fout << cnt << endl;



    return 0;
}