Previous Questions number game
Time limit: 1.0s memory limit: 256.0MB
Submit this question
Problem description
The building is playing a number game with the students.
The rules of the game are this: the building and the students are all sitting around in a circle of n people. The building first says the number 1. Next, the classmate sitting on the left side of the building will say the next number 2. Then one of the students from the last classmate said the number down two she used out, that is to say 4. The next classmate is going to count three numbers, say 7. In turn.
In order to make the numbers not too large, the building and the students agreed that when the heart count to K-1, the next number from 0 to start. For example, when K=13, the first few numbers that the building and the students quoted were:
1, 2, 4, 7, 11, 3, 9, 3, 11, 7.
The game was going on for a while, and the building wondered what the sum of all the numbers he had been saying so far.
Input format
The first line of the input contains three integer n,k,t, where n and K are the meanings described above, T represents the number of numbers that have been uttered so far in the building.
Output format
The output line contains an integer that represents the and of all the numbers in the building.
Sample input
3 13 3
Sample output
17
Sample Description
The number of buildings to be uttered is 1, 7, 9, and 17.
Data size and conventions
1 < n,k,t < 1,000,000;
The data on the topic is probably an analysis of the situation.
For example 5 13 5
So that means the first ice ice says
First time: 1
Second time: 1+ (2+3+4+5) =15
Third time: 15+ (6+7+8+9) =~
。。。。
Then n times there is recursion: f[i-1]+ ((i-1) *n+1+f[i]) *N/2
Wow, then is to take the surplus, sum ~ ~ ~ ~
#include <cstdio> #include <algorithm> #include <iostream> using namespace
Std
int main () {Long long n,k,t;
Long Long d=1;
Long Long sum=1; while (scanf ("%d%d%d", &n,&k,&t)!=eof) {for (int i=1;i<t;i++) {Long Long di
S= ((i-1) *n+1+n*i) *N/2;
D+=dis;
Dis+=n*n;
if (d>=k-1) d%=k;
Sum+=d;
} cout<<sum<<endl;
} return 0; }