[Twelve provinces exam 2019] cheat divided over the sample

Portal

  This question is a cancer problem, he spent a blogger \ (\ text {1day} \ ) to independently solve \ (16 \) sub-tasks. Here we come to the question.

subtask 1-3:1_998244353

  This observation is not difficult to obtain data required \ (the X-19 ^ \ BMOD 998 244 353 \) , you can directly engage. Noting possible \ (X \) is very large, according to Fermat's little theorem \ (. 1-X ^ {P} \ equiv. 1 \ PMOD P \) , we need to read the modulo .

subtask 4:1?

  Observations and tips tells us: still seeking \ (the X-19 ^ \) , but do not know modulus. It found that the maximum value of the output file in the \ (10 ^ 6 \) or so, we take the first direct input explosion test search, finally able to find out \ (P = 1,145,141 \) .

subtask 5:1?+

  This is an enhanced version of the former, the modulus was found in \ (5 \ times 10 ^ { 18} \) or so, the bad violent. How to do it? I have had a number of rows of the input sequence, found two input \ (X \) of the difference \ (2 \) , so I found these two groups corresponding output obtained: \ (19 ^ {264 708 066} \ equiv 1996649514996338529 \ pmod P \) and \ (. 19 264 708 068 ^ {} \ equiv 1,589,589,654,696,467,295 \ PMOD P \) . That is multiplied by the above formula \ (2 19 ^ \) then modulo can be obtained following figures, then we get: \ (1996649514996338529 \ Times 19 ^ 2 \ equiv 1589589654696467295 \ PMOD P \) . Then rewrite this formula: \ (1996649514996338529 \ Times 361-nP = 1,589,589,654,696,467,295 \) , the constant to the right, found in the (long \ long \) \ can not be calculated within the range, I used \ (long \ double \) was calculated approximation. Then \ (P \) must be a factor of this number. Found \ (n-\) in \ (100 \) to \ (200 \)Or less, I will try in addition to the violence, taking into account the accuracy of the analog to digital in addition to turn out as well as \ (\ pm 1000 \) within a first set of input and output judgment a bit, finally found a modulus \ (P = 5211600617818708273 \) .

subtask 6-7:1wa_998244353

  The findings are not seeking \ (19 ^ x \ bmod 998244353 \) , and replaced with a \ (int \) step by step, and then take the modulo directly, ignoring the overflow problem. code show as below.

    x = (int)(x * 19) % 998244353;

  The first \ (6 \) points to a direct order to solve. The first \ (7 \) points that it is not OK, \ (the X-\) too. I began to think fast to rewrite power to solve, find work. While I do nothing, I let the first \ (6 \) points to go more than \ (10 ^ 6 \) group, we discovered the circulation section. Is from the \ (x = 55246 \) begins, every \ (45699 \) number of cycles of time. This reminds me of \ (\ text {Pollard-Rho } \) algorithm ring and \ (\ rho \) like. Of course, nothing to do with that algorithm, where you can directly use the above properties.

subtask 14-16:2g && 2g+

  I was done in front of \ (6 \) a \ (\ text {subtask} \ ) immediately after the do. The first two points, each time you ask three numbers \ (L \) , \ (R & lt \) , \ (P \) , requires \ (L \) to \ (R & lt \) in the mold \ (P \) under the original root. For the first \ (14 \) points, \ (P = 998 244 353 \) when, \ (\ varphi (P) = P-. 1 = 998 244 352 = 2 ^ {23 is} \ Times. 7 \ Times. 17 \) , because different only quality factor \ (3 \) a, in addition to the test can be directly determined whether the primitive root.

  For the first \ (15 \) points, \ (P = 13,123,111 \) , \ (\ varphi (P) = 13.12311 million = 2 ×. 3 ×. 5 ×. 7 ×. 11 × 13 is ×. 19 × 23 is \) , and determines the numbers up to \ (10 ^ 7 \) months, in addition to certainly try \ (\ text {T} \) , and we can use one of the other original primitive root out the root traversal. Here \ (G \) take \ (6 \) , since \ (g ^ t \) through all \ (\ varphi (P) \ ) th and \ (P \) prime number, and if and only if \ (T \) and \ (\ varphi (P) \ ) prime time \ (g ^ t \) is a primitive root. So we use \ (\ varphi (P) \ ) prime factor of \ (T \) modulo judgment. After traversing the primary root to find it all.

  For the first (16 \) \ points, the last group of unknown query module, according to the data we reverse primitive root modulo. Suggest that the \ (10 ^ 9 \) to \ (2 \ times 10 ^ 9 \) between and is a prime, we find a one, then the original root by means of conventional trial division can determine the number of viable quality. \ (\ FORALL G \) , if the \ (G ^ \ P-FRAC. 1} {2} {\ Not \ equiv. 1 \ PMOD P \) , then \ (P \) is very likely that we are looking modulus. My computer ran about \ (5min \) found a number \ (P = 1515343657 \) , then test found to be correct. It is found by using the primitive root and \ (P = 998244353 \) as the method. So solved.

subtask 8-10:2p

  We claim Analyzing \ (L \) to (\ R & lt) \ Each number is not a prime number within. May be linear small screen, the range may be slightly larger mesh number and then use this fractional part to screen \ (L \) to \ (R & lt \) , but directly on I \ (\ text {Miller-Rabin } \) , the algorithm may be (\ log n \) \ testing a number is not a prime number over the time, the correct rate \ (. 1 - (\ FRAC {. 1} {. 4}) ^ S \) , \ (S \) is the number of tests. This problem seems to choose twenty-three number on it, so constant small versatile too.

subtask 11-13:2u

  Here let us screen out \ (l \) to \ (r \) Mobius function.

  As above, we can screen out a small scale \ (\ mu \) before had lost two points. I did not think so, use the \ (\ text {Pollard-Rho } \) to screen out violent break down before then \ (10 ^ 6 \) a Mobius function, we found the second point are too stubborn. How to do it? The maximum number of \ (10 ^ {18} \) , I think if screening out \ (10 ^ 6 \) primes within then used primes to screen these numbers, the remaining prime factor of a certain number of \ (\ GEQ 10 ^ 6 \) , so the rest of the number at most only two prime factors, namely the following three conditions:

  First, the remaining number is a prime number, with \ (\ text {Miller-Rabin } \) sentenced at this time would \ (\ mu \) multiplied by \ (--1 \) ;

  Second, the remaining number is the product of two different prime numbers; negatives make a positive, this time not to \ (\ mu \) to generate contributions;

  Third, the remaining number is the square of a prime number. This time \ (\ mu \) to \ (0 \) .

  Then treated with less than \ (10 ^ 6 \) is the number of these factors to screen, and maintains \ (\ MU \) , can be solved.

  But to pay attention to the number of removed squares containing factor. Finally, the solution of this question would be finished.

\\ AC代码
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i, a, b) for (register int i = a, end = b; i <= end; i++)
#define repd(i, a, b) for (register int i = a, end = b; i >= end; i--)
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)
#define INF (1<<30)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define fst first
#define snd second
#define pii pair<int, int>

char s[15];

namespace _998244353 {
    int N;
    ull P;
    ull v;

    inline void inc(ull &a, ull b, ull p) {
        a += b;
        if (a >= p) a -= p;
    }

    ull Mult(ull a, ull b, ull p) {
        ull res = 0;
        for (ull k = a; b; inc(k, k, p), b >>= 1)
            if (b & 1) inc(res, k, p);
        return res;
    }

    ull qpow(ull a, ull b, ull p) {
        ull res = 1;
        for (register ull k = a; b; k = Mult(k, k, p), b >>= 1)
        if (b & 1) res = Mult(res, k, p);
        return res;
    }

    inline ull read() {
        ull w = 0; char c;
        while (!isdigit(c = getchar())) ;
        while (isdigit(c)) w = ((w << 3) + (w << 1) + (c ^ 48)) % (P-1), c = getchar();
        return w;
    }
    void main(ull orz) {
        P = orz;
        scanf("%d", &N);
        rep(i, 1, N) {
            v = read();
            printf("%llu\n", qpow(19, v, P));
        }
    }
}

namespace WA {
    int N;
    int ans[55246+45699+5];
    void main() {
        scanf("%d", &N);
        ans[0] = 1;
        rep(i, 1, 55246+45699) {
            ans[i] = (int)(ans[i-1]*19)%998244353;
        }
        rep(i, 1, N) {
            ll val;
            scanf("%lld", &val);
            if (val <= 55246+45699) printf("%d\n", ans[val]);
            else printf("%d\n", ans[(val-55246)%45699+55246]);
        }
    }
}

namespace GG {
    int qpow(int a, int b, int p) {
        int res = 1;
        for (register int k = a; b; k = (ll)k*k%p, b >>= 1)
            if (b & 1) res = (ll)res * k % p;
        return res;
    }
    void run1(int l, int r, int p) {
        if (p == 998244353) {
            rep(i, l, r) if (qpow(i, 499122176, 998244353) != 1 && qpow(i, 142606336, 998244353) != 1 && qpow(i, 58720256, 998244353) != 1) printf("g"); else printf(".");
        } else {
            rep(i, l, r) 
                if (qpow(i, 757671828, 1515343657) != 1 && qpow(i, 505114552, 1515343657) != 1 &&
                    qpow(i, 378552, 1515343657) != 1 && qpow(i, 96072, 1515343657) != 1) printf("g"); else printf(".");
        }
        puts("");
    }
    int st[13123120];
    void run2(int p) {
        memset(st, 0, sizeof(st));
        int g = 6, cnt = 0;
        do {
            cnt++;
            if (cnt % 2 && cnt % 3 && cnt % 5 && cnt % 7 && cnt % 11 && cnt % 13 && cnt % 19 && cnt % 23) st[g] = 1;
            g = g*6%p;
        } while (g != 6);
        rep(i, 1, 13123110) if (st[i]) printf("g"); else printf(".");
        puts("");
    }
}

namespace PP {
    inline ll Mult(ll a, ll b, ll p) {
        ll c = (ll)a*b - (ll)((ull)((long double)a*b/p)*p);
        return c < 0 ? c+p : ((ull)c >= (ull)p ? c-p : c);
    }

    ll qpow(ll a, ll b, ll p) {
        ll res = 1;
        for (register ll k = a; b; k = Mult(k, k, p), b >>= 1)
            if (b & 1) res = Mult(res, k, p);
        return res;
    }
    int test[10] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
    bool MR(ll P, int cnt = 10) {
        ll s = P-1; int t = 0;
        while (!(s & 1)) s >>= 1, t++;
        rep(i, 0, cnt-1) {
            if (P == test[i]) return true;
            if (test[i] > P) return false;
            ll a = qpow(test[i], s, P), nxt;
            rep(x, 1, t) {
                nxt = Mult(a, a, P);
                if (nxt == 1 && a != 1 && a != P-1) return false;
                a = nxt;
                if (a == 1) break;
            }
            if (a != 1) return false;
        }
        return true;
    }
    int N;
    void main() {
        scanf("%d", &N);
        while (N--) {
            ll l, r;
            scanf("%lld%lld", &l, &r);
            while (l <= r) {
                if (MR(l)) printf("p"); else printf(".");
                l++;
            }
            puts("");
        }
    }
}

namespace UU {
    int N;
    int check[1000005], p[100000];
    void init() {
        memset(check, 0, sizeof(check));
        p[0] = 0;
        rep(i, 2, 1000000) {
            if (!check[i]) p[++p[0]] = i;
            for (register int j = 1; j <= p[0] && i*p[j] <= 1000000; j++) {
                check[i*p[j]] = 1;
                if (!(i % p[j])) break;
            }
        }
    }
    ll frac[1000001], mu[1000001];
    bool issqr(ll x) {
        ll v = sqrt(x);
        if (v*v == x || (v-1)*(v-1)==x || (v+1)*(v+1)==x) return true;
        return false;
    }
#define cc(x) ((x) == 0 ? '0' : ((x) < 0 ? '-' : '+'))
    void main() {
        init();
        scanf("%d", &N);
        while (N--) {
            ll l, r;
            scanf("%lld%lld", &l, &r);
            rep(i, 0, r-l) mu[i] = frac[i] = 1;
            rep(i, 1, p[0]) {
                ll x = 1ll*p[i]*p[i], st = l-(l-1)%x-1+x;
                while (st <= r) {
                    mu[st-l] = 0; frac[st-l] = st; st += x;
                }
                x = p[i], st = l-(l-1)%x-1+x;
                while (st <= r) {
                    mu[st-l] = -mu[st-l];
                    if (frac[st-l] != st) frac[st-l] *= x;
                    st += x;
                }
            }
            for (register ll i = l; i <= r; i++) {
                ll val = i/frac[i-l];
                if (val == 1) printf("%c", cc(mu[i-l]));
                else if (PP::MR(val, 2)) printf("%c", cc(-mu[i-l]));
                else if (issqr(val)) printf("0");
                else printf("%c", cc(mu[i-l]));
            }
            puts("");
        }
    }
}

int main() {
    srand(time(0));
    scanf("%s", s);
    if (s[2] == '9') _998244353::main(998244353);
    if (s[1] == '?') {
        if (s[2] == '+') {
            _998244353::main(5211600617818708273ll);
        } else {
            _998244353::main(1145141);
        }
    }
    if (s[1] == 'w') {
        WA::main();
    }
    if (s[1] == 'g') {
        int l, r, p, N;
        if (s[2] == '?') {
            scanf("%d", &N);
            while (N--) {
                scanf("%d%d", &l, &r);
                if (N) scanf("%d", &p); else p = 1515343657;
                GG::run1(l, r, p);
            }
        } else {
            scanf("%d", &N);
            while (N--) {
                scanf("%d%d%d", &l, &r, &p);
                if (p == 998244353) GG::run1(l, r, p);
                else GG::run2(p);
            }
        }
    }
    if (s[1] == 'p') {
        PP::main();
    }
    if (s[1] == 'u') {
        UU::main();
    }

    return 0;
}

Guess you like

Origin www.cnblogs.com/ac-evil/p/11774865.html