Subject to the effect
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.
Ideas analysis
Look at the code it direct, easy to understand
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define ll long long
#define MAX 10005
ll arr[MAX];
int main() {
ll cnt = 1, num = 1; arr[0] = 0;
for (ll i = 1; i < MAX; i++) {
arr[i] = arr[i - 1] + num;
cnt--;
if (cnt == 0)num++, cnt = num;
}
while (cin >> cnt && cnt)cout << cnt << ' ' << arr[cnt] << endl;
}