NOI 1.5 45: Gold coins

Source: Internet
Author: User

Describe

The king paid the coins as wages to the loyal knight. On the first day, the knight received a gold coin, two days (the second day and the third day), received two gold coins per day, three days (iv days), received three gold coins per day, and four days (第七、八、九、十 days), four gold coins per day ... This pattern of pay continues: when n gold coins are received every day for successive n days, the knight receives n+1 gold coins (n is any positive integer) every day for successive n+1 days.

You need to write a program that determines how many coins a knight has received in a given number of days from the first day.

Input

An integer (range 1 to 10000) that represents the number of days.

Output

The number of coins won by the knight. Enter an integer (range 1 to 10000) that represents the number of days. Output the number of coins the knight obtains.

Sample input

6

Sample output

14






Fayi
#include <iostream>using namespacestd;intN;intMain () {CIN>>N; intt=0, s=0, z=0;//T means that a few gold coins are currently available each day, s represents the total number of coins, and Z indicates the total number of days in the current     while(1) {T++; if(t+z> N) Break;/*t=a can either indicate that a gold coin is currently available daily, or that the status of a gold coin is about to last a day, note that it is about to continue, that is, this a*a gold coin has not accumulated at this time, and Z is the number of days already calculated. When the t+z>n, that is, if the a*a with the time of accumulation, will be the number of days to get gold coins >n, so to break, through the back of the For Loop day by day Plus. */s+=t*t;//t*t The number of gold coins available for this T-dayz+=T; }     for(inti=z+1; i<=n;i++) s+=t;/*when the above t+z=n, will not break, accumulate a t*t, at this time just got n days of gold, z=n,for cycle conditions are not satisfied, not executed. */cout<<s;

Law II

#include <iostream>#include<cmath>using namespacestd;intMain () {intn,t=0, s=0; CIN>>N;  for(intI=1; i<=n;i++)    {         for(intj=1; j<=i;j++)         {              if(t>=n) Break//eg:t=6 When the note has been circulating for 6 days, when T=6 enters the loop is already the seventh day of money s=s+i; T++;//t indicates the number of days that have elapsed}} cout<<s; return 0;}

NOI 1.5 45: 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.