Title Description
The king paid his loyal knight coins. On the first day of service, the knight received a gold coin. In the next two days each day (second third day of service), the knight received two gold coins. Every day after three days (No. 456 day of service), the knight receives three gold coins. This payment mode will continue indefinitely: After receiving n gold coins every day for successive n days, the knight will receive n+1 gold coins every day for the next n+1 days, where n is an arbitrary positive integer.
Your program will determine how many coins are received by the rider in any given number of days (starting from day one).
Input
The input contains at least one, but at most 21 rows. Each line of input (except the last row) contains a set of test instances of the problem, and a set of instances is an integer (within the 1...10000 range) that represents the number of days. The end of the input is represented by a line that contains a number of 0.
Output
There will be one row for each set of test instances. This line contains the number of days from the corresponding input line, followed by a space and the amount of gold coins received by the knight from the first day to the given number of days.
Source
Rocky Mountain 2004
Ideas
Data is relatively small, direct simulation. In addition to calculate the words can O (1), here will not forget.
Code
#include <stdio.h>const int MAXN = 10000 + 5;int Pay[maxn];int main () { int now = 1; int cnt = 0; for (int i = 1; i < MAXN; i++) { pay[i] = now; cnt++; if (cnt = = Now) { now++; CNT = 0; } } for (int i = 1; i < MAXN; i++) Pay[i] + + pay[i-1]; for (int n; scanf ("%d", &n) && N;) printf ("%d%d\n", N, Pay[n]); return 0;}
POJ Gold Coins