40分,c++求助

P2669 [NOIP2015 普及组] 金币

MZL1234 @ 2023-08-21 16:21:45

#include<iostream>
using namespace std;
int main(){
    long long k,coin=0,day=1;
    cin>>k;
    for(long long n=1;n<=k;n++){
        for(long long i=1;i<=n;i++){
            coin+=n;
            day++;
        }
        if(day>k) break;
    }
    cout<<coin;
    return 0;
}

by tjr0513 @ 2023-08-21 16:24:27

内层循环也要判断if(day>k) break;


by tjr0513 @ 2023-08-21 16:25:25

求关


by MZL1234 @ 2023-08-21 16:29:01

@tjr0513 AC了,谢谢


|