luogu P5285 [十二省联考2019]骗分过样例

传送门

你管这玩意叫传统题?

1_998244353通过样例可以发现就是(19^amod 998244353),然后如果读入的数过大,根据费马小定理,那个读进来的数对(998244352)取模就行了

1?1?+就是(19^amod ?),前者可以暴力求出,后者比较牛皮,可以找到数据中的两个数(x,y(x<y)),并且(y-x)较小,然后可以知道(19^x,19^{y-x},19^y),因为(19^x*19^{y-x}equiv 19^ymod ?),然后可以求出模数的倍数,多搞几个,求一个gcd就好了

1wa_998244353(19^amod 998244353)然后爆了int,不过注意这个是每次乘19然后爆了int再模(998244353),所以直接快速幂,各种快速幂都是错的,然后打表可以发现在第5W多个数后面有个大约长度是5W的循环节,然后前面部分随便预处理即可

2p为输出区间内是质数的位置,因为区间长度(le 10^6),(Miller\_Rabin)即可

2u为输出区间内每个位置的(mu),显然可以质因数分解做,因为区间长度(le 10^6),(Pollard\_Rho)即可只有暴力的分...不过可以用(10^6)内的质数去筛掉每一个数的部分质因子,然后剩下的数要么是1,要么是(p,p^2)(pq(p,qin Prime,p eq q)),然后(p)直接(Miller\_Rabin),(p^2)直接用平方根判一下,剩下的就是(pq)

2g是区间内某个模数的原根,首先有做法,对(varphi(p))质因数分解(varphi(p)=p_1^{a_1}p_2^{a_2}...p_k^{a_k}),然后判断如果所有质因子(p_i),满足(a^{frac{varphi(p)}{p_i}} eq1),那就是原根,复杂度(O(nklog(p)));或者首先找到一个原根为(g),然后所有满足(gcd(i,varphi(p))=1)(i),对应的(g^i)都是原根,复杂度(O(plog(p)))

最后一个点的模数可以先筛出对应区间的质数,然后一个个判断,据说5h可以跑出来(大雾

// luogu-judger-enable-o2
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define ui unsigned 
#define LL long long
#define uLL unsigned long long
#define lbw __int128
#define db long double

using namespace std;
const int N=5e5+10;
LL rd()
{
    LL x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
int T;
char cc[100];
int a[13123111+10];
namespace ct1
{
    int mod=998244353;
    int rdd()
    {
        LL x=0,w=1;char ch=0;
        while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=((x<<3)+(x<<1)+(ch^48))%(mod-1);ch=getchar();}
        return x*w;
    }
    int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;} return an;}
    void wk()
    {
        while(T--)
            printf("%d
",fpow(19,rdd()));
    }
}
namespace ct2
{
    int mod=1145141;
    int rdd()
    {
        LL x=0,w=1;char ch=0;
        while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=((x<<3)+(x<<1)+(ch^48))%(mod-1);ch=getchar();}
        return x*w;
    }
    int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;} return an;}
    void wk()
    {
        while(T--)
            printf("%d
",fpow(19,rdd()));
    }
}
namespace ct3
{
    uLL mod=5211600617818708273;
    uLL mul(uLL a,uLL b){uLL an=0;while(b){if(b&1) an=(an+a)%mod;a=(a+a)%mod,b>>=1;} return an;}
    uLL fpow(uLL a,uLL b){
        uLL an=1;
        while(b){if(b&1) an=mul(an,a);
            a=mul(a,a),b>>=1;} return an;}
    int st[100010],a[100010],tp;
    bool cmp(int aa,int bb){return st[aa]<st[bb];}
    void wk()
    {
        while(T--)
            printf("%llu
",fpow(19,rd()));
    }
}
namespace ct4
{
    int mod=998244353;
    void wk()
    {
        a[0]=1;
        for(int i=1;i<=200000;++i) a[i]=(int)((ui)a[i-1]*(ui)19)%mod;
        while(T--)
        {
            scanf("%s",cc);
            int n=strlen(cc),x=0;
            bool fg=n>=6;
            if(fg)
            {
                for(int i=0;i<n;++i) x=(x*10+cc[i]-'0')%45699;
                x=100000+((x-100000+45699+45699+45699)%45699);
            }
            else for(int i=0;i<n;++i) x=x*10+cc[i]-'0';
            printf("%d
",a[x]);
        }
    }
}
namespace ct5
{
    int prm[5]={2,3,7,61,24251};
    //lbw mul(uLL a,uLL b,uLL mod){return ((a*b-mod*(uLL)((db)a/mod*b))%mod+mod)%mod;}
    lbw fpow(lbw a,lbw b,lbw mod){
        lbw an=1;while(b){if(b&1) an=an*a%mod;a=a*a%mod,b>>=1;} return an;}
    bool mlrb(uLL x)
    {
        if(x==2||x==3||x==5||x==7||x==11||x==13||x==17||x==61||x==24251) return 1;
        if(x==1||x%2==0||x%3==0||x%5==0||x%7==0||x%11==0||x%13==0||x%17==0||x%61==0||x%24251==0) return 0;
        for(int i=0;i<=4;++i)
        {
            int p=prm[i];
            for(lbw j=x-1;;j>>=1)
            {
                lbw a=fpow(p,j,x);
                if(a!=1&&a!=x-1) return 0;
                if(a==x-1||j&1) break;
            }
        }
        return 1;
    }
    void wk()
    {
        while(T--)
        {
            LL l=rd(),r=rd();
            for(LL i=l;i<=r;++i)
                putchar(mlrb(i)?'p':'.');
            puts("");
        }
    }
}
namespace ct6
{
    int prm[5]={2,3,7,61,24251};
    lbw fpow(lbw a,LL b,lbw mod){
        lbw an=1;while(b){if(b&1) an=an*a%mod;a=a*a%mod,b>>=1;} return an;}
    lbw st[100];
    bool mlrb(LL x)
    {
        if(x==2||x==3||x==7||x==24251) return 1;
        if(x==1||x%2==0||x%3==0||x%7==0||x%61==0||x%24251==0) return 0;
        for(int i=4;i<=4;++i)
        {
            int p=prm[i];
            LL j=x-1;
            while(j%2==0) j>>=1;
            int ts=1;
            st[ts]=fpow(p,j,x);
            while(j<x-1) j<<=1,++ts,st[ts]=st[ts-1]*st[ts-1]%x;
            for(int k=ts;k;--k)
            {
                if(st[k]!=1&&st[k]!=x-1) return 0;
                if(st[k]==x-1) break;
            }
        }
        return 1;
    }
    int p[1000010],tp;
    LL b[1000010];
    bool v[1000010];
    void wk()
    {
        while(T--)
        {
            LL l=rd(),r=rd();
            for(LL i=l;i<=r;++i) a[i-l+1]=1,b[i-l+1]=i,v[i-l+1]=0;
            int n=r-l+1;
            for(int i=2;i<=n;++i)
            {
                if(!v[i])
                {
                    p[++tp]=i;
                    for(LL j=(l+i-1)/i*i;j<=r;j+=i)
                    {
                        if((b[j-l+1]/i)%i==0) a[j-l+1]=0;
                        else a[j-l+1]=-a[j-l+1];
                        while(b[j-l+1]%i==0) b[j-l+1]/=i;
                    }
                }
                for(int j=1;j<=tp&&i*p[j]<=n;++j)
                {
                    v[i*p[j]]=1;
                    if(i%p[j]==0) break;
                }
            }
            for(int i=1;i<=n;++i)
            {
                if(!a[i]||b[i]==1) continue;
                if(mlrb(b[i])) a[i]=-a[i];
                else if((LL)sqrt(b[i])*(LL)sqrt(b[i])==b[i]) a[i]=0;
            }
            for(int i=1;i<=n;++i)
                putchar(!a[i]?'0':(a[i]>0?'+':'-'));
            puts("");
        }
    }
}
namespace ct7
{
    int gcd(int a,int b){return b?gcd(b,a%b):a;}
    int fpow(int a,int b,int mod){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;} return an;}
    int prm[30],tt,l,r,mod;
    void sov()
    {
        for(int i=l;i<=r;++i)
        {
            bool o=1;
            for(int j=1;o&&j<=tt;++j) o=fpow(i,(mod-1)/prm[j],mod)!=1;
            putchar(o?'g':'.');
        }
    }
    void wk()
    {
        while(T--)
        {
            l=rd(),r=rd();
            if(l>200000000)
            {
                mod=1515343657;
                tt=4;
                prm[1]=2,prm[2]=3,prm[3]=4003,prm[4]=15773;
                sov();
            }
            else if((mod=rd())==13123111)
            {
                tt=8;
                prm[1]=2,prm[2]=3,prm[3]=5,prm[4]=7,prm[5]=11,prm[6]=13,prm[7]=19,prm[8]=23;
                int g=6;
                for(int i=1,j=g;i<mod;++i,j=j*g%mod)
                    if(gcd(i,mod-1)==1) a[j]=1;
                for(int i=1;i<mod;++i) putchar(a[i]?'g':'.');
            }
            else
            {
                tt=3;
                prm[1]=2,prm[2]=7,prm[3]=17;
                sov();
            }
            puts("");
        }
    }
}

int main()
{
    //nctjxcxk
    scanf("%s",cc);
    T=rd();
    if(cc[1]=='_') ct1::wk();
    else if(cc[1]=='?'&&cc[2]==0) ct2::wk();
    else if(cc[1]=='?'&&cc[2]=='+') ct3::wk();
    else if(cc[1]=='w') ct4::wk();
    else if(cc[1]=='p') ct5::wk();
    else if(cc[1]=='u') ct6::wk();
    else ct7::wk();
    return 0;
}
原文地址:https://www.cnblogs.com/smyjr/p/10713595.html