Cod sursa(job #1411388)

Utilizator tudorcomanTudor Coman tudorcoman Data 31 martie 2015 18:03:43
Problema Kperm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb


#include <fstream>
using namespace std;

const int MOD = 666013;
const char IN[] = "kperm.in";
const char OUT[] = "kperm.out";

int main(int argc, const char * argv[]) {
    
    ifstream fi (IN);
    ofstream fo (OUT);
    
    int N,K;
    fi >> N >> K; fi.close();
    
    long long int ANS = 1;
    
    if (!(K & 1)) fo << 0;
    
    else
    {
        int cat = N / K, rest = N % K, a,b;
        
        a = b = 1;
        
        for (int i = 1; i <= cat; ++i)
            a = (a * i) % MOD;
        b = ( a * (cat + 1) ) % MOD;
        
        
        for (int i=1; i <= rest; ++i)
            ANS = (ANS * i) % MOD, ANS = (ANS * b) % MOD;
        
        for (int i=1; i <= K - rest; ++i)
            ANS = (ANS * i) % MOD, ANS = (ANS * a) % MOD;
        
        fo << ANS;
        
        
    }
    
    fo << endl;
    fo.close();
    return 0;
}