Lightoj 1340-story of Tomisu Ghost factorial factorization factor

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.