H_sDc_N @ 2021-08-05 23:15:53
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int i = 0 , day = 0 , sum = 0 , k;
cin >> k;
while (day < k) {
i ++;day +=i ;
for (int j = 1;j <= i; j++)
sum += i;
}
printf("%lld\n", sum);
return 0;
}
by dtrthg @ 2021-08-06 03:55:23
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int i = 0 , day = 0 , sum = 0 , k;
cin >> k;
while (true) {
i ++;day +=i ;
for (int j = 1;j <= i; j++)
sum += i;
if(day>k){
sum=sum-(day-k)*i;
break;
}
}
printf("%lld\n", sum);
return 0;
}
多算金币了,假如k=13,那么模拟一遍就会这样:
然鹅,金币多算了2天,这时要把多出的金币还回去。已知多拿了day-k天金币,每天多拿了i个金币,那多领了多少也就很好算了
by dtrthg @ 2021-08-06 03:56:15
@ H_sDc_N
by H_sDc_N @ 2021-08-11 17:57:59
谢谢您!orz @dtrthg
by 武意程wyc @ 2021-08-16 16:36:11
#include<iostream>
using namespace std;
int main()
{
int n,i,s=0,a,b;
cin>>n;
a=1;
b=0;
for(i=1;i<=n;i++)
{
s=s+a;
b=b+1;
if(b == a)
{
b=0;
a=a+1;
}
}
cout<<s;
}
一种答案