悬关救命!40分

P2669 [NOIP2015 普及组] 金币

__Harry_Haiyun__ @ 2023-08-23 21:52:49


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
int main()
{
    int n;
    cin >> n;
    int sum = 0,temp = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= temp; j++,i++)
            sum += temp;
        temp++;
    }
    cout << sum;
    return 0;
}

by luogu10086 @ 2023-08-23 22:18:38

@__Harry_Haiyun__

供参考

#include<bits/stdc++.h>
using namespace std;
int main(){
    int ji,kun = 0,z = 0;
    cin >> ji;
    for(int i = 1;i <= ji;i++){
        for(int j = 1;j <= i;j++){
            kun += i;
            z++;
            if(z == ji){
                cout << kun;
                return 0;
            }
        }
    }  
}

by __Harry_Haiyun__ @ 2023-08-23 22:21:14

谢,已AC。此帖终


|