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

Can anybody check my program? It seems to be very simple, but my solution fails.
Posted by Osama Ben Laden 5 Mar 2002 20:32
Here is my solution:

#include <fstream.h>
#include <math.h>

int main()
{
 // p*(2*a+p-1) = 2*n  ==>
 long n; cin>>n; n*=2;
 for(long p=sqrt(n); p>1; p--)
  if(n%p==0) if(n/p>p && (n/p-p)%2)
  {cout<<(n/p-p+1)/2<<' '<<p<<endl; return 0;}
 return 0;
}

Best regards!
I know why ur solution fails! :)
Posted by I have answers to all your questions :) 5 Mar 2002 22:07
> Here is my solution:
>
> #include <fstream.h>
> #include <math.h>
>
> int main()
> {
>  // p*(2*a+p-1) = 2*n  ==>
>  long n; cin>>n; n*=2;
>  for(long p=sqrt(n); p>1; p--) <====== p == 1 ???
>   if(n%p==0) if(n/p>p && (n/p-p)%2)
>   {cout<<(n/p-p+1)/2<<' '<<p<<endl; return 0;}
>  return 0;
> }
>
> Best regards!
Thank you! I got AC.
Posted by Osama Ben Laden 7 Mar 2002 19:01
I always fail with such a stupid errors.
Much obliged!