40。。。

P2669 [NOIP2015 普及组] 金币

anata @ 2019-06-12 14:01:59

求解。。。

include<bits/stdc++.h>

using namespace std;

int main()

{

long long ans=0,k=0,i=1,bk=0;
cin>>k;
do
{
    ans+=i*i;
    bk+=i;
    i++;
}
while(bk<k);
ans-=i*(bk-k);
cout<<ans;
return 0;

}


by charliegong @ 2019-06-12 14:06:57


#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
    int i,j,n,x=1,sum=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(x*(x+1)/2<i){
            x++;
        }
        sum+=x;
    }
    cout<<sum;
    return 0;
}

by zhangyuzhe @ 2019-06-12 14:15:04

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int n,s=0,t=0;
    cin>>n;
    for(int i=1;;i++)
    for(int j=1;j<=i;j++)
    {
        s+=i;
        t++;
        if(t==n) {
        cout

by sycqwq @ 2019-06-12 14:15:59


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

by zhangyuzhe @ 2019-06-12 14:16:00

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int n,s=0,t=0;
    cin>>n;
    for(int i=1;;i++)
    for(int j=1;j<=i;j++)
    {
        s+=i;
        t++;
        if(t==n) {
        cout<<s;exit(0);}
    }
    return 0;
}

by zhangyuzhe @ 2019-06-12 14:16:16

刚刚发漏了,不好意思


|