zoukankan      html  css  js  c++  java
  • 【规律】ABC179 E Sequence Sum

    题目链接

    题目解析

    刚开始把题目看错了,看成了乘法,然后直接上指数循环节了qwq

    虽然(N)很大,但是(M)却很小,(A_i)的范围被限定在([0,M-1]),而这个(f())是类似于函数一样的东西,一旦第一个数给定,后面的数就唯一确定(拉普拉斯信条。而根据抽屉原理,至少(m+1)个数之后就会重复,那么重复之后就会产生循环节!那么就做完了!


    ►Code View

    #include<cstdio>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    #define LL long long
    #define N 100005
    #define DEL 100000
    #define INF 0x3f3f3f3f
    LL rd()
    {
    	LL x=0,f=1;char c=getchar();
    	while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    	while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48); c=getchar();}
    	return f*x;
    }
    LL n,x,m,ans;
    LL a[N<<1],s[N<<1];
    int pos[N];
    int main()
    {
    	n=rd(),x=rd(),m=rd();
    	a[1]=x,s[1]=x;
    	for(int i=2;i<=min(100000ll,n);i++)
    	{
    		a[i]=a[i-1]*a[i-1]%m;
    		if(pos[a[i]])
    		{
    			int l=pos[a[i]];
    			LL len=i-l,sum=s[i-1]-s[l-1];
    			ans=s[l-1];
    			LL tmp=n-(l-1);
    			LL p=tmp/len,q=tmp%len;
    			ans=ans+p*sum;
    			ans=ans+s[l+q-1]-s[l-1];
    			printf("%lld
    ",ans);
    			return 0;
    		}
    		s[i]=s[i-1]+a[i];
    		pos[a[i]]=i;
    	}
    	printf("%lld
    ",s[n]);
    	return 0;
    } 
    /*LL ksm(LL a,LL b,LL MOD)
    {
    	LL res=1ll;
    	while(b)
    	{
    		if(b&1) res=res*a%MOD;
    		a=a*a%MOD;
    		b>>=1;
    	}
    	return res;
    }
    //phi(x)=x*(1-1/p1)*(1-1/p2)*...*(1-1/pn)
    LL Phi(LL a)
    {
    	LL res=a;
    	for(LL i=2;i*i<=a;i++)
    		if(a%i==0)
    		{
    			res=res/i*(i-1);
    			while(a%i==0) a/=i;
    		}
    	if(a>1) res=res/a*(a-1);
    	return res;
    }
    //x^{2^n-1}%MOD=x^{(2^n-1)%phi+phi}%MOD
    int main()
    {
    	n=rd(),x=rd(),m=rd();
    	LL phi=Phi(m);
    	LL ind=(ksm(2,n,phi)-1+phi)%phi+phi;
    	LL ans=ksm(x,ind,m);
    	printf("%lld
    ",ans);
    	return 0;
    }*///想成乘法了 qwq 
    
    
  • 相关阅读:
    aspjpeg 组件在asp中的使用
    C# 使用 fckeditor 上传文件中文名乱码的问题---转
    我来挑战主页绑定,浏览器被绑架之终极方案!
    nginx简易配置
    树莓派安装中文输入法
    树莓派4超频至2.0GHz
    python3 requests使用连接池
    python3 语言特性5
    git日常使用
    python3 时间格式化
  • 原文地址:https://www.cnblogs.com/lyttt/p/13982983.html
Copyright © 2011-2022 走看看