rq1qr @ 2021-08-23 10:30:01
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int k;
scanf("%d", &k);
int i = (sqrt(8 * k + 1) - 1) / 2;
printf("%d", i*(i+1)*(2*i+1)/6+
(k-i*(i+1)/2)*(i+1));
return 0;
}
by XiaoQuQu @ 2021-08-23 10:35:41
简单一句话:常数问题。
by XiaoQuQu @ 2021-08-23 10:36:21
而且,你的这份代码也可以吊打我的暴力 114ms
了。
by XiaoQuQu @ 2021-08-23 10:36:51
#include<iostream>
using namespace std;
int main()
{
int day, coin = 0, coinday = 0, daycoin = 1;
/*
day = 天数
coin = 发布的金币
coinday = 已经发布几天这个金币数
daycoin = 今日将要发布的金币数
*/
cin >> day;
for (int i = 1; i <= day; i++)
{
coinday++;
coin += daycoin;
if (coinday == daycoin)
{
daycoin++;
coinday = 0;
}
}
cout << coin;
return 0;
}
我的代码
by fuqiuyu @ 2021-10-22 18:51:48
@XiaoQuQu,“已经发布几天这个金币数”是什么?