Link: HDU 3641 treasure hunting
Question: X! % M = the smallest X in 0. M = A1 ^ B1 * A2 ^ B2 * A3 ^ b3 ....
Idea: Evaluate the remainder to 0 and think of division, that is, the set of denominator factors is a subset of the set of molecular factors. The factor also thinks that any integer can be divided into several prime numbers and multiplied.
Note: The question data is very big, and the answer is obtained in two points.
AC code:
# Include <stdio. h> # include <string. h> # define ll _ int64bool prime [210]; ll num [210]; // Number of prime factors in M void getprime () // Number of prime numbers in the table {int I, J; memset (Prime, true, sizeof prime); prime [0] = prime [1] = false; for (I = 2; I * I <= 110; I ++) {If (prime [I]) {for (j = I + I; j <= 110; j + = I) prime [J] = false ;}}} void CAL (ll a, LL B) // factorization prime factor {ll I, n = A; for (I = 2; I <= ;) {If (N % I = 0 & prime [I]) {n/= I; num [I] + = B;} elseI ++ ;}} ll find (Ll I, ll X) // X! The number of I in {ll ans = 0; while (x) {x/= I; ans + = x;} return ans;} bool OK (LL X) // {ll I; for (I = 1; I <= 100; I ++) {If (Num [I]) {ll temp = find (I, X ); if (Num [I]> temp) // The number of prime factors of the denominator is greater than that of the molecular weight factor. Return false;} return true;} ll bfind () // returns the result {ll ans = 0; ll left, right, mid; left = 0; right = LL (1) <62; while (left <= right) {mid = (left + right)> 1; if (OK (MID )) {ans = mid; // to get the minimum value. Right = mid-1;} elseleft = Mid + 1;} return ans;} int main () {int t, n, I; ll a, B; getprime (); while (scanf ("% d", & T )! = EOF) {While (t --) {memset (Num, 0, sizeof num); scanf ("% d", & N); for (I = 0; I <n; I ++) {scanf ("% i64d % i64d", & A, & B); CAL (a, B);} ll ans = 0; ans = bfind (); printf ("% i64d \ n", ANS) ;}} return 0 ;}