/ Vijos / 题库 / 金币 /

题解

74 条题解

  • 0
    @ 2016-06-03 13:30:18

    var
    a,i,j,n,t:longint;
    begin
    readln(n);
    for i:=1 to n do
    for j:=1 to i do
    begin
    a:=a+i;
    t:=t+1;
    if t=n then
    begin
    writeln(a);
    break;
    end;
    end;
    end.

  • 0
    @ 2016-05-30 21:09:55

    #include<iostream>
    #include<cmath>
    using namespace std;
    int main()
    {
    int i,j,k;
    cin>>k;
    i=j=0;
    long sum=0;
    while (i<k)
    {
    i+=j+1;
    j++;
    sum+=j*j;
    }
    if (i>k) sum-=(i-k)*j;
    cout<<sum;
    return 0;
    }

  • 0
    @ 2016-05-30 13:28:48

    var
    k,n:longint;
    procedure main;
    var
    i,t,s:longint;
    begin
    readln(k);
    t:=1;
    s:=0;
    for i:= 1 to k do
    begin
    if s<t
    then
    begin
    n:=n+t;
    inc(s);
    end
    else
    begin
    s:=1;
    inc(t);
    n:=n+t;
    end;
    end;
    writeln(n);
    end;
    begin
    main;
    readln
    end.

  • 0
    @ 2016-05-30 13:09:24

    var
    k,n:longint;
    procedure main;
    var
    i,t,s:longint;
    begin
    readln(k);
    t:=1;
    s:=0;
    for i:= 1 to k do
    begin
    if s<t
    then
    begin
    n:=n+t;
    inc(s);
    end
    else
    begin
    s:=1;
    inc(t);
    n:=n+t;
    end;
    end;
    writeln(n);
    end;
    begin
    main;
    readln
    end.

  • 0
    @ 2016-05-28 18:58:26

    program coin;
    var
    k,n:longint;
    procedure main;
    var
    i,t,s:longint;
    begin
    readln(k);
    t:=1;
    s:=0;
    for i:= 1 to k do
    begin
    if s<t
    then
    begin
    n:=n+t;
    inc(s);
    end
    else
    begin
    s:=1;
    inc(t);
    n:=n+t;
    end;
    end;
    writeln(n);
    end;
    begin
    main;
    readln
    end.

  • 0
    @ 2016-04-26 14:31:23

    O(1)算法
    那些用O(n)算法的就不要发题解了,一点思维都没有

    补充一个公式:1^2+2^2+…+n^2=n*(n+1)*(2*n+1)/6

    #include<cmath>
    #include<cstdio>
    int n,m,ans;
    int main()
    {
    scanf("%d",&n);
    m=(-1+(int)sqrt(1+8*n))>>1;
    ans=m*(m+1);
    ans=ans*((m<<1)+1)/6+(n-(ans>>1))*(m+1);
    printf("%d",ans);
    return 0;
    }

  • 0
    @ 2016-04-02 09:07:39

    水题啊 那年的~

  • 0
    @ 2016-04-02 09:07:26

    var
    n,i:integer; s:longint;
    begin
    readln(n);
    s:=0;
    for i:=1 to n do
    begin
    n:=n-i;
    s:=i*i+s;
    if n<=0 then begin s:=s+i*n; writeln(s); halt; end;
    end;
    writeln(s);
    end.

  • 0
    @ 2016-03-26 20:36:01

    普及组什么时候这么水了。这个连刚学的都会做呀。。。。
    var
    x,ans,n,i,m:longint;
    begin
    readln(n);
    x:=0; i:=0; m:=1;
    while x<n do
    begin
    ans:=ans+m;
    inc(x);
    inc(i);
    if i=m then
    begin
    inc(m);
    i:=0;
    end;
    end;
    writeln(ans);
    end.

  • 0
    @ 2016-02-27 13:49:11

    program lx;
    var sum,s,a,d,k:longint;
    begin
    read(k);
    d:=0;s:=0;sum:=0;
    repeat
    inc(d);
    s:=s+d;
    if s<=k then sum:=sum+d*d
    else begin
    s:=s-d;
    sum:=sum+(k-s)*d;
    s:=s+d;
    end;
    until s>=k;
    write(sum);
    end.

  • 0
    @ 2016-02-22 13:06:13

    超水,这里就不发答案了

  • 0
    @ 2016-01-12 11:05:22

    var
    k,n,s:longint;
    begin
    readln(k);
    n:=trunc((sqrt(8*k+1)-1)/2);
    s:=n*(n+1)*(2*n+1) div 6 + (k-n*(n+1) div 2)*(n+1);
    writeln(s);
    readln;
    end.

  • 0
    @ 2016-01-04 08:08:45

    #include<iostream>
    using namespace std;
    int main()
    {
    int k,j,temp;
    long long sum=0;
    cin>>k;
    for(int i=1,j=1,temp=1;i<=k;i++)
    {
    sum+=j;
    temp--;
    if(temp==0)temp=++j;
    }
    cout<<sum;
    return 0;
    }

  • 0
    @ 2015-12-31 07:41:05

    #include<iostream>
    #include<cstring>
    #include<cmath>
    using namespace std;
    int main()
    {
    long long int x;
    long long int y;
    long long int z;
    cin>>x;
    y=1;
    z=0;
    while(x>=y)
    {
    x-=y;
    z+=y*y;
    y++;
    }
    z+=x*y;
    cout<<z;
    return 0;
    }

  • 0
    @ 2015-12-30 17:16:40

    include<iostream> include<cstdio>

    using namespace std;
    int main()
    {
    long long int a,b,c,e,f,g;
    int d=0;
    cin>>a;
    while(1)
    {
    d++;
    c=(d(d+1))/2;
    if(c>=a)
    {break; }
    }
    d=d-1;
    e=(2a-d(d+1))/2(d+1);
    f=d(d+1)(2*d+1)/6;
    g=f+e;
    cout<<g<<endl;
    return 0;
    }

  • 0
    @ 2015-12-30 17:06:43

    program p1974;
    var k,t,j,i,s:longint;
    begin
    read(k);
    t:=0;
    i:=0;
    while t<k do
    begin
    inc(i);
    t:=t+i;
    end;
    s:=0;
    for j:=1 to i do
    begin
    s:=s+jj;
    end;
    s:=s-i(t-k);
    write(s);
    end.

  • 0
    @ 2015-12-30 17:04:48

    #include<algorithm>
    #include<cstring>
    #include<fstream>

    using namespace std;
    ifstream fin("coin.in");
    ofstream fout("coin.out");
    int n,i=0,ct,net;

    int main()
    {
    fin>>n;
    while(n>0)
    {
    i++;
    ct+=i;
    n=n-i;
    net=i;
    }
    //fout<<ct;
    if(n<0)
    {
    ct=ct-(0-n,i);
    }
    fout<<ct;

    return 0;
    }

  • 0
    @ 2015-12-10 18:41:14

    var n,k,i,j,sum,z:longint;
    begin
    readln(k);
    j:=0;
    repeat
    j:=j+1;
    i:=i+j;
    until i>=k;
    z:=i;
    n:=z-k;
    for i:=1 to j do sum:=sum+i*i;
    sum:=sum-n*j;
    writeln(sum);
    end.

  • 0
    @ 2015-12-02 16:37:26

    编译成功

    Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
    Copyright (c) 1993-2014 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    Linking foo.exe
    19 lines compiled, 0.0 sec , 27840 bytes code, 1628 bytes data

    测试数据 #0: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #4: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #5: Accepted, time = 0 ms, mem = 440 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #8: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    测试数据 #9: Accepted, time = 0 ms, mem = 436 KiB, score = 10

    Accepted, time = 0 ms, mem = 440 KiB, score = 100

    代码
    program p1974;
    var k,t,j,i,s:longint;
    begin
    read(k);
    t:=0;
    i:=0;
    while t<k do
    begin
    inc(i);
    t:=t+i;
    end;
    s:=0;
    for j:=1 to i do
    begin
    s:=s+j*j;
    end;
    s:=s-i*(t-k);
    write(s);
    end.

    奇葩

  • 0
    @ 2015-12-02 16:36:18

    program p1974;
    var k,i,j,s,t:longint;
    begin
    read(k);
    t:=0;
    i:=0;
    s:=0;
    while t<=k do
    begin
    i:=i+1;
    t:=t+i;
    end;
    for j:=1 to i do
    begin
    s:=s+j*j;
    end;
    s:=s-i*(t-k);

    write(s);
    end.

信息

ID
1974
难度
3
分类
模拟 点击显示
标签
递交数
2947
已通过
1418
通过率
48%
被复制
32
上传者