Description questions
The king gold as wages paid to loyal knight. The first day, Knight received a gold coin; two days (days two and three) years, received two gold coins every day; three days later (fourth, five or six days), the received three daily gold coins; four days later (seventh, eight, nine, ten) years, received four gold ...... this day payroll mode will always continue like this: when N N consecutive days to receive gold coins every day, Knights N + 1 consecutive days after, the coins received N + 1 (N is any positive integer) every day. You need to write a program to determine from the first day of a given number of days, the Knights won a total of how many gold coins.
Input Format
An integer (range of 1 to 10000), the number of days.
Output Format
Knight gold coins obtained.
Sample input
6
Sample Output
14
#include <stdio.h>
int main()
{
int n,i,j,k,sum;
while(scanf("%d",&n)!=EOF)
{
sum=0; j=1; k=1;
for(i=1;i<=n;i++){
sum+=k;
if(i==j){
k++; //k表示当天可获得的金币数
j+=k; //j表示金币能增加时需要跨过的天数
}
}
printf("%d\n",sum);
}
return 0;
}