Cod sursa(job #2281094)

Utilizator skoda888Alexandru Robert skoda888 Data 11 noiembrie 2018 16:11:15
Problema Pascal Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.5 kb

#include <iostream>
#include <fstream>
#include <cmath>

int main()
{
    std::ifstream in("pascal.in");
    std::ofstream out("pascal.out");

    //citire
    long long R;
    int D;
    in >> R >> D;

    int doi[R + 1] = {}, trei[R + 1] = {}, cinci[R + 1] = {};
    for(int i = 2; i <= R; ++i){
        if(D == 2 || D == 4 || D == 6){
            int p = 2;
            while(p <= i){
               doi[i] += i / p;
               p *= 2;
            }
        }

        if(D == 3 || D == 6){
            int p = 3;
            while(p <= i){
               trei[i] += i / p;
               p *= 3;
            }
        }

        if(D == 5){
            int p = 5;
            while(p <= i){
               cinci[i] += i / p;
               p *= 5;
            }
        }
    }

    int k = 0;
    for(int j = 0; j < R / 2; ++j){
        if(D == 2){
            int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
            if(comb2 > 0) k += 2;
        }
        else if(D == 4){
            int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
            if(comb2 > 1) k += 2;
        }
        else if(D == 3){
            int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
            if(comb3 > 0) k += 2;
        }
        else if(D == 6){
            int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
            int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
            if(comb3 > 0 && comb2 > 0) k += 2;
        }

        else{
            int comb5 = std::abs(cinci[R] - cinci[R - j] - cinci[j]);
            if(comb5 > 0) k += 2;
        }
   }

        int j = R / 2;
        int init_k = k;
        if(D == 2){
            int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
            if(comb2 > 0) ++k;
        }
        else if(D == 4){
            int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
            if(comb2 > 1) ++k;
        }
        else if(D == 3){
            int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
            if(comb3 > 0) ++k;
        }
        else if(D == 6){
            int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
            int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
            if(comb3 > 0 && comb2 > 0) k += 2;
        }

        else{
            int comb5 = std::abs(cinci[R] - cinci[R - j] - cinci[j]);
            if(comb5 > 0) k += 2;
        }

        if(k > init_k && R % 2 == 1){
            ++k;
        }

    out << k;
    return 0;
}