这怎么就错了???

P2669 [NOIP2015 普及组] 金币

Miracle516 @ 2021-06-28 23:30:42

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int k,sm = 0,tmp = k,j = 1,l = 1;
    scanf("%d",&k);
    for(int i = 1; i <= k; i++){
        if(i <= tmp){
            sm += i * i;
            tmp -= i;
        }else{
            j = tmp;
            l = i;
            break;
        }
    }
    sm += j * l;
    printf("%d",sm);
    return 0;
}

by 年子鳖 @ 2021-06-29 00:37:59

tmp=k,要先读入k噢


|