zcmu-1925
1925: hx & xh's game
Time Limit:?1 Sec??Memory Limit:?128 MBSubmit:?30??Solved:?13
[Submit][Status][Web Board]
Description
xh和hx玩一個游戲,過程如下:?首先,hx給xh等差數列A,告訴xh首項a和公差d,讓xh求出數列A前n項和。于是xh將結果求出,并得到一個新的數列B,他也讓hx求數列B前n項和。hx也按xh的要求做了,結果又得到一個數列C,他再次讓xh求數列C前n項和。xh又將結果求出,得到數列D,他不想再為難hx了,現在讓你求數列D的第i項。
Input
該題含有多組測試數據,每組一行,包含三個正整數a(0≤ a≤ 100),d(0≤ d≤ 100),i(1≤ i≤ 100000000)。
Output
由于數據過大,輸出結果mod2017
Sample Input
1 1 5Sample Output
70HINT
Source
哎,自己太菜了,以為這題就3個求和,然后自己后面一直在求通項公式,結果求不出來的,看了大佬的代碼,才知道一開始沒看清楚題目,自己瞎幾把的算。
代碼:
#include<iostream> #include<vector> #include<set> #include<map> #include<stack> #include<queue> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; int a[2018]; int sa[2018]; int sumsa[2018]; int main() {int i,j,sum2017,d,n,left2017,left,sumleft,sum;while(cin>>a[1]>>d>>n){left=n%2017;left2017=n/2017;while(left>=2017)left2017=left2017%2017;sumleft=0;sum2017=sa[1]=sumsa[1]=a[1];if(left==1)sumleft=a[1];for(i=1;i<2017;i++){a[i+1]=(a[i]+d)%2017;sa[i+1]=(sa[i]+a[i+1])%2017;sumsa[i+1]=(sumsa[i]+sa[i+1])%2017;sum2017=(sum2017+sumsa[i+1])%2017;if(i+1==left)sumleft=sum2017;}sum=((sum2017*left2017)%2017+sumleft)%2017;cout<<sum<<endl;}return 0; }總結
- 上一篇: (转载)WebStorm 2018.3.
- 下一篇: zcmu-1918