Esempio n. 1
0
Int divide(Int a, Int b, Int m) {
	Int g = gcd(a, m);
	if (b%g != 0)
		throw no_solution();
	Int x, y;
	extgcd(a, m, x, y);
	assert(a*x+m*y == gcd(a,m));
	Int n = x*b/g;
	Int dn = m/g;
	n -= n/dn*dn;
	if (n < 0)
		n += dn;
	return n;
}
Esempio n. 2
0
void solve(int a, int b, int c)
{
	A = a; B = b; C = c;
	p = 0;
	dfs(0, 0);
	if(p) {
		for(int i = 0; i < p; i++) switch(path[i]) {
			case 1 : fill_1(); break;
			case 2 : fill_2(); break;
			case 3 : empty_1(); break;
			case 4 : empty_2(); break;
			case 5 : pour_1_to_2(); break;
			case 6 : pour_2_to_1(); break;
		} verify();
	} else no_solution();
	memset(vis, 0, sizeof(vis));
}