Cod sursa(job #1809064)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 18 noiembrie 2016 17:02:00
Problema Kperm Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

std::ifstream in ( "kperm.in"  );
std::ofstream out( "kperm.out" );

const int MOD = 666013;

int fct( int x ) {
    if( x == 0 ) { return 1; }
    else         { return ( x * 1LL * fct( x - 1 ) ) % MOD; } }

int pow( int x, int y ) {
    if( y == 0 ) { return 1; }
    else         { return ( x * 1LL * pow( x, y - 1 ) ) % MOD; } }

int main( int argc, const char *argv[] ) {
    std::ios::sync_with_stdio( false );
    int n, k, ans = 1; in >> n >> k;
    ans = ( ans * 1LL * fct(n % k) ) % MOD;
    ans = ( ans * 1LL * fct(k - n % k) ) % MOD;
    ans = ( ans * 1LL * pow(fct(n / k + 1), n % k) );
    ans = ( ans * 1LL * pow(fct(n / k), n - n % k) );
    out << ans * (n % 2) << std::endl;
    return 0; }