POJ Gold Coins

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.