Cod sursa(job #1782521)

Utilizator giotoPopescu Ioan gioto Data 18 octombrie 2016 11:19:01
Problema Pascal Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <cstdio>
using namespace std;

short a[5000000];
int n, d;
inline int Legendre(int X, int IMP){
    int Sol = 0;
    long long L = IMP;
    while(L <= X){
        Sol = Sol + X / L;
        L *= (long long) IMP;
    }
    return Sol;
}
int main()
{
    freopen("pascal.in", "r", stdin);
    freopen("pascal.out", "w", stdout);
    scanf("%d%d", &n, &d);
    a[0] = 1;
    int Sol = 0;
    for(int j = 1; j < n ; ++j){
        int D2 = Legendre(n, 2) - Legendre(n - j, 2) - Legendre(j, 2);
        int D3 = Legendre(n, 3) - Legendre(n - j, 3) - Legendre(j, 3);
        if(d == 2){
            if(D2 > 0) ++Sol;
            continue ;
        }
        if(d == 3){
            if(D3 > 0) ++Sol;
            continue ;
        }
        if(d == 6){
            if(D2 && D3) ++ Sol;
            continue ;
        }
    }
    printf("%d", Sol);

}