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);
       }
    }
 }
Пример #2
0
Файл: dtm.c Проект: brogar/pykdb
/* 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;
}
Пример #4
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;
}                                                                                
Пример #5
0
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);
}
Пример #6
0
 bint &operator%=(const bint &v) {
     return *this = divmod(*this, v).second;
 }
Пример #7
0
 bint &operator/=(const bint &v) {
     return *this = divmod(*this, v).first;
 }
Пример #8
0
 bint operator%(const bint &v)const {
     return divmod(*this, v).second;
 }
Пример #9
0
 bint operator/(const bint &v)const {
     return divmod(*this, v).first;
 }
Пример #10
0
	BigInteger operator % (const BigInteger &divider) const {
		return divmod(divider).second;
	}
Пример #11
0
	BigInteger operator / (const BigInteger &divider) const {
		return divmod(divider).first;
	}
Пример #12
0
 Array* Float::divmod(STATE, Integer* other) {
   return divmod(state, Float::coerce(state, other));
 }
Пример #13
0
inline tuple2<double, double> *divmod(__ss_int a, double b) { return divmod((double)a, b); }
Пример #14
0
inline tuple2<double, double> *divmod(double a, __ss_int b) { return divmod(a, (double)b); }