「十二省联考 2019」骗分过样例

传送门

Solution 

\(1\_998244353\):求\(19\)的幂,因为次数可能很大,所以直接对\(P\)的欧拉函数取模

\(1?\)/\(1?+\):要猜模数,分别是\(1145141\)\(5211600617818708273\)

\(1wa\_998244353\):不能快速幂了,需要直接乘。。。发现循环节很短,考虑直接求出来

\(2p\):区间求质数, \(Miller\_ Rabbin\)即可

\(2u\):区间求莫比乌斯函数,先把\(10^6\)内的质数筛出来处理区间的数,大于\(10^6\)的质因子最多两个,先判断剩下的积是不是完全平方数,再用\(MR\)判断是不是质数

\(2g\):区间求原根,设\(P\)的质因子有\(n\)

  1. 对于区间长但原根小的,用\(O(Pk)\)的方法,先找到一个原根\(g\)(观察数据即可),然后把形如\(g^i,i|P-1\),的筛掉,枚举\(P-1\)的每个质因子分别筛
  2. 对于区间短但是原根大的,用\(O(len \cdot n\log P)\),枚举\(x^{\frac{(P-1)}{p_i}}\),判断是否模\(P\)\(1\)

Code 

#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
char ch[100];
ll Mul(ll x,ll y,const ll M){return (x*y-(ll)((long double)x/M*y+.5)*M+M)%M;}
ll Add(ll a,ll b,const ll M){return (a+b)%M;}
ll fp(ll x,ll y,const ll M)
{
    ll r=1;for(;y;y>>=1,x=Mul(x,x,M))if(y&1)r=Mul(r,x,M);
    return r;
}
const ll a[]={2,3};
bool pd(ll x,int y=2)//Miller_Rabin
{
    for(int i=0;i<y;++i)
    {
        if(x==a[i]) return true;
        if(x%a[i]==0) return false;
        if(x<a[i])break;
        if(fp(a[i],x-1,x)!=1) return false;
        ll j=x-1,k;
        while(~j&1)
        {
            j>>=1;k=fp(a[i],j,x);
            if(Mul(k,k,x)==1&&k!=1&&k!=x-1) return false;
        }
    }
    return true;
}
namespace pow19
{
    ll Read(ll M)
    {
        static char s[100];
        scanf("%s",s);ll r=0;int len=strlen(s);
        for(int i=0;i<len;++i)r=Mul(r,10ll,M),r=Add(r,s[i]-'0',M);
        return r;
    }
    void Main(ll P)
    {
        int N=read();
        while(N--) printf("%lld\n",fp(19,Read(P-1),P));
    }
    int f[101000];
    void Main2(ll P)
    {
        int st=55245,ed=100944;
        ll x,N=read();
        for(f[0]=x=1;x<=ed;++x) f[x]=f[x-1]*19%P;
        while(N--)
        {
            x=read();
            printf("%d\n",x<st?f[x]:f[(x-st)%(ed-st)+st]);
        }
    }
}
namespace p
{
    void Main()
    {
        ll l,r,i,N=read();
        for(;N--;puts(""))
        {
            l=read(),r=read();
            for(i=l;i<=r;++i) putchar(pd(i)?'p':'.');
        }
    }
}
namespace u
{
    #define LA 1000000
    int ans[LA+100],tot,pr[LA+5],mrk[LA+5];ll v[LA+100];
    void init(int N)
    {
        mrk[1]=1;
        for(int i=2;i<=N;++i)
        {
            if(!mrk[i]) pr[++tot]=i;
            for(int j=1;j<=tot&&pr[j]*i<=N;++j)
            {
                mrk[pr[j]*i]=1;
                if(i%pr[j]==0) break;
            }
        }
    }
    void solve(ll l,ll r)
    {
        reg ll i,j;
        for(i=l;i<=r;++i) v[i-l]=i;
        for(i=1;i<=tot;++i)
        for(j=l-((l+pr[i]-1)%pr[i])-1+pr[i];j<=r;j+=pr[i])
        if(~ans[j-l]){
            ans[j-l]++;v[j-l]/=pr[i];
            if(v[j-l]%pr[i]==0) ans[j-l]=-1;
        }
        for(i=l;i<=r;++i)
        {
            if(ans[i-l]==-1){putchar('0');continue;}
            if(v[i-l]!=1)
            {
                if(1ll*(ll)sqrt(v[i-l])*(ll)sqrt(v[i-l])==v[i-l]){putchar('0');continue;}
                ans[i-l]+=(v[i-l]<=1e12||pd(v[i-l],1));
            }
            putchar(ans[i-l]&1?'-':'+');
        }
    }
    void Main()
    {
        init(LA);
        puts("--0-+-00+");puts("-+-00+");puts("--0-+-00+-0-++");
        for(int i=1;i<=7;++i)read();
        ll l=read(),r=read();
        solve(l,r);
    }
    #undef LA
}
namespace g
{
    ll P,tot,fac[30];
    bool mk[13123111],ans[13123111];
    void getfac()
    {
        if(tot&&P==998244353)return;tot=0;int P1=P-1;
        for(int i=2;i*i<=P1;++i)if(P1%i==0)for(fac[++tot]=i;P1%i==0;P1/=i);
        if(P1)fac[++tot]=P1;
    }
    void Main()
    {
        puts(".g");puts(".g.gg...g");
        int N=read()-2;ll i,j;for(i=1;i<=6;++i)read();
        while(N--)
        {
            ll l=read(),r=read();P=l==233333333?1515343657:read();
            getfac();
            if(P==13123111)
            {
                for(i=1;i<=tot;++i)for(j=fac[i];j<P;j+=fac[i])mk[j]=1;
                for(j=1,i=0;i<P;++i,j=(j*6ll)%P)ans[j]=mk[i];
                for(i=1;i<P;++i)putchar(ans[i]?'.':'g');
            }
            else for(i=l;i<=r;++i)
            {
                bool fl=1;
                for(j=1;j<=tot;++j)if(fp(i,(P-1)/fac[j],P)==1){fl=0;break;}
                putchar(fl?'g':'.');
            }
            puts("");
        }
    }
}
int main()
{
    scanf("%s",ch);
    if(ch[0]=='1'&&ch[1]=='_') pow19::Main(998244353);
    else if(ch[0]=='1'&&ch[1]=='?'&&ch[2]=='+') pow19::Main(5211600617818708273);
    else if(ch[0]=='1'&&ch[1]=='?') pow19::Main(1145141);
    else if(ch[0]=='1'&&ch[1]=='w') pow19::Main2(998244353);
    else if(ch[0]=='2'&&ch[1]=='p') p::Main();
    else if(ch[0]=='2'&&ch[1]=='u') u::Main();
    else if(ch[0]=='2'&&ch[1]=='g') g::Main();
    return 0;
}



Blog来自PaperCloud,未经允许,请勿转载,TKS!

猜你喜欢

转载自www.cnblogs.com/PaperCloud/p/11306120.html