2019 Multi-University Training Contest 3 - 1006 - Fansblog - hit the table - Violence

http://acm.hdu.edu.cn/showproblem.php?pid=6608

Meaning of the questions: to a large prime number P (less than 1e14), seeking smaller than its largest prime number Q (looks like there is a guarantee, anyway, I did not sentence does not exist), find the Q value modP!.

A beginning that is what immortal question, but how the audience are green an instantaneous feeling intelligence insulted. Like a lot of what the weird nature, are not very clear, then teammate cards 1007, when I called to find ans P looked at the table. Found that when PQ = 2 is ans = 1? ? ?

Then make a (P-2)!% P table, we found a small data this way before, like this estimate is true.

So consider how to find the Q, first affirmed the sentence out special P = 3, then Q must be an odd number.

Consider the complexity of violence find Q: First of all prime number theorem (or directly hit the table out 1e7 know) obtained according to the number of prime numbers probably 6e5 like this, verify that Q is prime circle of violence.

If Q is not a prime number, in extreme cases, is the product of two different prime numbers, then the number of such distribution should be great.

The following code can play such extreme composite number:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e7;

int pri[MAXN + 5], pritop;
bool notpri[MAXN + 5];
//pritop从1开始计数

void sieve(int n) {
    notpri[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!notpri[i])
            pri[++pritop] = i;
        for(int j = 1; j <= pritop && i * pri[j] <= n; j++) {
            notpri[i * pri[j]] = 1;
            if(i % pri[j] == 0)
                break;
        }
    }
    printf("ptop=%d\n", pritop);
}

vector<ll> H;

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    sieve(MAXN);
    for(int i = pritop; i >= pritop - 100; --i) {
        for(int j = i - 1; j >= i - 1 - 100; --j) {
            H.push_back(1ll*pri[i]*pri[j]);
        }
    }
    sort(H.begin(),H.end(),greater<ll>());
    for(int i=0;i<100;++i){
        printf("i=%d num=%lld\n",i+1,H[i]);
    }
    return 0;
}

We can see the gap between such extremes composite number is very large! The difference between the two 1e6 more!

ptop=664579
i=1 num=99999640000243
i=2 num=99999620000261
i=3 num=99999440000783
i=4 num=99999340000513
i=5 num=99999280000567
i=6 num=99999220000621
i=7 num=99999200000639
i=8 num=99999160001539
i=9 num=99999140001653
i=10 num=99999100001701
i=11 num=99999080001827
i=12 num=99999040001863
i=13 num=99999020002001
i=14 num=99999020001917
i=15 num=99999000002059
i=16 num=99998980000837
i=17 num=99998920000891
i=18 num=99998800003591
i=19 num=99998800002511
i=20 num=99998800000999

If the product of three distinct primes also Fangshanglai is not substantially reduced to where.

So you can guess, the number of the number of extreme violence in a co-verification process, before finding Q, is not expected to encounter more than 10, not even over five. Other prime factors of the number of co sentenced to easily cut off, almost just a fraction Q of violence sentence, is negligible.

Interval between prime numbers, then the total number of prime numbers, the average is 32 appears a course in relatively large time interval far, but I guess no more than 1000, 1000 the number of consecutive prime numbers are not, I hope Gangster give an estimate?

So probably a violent sentence Q, the worst case is about 6e6, consider T is relatively small (behind the title change to change the face of negative feedback), direct violence.

The result of the speculation (Wilson's Theorem) :( P-2)! = 1 mod P, two each on both sides by one inverse element can also be transferred to the next number, up to 1000 transfer, 1000log1e14 fraction is, negligible.

Finally, be careful overflow, we changed a lot of places, take the inverse of places have changed __int128 power but which did not change fast, resulting in an overflow WA1, too pit.

In fact, just using multiplication modulo, you can quickly multiply.

Guess you like

Origin www.cnblogs.com/Yinku/p/11267358.html