Gold coins
Time Limit: 1000 ms memory limit: 30000 K
Total submissions: 21155 accepted: 13265
Description
The King pays his loyal knight in gold coins. on the first day of his service, the knight has es one gold coin. on each of the next two days (the second and third days of service), the knight waits es two gold coins. on each of the next three days (the fourth, th, and sixth days of service), the knight es three gold coins. on each of the next four days (the seventh, eighth, ninth, and tenth days of service), the knight waits es four gold coins. this pattern of payments will continue indefinitely: After processing ing n gold coins on each of N consecutive days, the knight will receive N + 1 gold coins on each of the next n + 1 consecutive days, where N is any positive integer.
Your program will determine the total number of gold coins paid to the knight in any given number of days (starting from day 1 ).
Input
The input contains at least one, but no more than 21 lines. each line of the input file (could t the last one) contains data for one test case of the problem, consisting of exactly one INTEGER (in the range 1 .. 10000), representing the number of days. the end of the input is signaled by a line containing the number 0.
Output
There is exactly one line of output for each test case. this line contains the number of days from the corresponding line of input, followed by one blank space and the total number of gold coins paid to the knight in the given number of days, starting with Day 1.
Sample Input
106711151610010000100021220Sample output
10 306 147 1811 3515 5516 61100 94510000 9428201000 2982021 9122 98
# Include <stdio. h> # include <string. h> # include <stdlib. h> int main () {int t, n; int sum = 0; // the money obtained within n days; int CNT; // control the amount of money per day; int ZF; // The amount of money to be paid per day; while (~ Scanf ("% d", & N) {If (n = 0) break; sum = 0; CNT = 0; ZF = 1; for (INT I = 1; I <= N; I ++) {sum + = ZF; CNT ++; If (CNT = ZF) {CNT = 0; ZF + = 1 ;}} printf ("% d \ n", N, sum);} return 0 ;}
Zookeeper
Gold coins)