Friday, 2 October 2015

Gold Coins (UVALive 3045, ZOJ 2345, POJ 2000, Regionals 2004 >> North America - Rocky Mountain)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 10010

int cumm[MX];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n;
    string s;
    char ch;
    int today=1, tmp=0;
    for(int i=1;i<=10000;i++)
    {
        cumm[i]=cumm[i-1]+today;
        tmp++;
        if(today==tmp) today++, tmp=0;

    }

    while(cin>>n && n)
    {
        cout<< n<< " "<<cumm[n] <<"\n";
    }
return 0;
}

No comments:

Post a Comment