Niu Ke summer vacation multi-school 200712J Easy Integration Fermat's little theorem / preprocessing / fast power

Link: https://ac.nowcoder.com/acm/contest/5666/J
Source : Niuke.com

question + ideas

Let you find the integral when n takes different values, and find it in the form of p/q. Ask you to change it into the form of p * q^(-1) mod 998244353. What is the result?
I didn't figure it out myself. The
solution is the
required p/ q is ( n! )^2 / ( ( 2 n+1 )! )
Then we actually require p
q^-1(mod 998244353),
then p is good for O1 query after preprocessing factorial.
What about the inverse of q?
According to Fermat's little theorem, if the modulus m is a prime number
q^(m-1) = 1 (mod m) ①
q^(m-2) = q ^(-1) (mod m) ②

Then q^(-1) = q ^ (m-2) (where m is the modulus)
means that the inverse of q modulus m is the (m-2) power of q (m is a prime number)

Because the Euler function should have been
q ^( phi(m) ) = 1 (mod m) ③
q ^( phi(m)-1) )= q ^(-1)(mod m) ④
So have you found
Euler ? Pull function ③ ④ is actually an extension of Fermat's little theorem ① ②

So here we have found the inverse of q,
that is, q^(m-2) Here we need to use fast power to find and remember to take the modulo
and then multiply to take the modulo.

code

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define inf 0x3f3f3f3f
#define sd(a) scanf("%d",&a)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define cl(a,b) memset(a,b,sizeof(a))
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dbg() printf("aaa\n")
using namespace std;
const int mod=998244353;
// (n!)^2/((2*n+1)!)
const int maxn=2e6+10;
int n;
ll j[maxn];
ll quick_pow(ll a,ll b){
    
    
    ll ans=1;
    while(b){
    
    
        if(b&1){
    
    
            ans=(ans*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return ans%mod;
}
void init(){
    
    
    //阶乘打表
    j[0]=1;
    for(ll i=1;i<=2e6+3;i++){
    
    
        j[i]=j[i-1]*i%mod;
    }
}
int main() {
    
    
    init();
	while(sd(n)!=EOF){
    
    
        ll p=quick_pow(j[n],2);
        ll q=j[2*n+1];
        ll q1=quick_pow(q,mod-2);
        printf("%lld\n",p*q1%mod);
    }
	return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326150590&siteId=291194637