|  | 
|  | 
| вернуться в форум | Can anybody check my program? It seems to be very simple, but my solution fails. 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! :) > 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. I always fail with such a stupid errors.Much obliged!
 | 
 | 
|