yutongt09 @ 2023-03-01 17:24:38
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,k=0,z=0,b=0;//n一共天数 k总数 z随时天数
cin>>n;
while(n>0){
z++;
if(z<=n){
for(int i=1;i<=z;i++){
k=k+z;
n--;
}
}
else
{
for(int j=1;j<=z;j++){
k=k+z;
n--;
}
}
}
cout<<k;
return 0;
}
我不知道哪里错了
by _Dolphin_ @ 2023-03-01 17:53:48
下面循环要先给z
赋值为n
by _Dolphin_ @ 2023-03-01 17:59:12
#include<bits/stdc++.h>
using namespace std;
int n,z,ans;
int main() {
scanf("%d",&n);
while(1) {
z++;
if(z<=n) {
ans+=z*z;
n-=z;
}
else {
ans+=n*z;
break;
}
}
printf("%d",ans);
return 0;
}
by _Dolphin_ @ 2023-03-01 17:59:59
@yutongt09
by yutongt09 @ 2023-03-04 08:35:19
@Dolphin0613
好好好,谢谢大佬