Social Icons

Thursday, November 26, 2015

Solve of UVA 12908: The book thief

Solve of UVA 12908: The book thief


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,i,j,k,l,x;
    while(scanf("%ld",&x)==1)
    {
        if(x==0) return 0;
        n=(-1+sqrt(1+8*x))/2;
        if((n*(n+1))/2==x)
            printf("%ld %ld\n",n+1,n+1);

        else
        printf("%ld %ld\n",((n+1)*(n+2))/2-x,n+1);

    }
    return 0;
}

No comments:

Post a Comment

 

Sample text

Sample Text

 
Blogger Templates