http://www.lightoj.com/volume_showproblem.php?problem=1340
Test Instructions: ask n! At least a T suffix of zero in the B-binary, the largest B.
idea: It is easy to think of a number by which the maximum exponent can be obtained by factorization factor. So the key is to get n!. The index of the factor of the element, find all the elements of the exponent greater than T, and then remove the index T, the remaining number is the largest B. When the factorial is decomposed, n is continuously removed from the prime number p, until n is 0 o'clock, at this time quotient and that is the exponent of the element factor.
/** @Date: 2016-11-30-19.35 * @Author: Lweleth ([email protected]) * @Link: https://github.com/* @Versi On: */#include <bits/stdc++.h> #define LL long long#define PII pair#define MP (x, y) Make_pair ((x), (y)) #define FI fir St#define se second#define PB (x) push_back ((x)) #define MMG (x) memset ((x), -1,sizeof (x)) #define MMF (x) memset ((x), 0, sizeof (x)) #define MMI (x) memset ((x), INF, sizeof (x)) using namespace Std;const int INF = 0x3f3f3f3f;const int N = 1e5+2000; const int mod = 10000019; LL pri[n];int C = 0;bool vis[n];void prime () {for (int i = 2; i < N; i++) {if (!vis[i]) { for (int j = i + i; j < N; j+= i) {if (!vis[j]) vis[j] = 1; } pri[c++] = i; }}}ll Fpow (ll A, ll N) {ll r = 1; while (n > 0) {if (n & 1) R = R * a% mod; A = a * a% mod; n >>= 1; } return R;} int main () {prime (); int T; IntCNT = 0; Cin >> T; while (t--) {LL n; LL R; CIN >> N >> R; LL ans = 1; for (int i = 0; i < c && Pri[i] <= N; i++) {LL t = N; LL ct = 0; while (t) {ct + = t/pri[i]; T/= Pri[i]; } if (CT >= r) ans = ans * FPOW (pri[i], ct/r)% MoD; if (CT < R) break; } if (ans = = 1) printf ("Case%d: -1\n", ++cnt); else printf ("Case%d:%d\n", ++cnt, ans); } return 0;}
Lightoj 1340-story of Tomisu Ghost factorial factorization factor