Cod sursa(job #2115613)

Utilizator andreicoman299Coman Andrei andreicoman299 Data 26 ianuarie 2018 22:18:57
Problema Pascal Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <bits/stdc++.h>
#define MAXN 5000000

int two[1 + MAXN], three[1 + MAXN], five[1 + MAXN];
int main(){
    FILE*fi,*fo;
    fi = fopen("pascal.in","r");
    fo = fopen("pascal.out","w");

    int r, d;
    fscanf(fi,"%d%d", &r, &d);
    for(int i = 1; i <= r; i++){
        int x = i;
        two[i] = two[i - 1];
        while(x % 2 == 0){
            two[i]++;
            x /= 2;
        }

        three[i] = three[i - 1];
        while(x % 3 == 0){
            three[i]++;
            x /= 3;
        }

        five[i] = five[i - 1];
        while(x % 5 == 0){
            five[i]++;
            x /= 5;
        }
    }

    int con = 0;
    for(int i = 0; i <= r; i++){
        int a = two[r] - two[i] - two[r - i];
        int b = three[r] - three[i] - three[r - i];
        int c = five[r] - five[i] - five[r - i];
        if(d == 2 && a >= 1) con++;
        else if(d == 3 && b >= 1) con++;
        else if(d == 4 && a >= 2) con++;
        else if(d == 5 && c >= 1) con++;
        else if(d == 6 && a >= 1 && b >= 1) con++;
    }
    fprintf(fo,"%d", con);

    fclose(fi);
    fclose(fo);
    return 0;
}