| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请教。我得解法是O(n)的。但是不知道哪儿错了。a=(bc-1)/(b+c)
令k=b+c
则b=k-c
所以a=((k-c)c-1)/k
化简为c*c+kc+(ak+1)=0;
c=(-k+sqrt(k*k-4(a*k+1))/2
相应的b=(-k-sqrt(k*k-4(a*k+1))/2
因此我直接对k进行循环,依次k=k+1直到sqrt(k*k-4(a*k+1))为整数。。
但是不知道。为什么就WA了。。。。
#include <iostream.h>
#include <math.h>
int main()
{
unsigned long a,k;
cin>>a;
k=4*a; //因为sqrt中的k*k-4(a*k+1)必须为正。
long double t;
t=sqrtl((unsigned long)(k*k-4*(a*k+1)));
while (!(abs(t-(unsigned long)(t))<0.00000001))
{
k++;
t=sqrtl((unsigned long)(k*k-4*(a*k+1)));
}
cout<<k<<endl;
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator