void test1(unsigned sx,unsigned sy) { DrawAlgo::LineDriverBase<unsigned> driver(sx,sy); unsigned x=0; unsigned y=0; for(unsigned count=sx; count ;count--) { y+=driver.step(); x++; UIntFunc<unsigned>::Mul mul(x,sy); UIntFunc<unsigned>::DivMod divmod(mul.hi,mul.lo,sx); unsigned z=divmod.div; if( divmod.mod>sx/2 ) z++; if( y!=z ) { Printf(Exception,"1 failed #; #;",sx,sy); } } }
/* One step of a mixed-radix conversion. A "hi" unit is equivalent to * factor "lo" units. factor must be > 0. If *lo is less than 0, or * at least factor, enough of *lo is converted into "hi" units so that * 0 <= *lo < factor. The input values must be such that int overflow * is impossible. */ /*static*/ void normalize_pair(int *hi, int *lo, int factor) { assert(factor > 0); assert(lo != hi); if (*lo < 0 || *lo >= factor) { const int num_hi = divmod(*lo, factor, lo); const int new_hi = *hi + num_hi; assert(! SIGNED_ADD_OVERFLOWED(new_hi, *hi, num_hi)); *hi = new_hi; } assert(0 <= *lo && *lo < factor); }
int main() { scanf("%d%d%d", &n, &k, &mod); if (k > n) { puts("0"); return 0; } int nf = fact(n), kf = fact(k), nkf = fact(n - k); // fprintf(stderr, "facts: %d %d %d\n", nf, kf, nkf); printf("%d\n", divmod(nf, (kf * 1LL * nkf * 1LL) % mod)); return 0; }
std::string encode_base58(const data_chunk& unencoded_data) { std::string encoded_data; // Expected size increase from base58 conversion is approximately 137% // use 138% to be safe encoded_data.reserve((unencoded_data.size() - 1) * 138 / 100 + 1); // Convert big endian data to little endian // Extra zero at the end make sure bignum will interpret // as a positive number data_chunk tmp_data(unencoded_data.size() + 1, 0); std::reverse_copy(unencoded_data.begin(), unencoded_data.end(), tmp_data.begin()); big_number long_value; long_value.set_data(tmp_data); while (long_value > 0) { auto result = divmod(long_value, 58); long_value = result.first; size_t remainder = result.second.uint32(); encoded_data += base58_chars[remainder]; } // Leading zeroes encoded as base58 zeros for (const uint8_t unencoded_byte: unencoded_data) { if (unencoded_byte != 0) break; encoded_data += base58_chars[0]; } // Convert little endian std::string to big endian reverse(encoded_data.begin(), encoded_data.end()); return encoded_data; }
void kputn(unsigned long long x, int radix, int pad, char padchar) { char b[65]; char* r = b + 64; char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; unsigned int remainder; if (radix < 2 || radix > 36) { return; } *r-- = 0; do { x = divmod(x, radix, &remainder); *r-- = digits[remainder]; pad--; } while (x > 0); while (pad-- > 0) { console_putchar_ansi(padchar); } console_writestring(r + 1); }
bint &operator%=(const bint &v) { return *this = divmod(*this, v).second; }
bint &operator/=(const bint &v) { return *this = divmod(*this, v).first; }
bint operator%(const bint &v)const { return divmod(*this, v).second; }
bint operator/(const bint &v)const { return divmod(*this, v).first; }
BigInteger operator % (const BigInteger ÷r) const { return divmod(divider).second; }
BigInteger operator / (const BigInteger ÷r) const { return divmod(divider).first; }
Array* Float::divmod(STATE, Integer* other) { return divmod(state, Float::coerce(state, other)); }
inline tuple2<double, double> *divmod(__ss_int a, double b) { return divmod((double)a, b); }
inline tuple2<double, double> *divmod(double a, __ss_int b) { return divmod(a, (double)b); }