/** * Compute the primitive part and the content of a modular multivariate * polynomial e \in Z_p[x_n][x_0, \ldots, x_{n-1}], i.e. e is considered * a polynomial in variables x_0, \ldots, x_{n-1} with coefficients being * modular polynomials Z_p[x_n] * @param e polynomial to operate on * @param pp primitive part of @a e, will be computed by this function * @param c content (in the sense described above) of @a e, will be * computed by this function * @param vars variables x_0, \ldots, x_{n-1}, x_n * @param p modulus */ void primpart_content(ex& pp, ex& c, ex e, const exvector& vars, const long p) { static const ex ex1(1); static const ex ex0(0); e = e.expand(); if (e.is_zero()) { pp = ex0; c = ex1; return; } exvector rest_vars = vars; rest_vars.pop_back(); ex_collect_t ec; collect_vargs(ec, e, rest_vars); if (ec.size() == 1) { // the input polynomial factorizes into // p_1(x_n) p_2(x_0, \ldots, x_{n-1}) c = ec.rbegin()->second; ec.rbegin()->second = ex1; pp = ex_collect_to_ex(ec, rest_vars).expand().smod(numeric(p)); return; } // Start from the leading coefficient (which is stored as a last // element of the terms array) auto i = ec.rbegin(); ex g = i->second; // there are at least two terms, so it's safe to... ++i; while (i != ec.rend() && !g.is_equal(ex1)) { g = euclid_gcd(i->second, g, vars.back(), p); ++i; } if (g.is_equal(ex1)) { pp = e; c = ex1; return; } exvector mainvar; mainvar.push_back(vars.back()); for (i = ec.rbegin(); i != ec.rend(); ++i) { ex tmp(0); if (!divide_in_z_p(i->second, g, tmp, mainvar, p)) throw std::logic_error(std::string(__func__) + ": bogus division failure"); i->second = tmp; } pp = ex_collect_to_ex(ec, rest_vars).expand().smod(numeric(p)); c = g; }
int main(int argc, char *argv[]) { int primes[168] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 }; int t = gint(); int i, a, b, gcd, ans, tmp; while(t--){ a = gint(); b = gint(); gcd = euclid_gcd(a, b); ans = 1; for (i = 0; i < 168; ++i) { if (gcd <= 1) break; tmp = 0; while(!(gcd % primes[i])){ gcd /= primes[i]; tmp++; } ans *= tmp + 1; } if(gcd > 1) ans *= 2; pint(ans); putchar_unlocked('\n'); } return 0; }