Cod sursa(job #1289192)

Utilizator stefanzzzStefan Popa stefanzzz Data 9 decembrie 2014 17:15:56
Problema Pascal Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <fstream>
using namespace std;
ifstream f("pascal.in");
ofstream g("pascal.out");

int n, d, p2, p3, p5, sol, x;

int main()
{
    int i, j;

    f >> n >> d;

    for(i = 1; i < n; i++){
        x = n - i + 1;
        while(x % 2 == 0){
            p2++;
            x /= 2;
        }
        while(x % 3 == 0 ){
            p3++;
            x /= 3;
        }
        while(x % 5 == 0 ){
            p5++;
            x /= 5;
        }

        x = i;
        while(x % 2 == 0){
            p2--;
            x /= 2;
        }
        while(x % 3 == 0 ){
            p3--;
            x /= 3;
        }
        while(x % 5 == 0 ){
            p5--;
            x /= 5;
        }

        switch(d){
        case 2:
            if(p2 > 0)
                sol++;
            break;
        case 3:
            if(p3 > 0)
                sol++;
            break;
        case 4:
            if(p2 >= 2)
                sol++;
            break;
        case 5:
            if(p5 > 0)
                sol++;
            break;
        default:
            if(p2 > 0 && p3 > 0)
                sol++;
        }
    }

    g << sol << '\n';

    f.close();
    g.close();
    return 0;
}