Dylan_66 @ 2023-01-09 12:34:38
#include <bits/stdc++.h>
using namespace std;
int main(){
int k ;
scanf("%d" , &k);
int sum , n , day;
for(int i = 1 ; i <= k;i++){
if(day < k){
day += i;
n = i;
}
}
//cout<<day<<endl;
//cout<<n<<endl;
for(int i = 1 ; i <= n ; i++){
sum += i * i;
if(i == n){
if(day - k == 0){
//cout<<"1";
//cout<<sum;
sum = sum - i*i;
sum += i * i;
}else{
//cout<<"0";
//cout<<sum;
sum = sum - i*i;
sum += (n - day + k) * i;
}
}
}
printf("%d" , sum);
return 0;
}
by Mikehuoshan @ 2023-01-09 12:44:05
在主函数内定义变量,变量初始值不是0
by Dylan_66 @ 2023-01-09 16:32:57
@Mikehuoshan 灰常感谢!