求改正

P2669 [NOIP2015 普及组] 金币

yangtianshu @ 2024-12-08 21:29:58

#include<iostream>
#include<cmath>
using namespace std;
int n,a[1000]={0},sum=0,x=0;
int main(){
    cin>>n;
    for(int i=1;sum!=n;i++)
    {
        a[i-1]=i;
        sum+=i;
    }
    for(int i=0;a[i]!=0;i++)
    {
        x+=pow(a[i],a[i]);
    }
    cout<<x;
    return 0;
}

只有#3AC;


by Zhi_ptb @ 2024-12-08 21:53:22

@yangtianshu

#include <bits/stdc++.h>
#define ll long long
#define N 200001
#define mod 998244353
#define sortu(a) sort(a.begin(), a.end())
#define uniqueu(a) a.erase(unique(a.begin(), a.end()), a.end())
using namespace std;
mt19937_64 mrand(random_device{}());

int k;

int main() {
    scanf("%d", &k);
    int ans = 0, j = 1, t = 0;
    for (int i = 1; i <= k; i++) {
        if (t <= j)
            ans += j,
            t++;
        if (t == j)
            j++,
            t = 0;
    }
    printf("%d\n", ans);
}

by kksc0033 @ 2024-12-25 20:38:55

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

AC题解


by kksc0033 @ 2024-12-25 20:39:38

哈哈哈 C++


|