|
|
back to boardCompilation Error WHY? #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? 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 |
|
|