Iamzzr @ 2021-07-15 10:07:48
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n, i, s=0, a, ans;
cin>>n;
for(i=1; ; i++){
s+=i;
if(s>=n) break;
}
for(a=1; a<=i; a++){
ans += pow(a, 2);
}
ans = ans - (s-n) * i;
cout<<ans;
return 0;
}
by wzmzmhk @ 2021-07-16 15:03:21
@Iamzzr Where is ans = 0?
by Klaus_Game_Bot @ 2021-12-11 16:59:18
试试这个
(最好不要抄代码)
#include<iostream>
using namespace std;
int main(){
int k,coin=0,day=0;
cin>>k;
for(int i=1;;i++){
for(int j=1;j<=i;j++){
coin += i;day++;
if(day==k){
cout<<coin<<endl;
return 0;
}
}
}
return 0;
}