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

Compilation Error WHY?
Posted by Marko Tintor (marko@pkj.co.yu) 25 Jul 2002 20:51
#include <iostream.h>
#include <math.h>
void main()
{
    unsigned long n,p,aa,nn;
    cin >> n; nn=2*n;
    for(p=floor((1+sqrt(1+4*n))/2); p>0; p--)
        if(nn%p==0)
        {
            aa=nn/p+1-p;
            if(aa>=0 && aa%2==0)
            {
                cout << aa/2 << ' ' << p << endl;
                break;
            }
        }
}
delete "sqrt" and got WA
Posted by Oleg 6 Dec 2002 06:33
> #include <iostream.h>
> #include <math.h>
> void main()
> {
>     unsigned long n,p,aa,nn;
>     cin >> n; nn=2*n;
>     for(p=floor((1+>>>>sqrt<<<<(1+4*n))/2); p>0; p--)
>         if(nn%p==0)
>         {
>             aa=nn/p+1-p;
>             if(aa>=0 && aa%2==0)
>             {
>                 cout << aa/2 << ' ' << p << endl;
>                 break;
>             }
>         }
> }
Re: Compilation Error WHY?
Posted by Kostrov Alexey 5 Apr 2005 20:41
Here is your solution, little modified.

#include <iostream>
#include <math.h>
using namespace std;
void main()
{
unsigned long n,p,aa,nn;
cin >> n; nn=2*n;
for(p=floor((1+sqrt((double)(4*n+1)))/2); p>0; p--)
if(nn%p==0)
{
aa=nn/p+1-p;
if(aa>=0 && aa%2==0)
{
cout << aa/2 << ' ' << p << endl;
break;
}
}
}

Compiling, but WA #2