ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1120. Sum of Sequential Numbers

For those who got WA on test#2
Posted by xcheng 27 Aug 2007 07:30
if n=1 the answer a=0 p=2 is wrong!
The correct answer is a=1 p=1
Re: For those who got WA on test#2
Posted by kalisha 11 Feb 2009 16:59
Answer 1 1, but WA2
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
int n;
int a;
int p;
int x,y;
int i,j;
int result=0;
cin>>n;

a=sqrt((float)n)+1;
p=a;
x=y=0;

for (i=1;i<=a;i++)
{
    result=0;
    for (j=1;j<=p;j++)
    {
    result+=(i+(j-1));
        if (result==n)
        {
            if (y<j)
            {
                x=i;
                y=j;
            }
        }
    }
}
cout<<x<<" "<<y<<endl;
return 0;
}