<JZOJ5941>乘

emmm还挺妙

不过我没想到qwq

考场上瞎写的还mle了心碎

b分两..预处理下 O1询问qwq

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define rint register int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
template <class T>inline void read(T &X)
{
    X=0;int W=0;char ch=0;
    while(!isdigit(ch))W|=ch=='-',ch=getchar();
    while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    X=W?-X:X;return;
}

int a,p,q,k,m,c;
long long b,l,powa[1000010],poww[1000010],ans=0;

void B()
{
    powa[0]=1;poww[0]=1;
    for(rint i=1;i<=1000000;++i)
        powa[i]=(powa[i-1]*a)%p;
    poww[1]=powa[1000000];
    for(rint i=2;i<=l/1000000;++i)
        poww[i]=(poww[i-1]*poww[1])%p;
}
int main()
{
//    freopen("pow.in","r",stdin);
//    freopen("pow.out","w",stdout);
    read(a),read(p),read(q),read(k);
    read(b),read(l),read(m),read(c);
    if(q==0)return 0;
    q=(q/k)*k;
    B();
    for(rint i=1;i<=q;++i)
    {
        b=((m%l)*(b%l)%l+(c%l))%l;
        ans^=(powa[b%1000000]*poww[b/1000000])%p;
        if(i%k==0)printf("%lld\n",ans);
    }
return 0;
}

 

posted @ 2018-11-01 17:35  Thheoo  阅读(168)  评论(0编辑  收藏  举报