题解:规律题;陈陈每次说的数字为a0+n*(n+1)/2;注意考虑%k否则最后一组数据会wa;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> using namespace std; const int INF=0x3f3f3f3f; #define mem(x,y) memset(x,y,sizeof(x)) #define SI(x) scanf("%d",&x) #define PI(x) printf("%d",x) #define SD(x,y) scanf("%lf%lf",&x,&y) #define P_ printf(" ") typedef long long LL; int main(){ int n,k,T; scanf("%d%d%d",&n,&k,&T); LL ans=0; LL temp=1,t=n; for(int i=0;i<T;i++){ ans+=temp; if(t&1)temp=(1+(t+1)/2*t%k)%k; else temp=(1+t/2*(t+1)%k)%k; t=(t+n)%(2*k); /*for(int j=0;j<n;j++){ t++; if(t>=k)t%=k; temp+=t; if(temp>=k){ temp=temp-k; } }*/ } printf("%lld\n",ans); return 0; }
原文:http://www.cnblogs.com/handsomecui/p/5122101.html