Page 6 of 11
Why Wrong Answer? 113
Posted: Sat Dec 13, 2003 8:40 pm
by 40019JR
[cpp]
This is my C++ answer for 113.
I got WA. However, I don't understand why. I thought it perfectly solves the problem. Can anyone help me?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double n, k, p;
while (cin >> n >> p)
{
k = pow(p,(1/n));
cout << k << endl;
}
return 0;
}

[/cpp]
Posted: Sun Dec 14, 2003 6:17 am
by shamim
Hi, I corrected the following line and got AC.
[cpp]cout << k << endl;[/cpp]
Most probably the default number digit after decimal is 6, so in UVA compiler your ans. for
2
16
would be
4.000000 and not 4.
Change it to the following line.
[cpp]printf("%.0lf\n",k); [/cpp]
I got compiler errors
Posted: Sun Dec 14, 2003 6:31 am
by 40019JR
Thanks for your reply.
I corrected the line and sent it. However, I got following compiler errors.
Also, when I run it on VC, I get no error but the output is funny. I mean, this doesn't solve the problem.
So if you have any thought on that, I appreciate it.
02143378_24.c: In function `int main ()':
02143378_24.c:14: `printf' undeclared (first use this function)
02143378_24.c:14: (Each undeclared identifier is reported only once for
each function it appears in.)
Posted: Sun Dec 14, 2003 2:48 pm
by Almost Human
the library iostream used by the judge's compiler doesn't support the printf function, so you have to include another library ( stdio.h )
I hope it helped you
Thanks.
Posted: Sun Dec 14, 2003 5:10 pm
by 40019JR
Thanks everyone. It worked.
But like how did you know that their compiler interpret it down to 6 decimal points and stuff like that?
Just out of curiosity.
Posted: Mon Dec 15, 2003 5:01 am
by Almost Human
I guess experience would be the greatest teacher in that case.

where is the bug?? can you help me 113~~~
Posted: Fri Jan 02, 2004 6:46 pm
by Jer
help me~~ plz~~
[cpp]
#include <iostream.h>
#include <math.h>
int main(void)
{
double p,n;
while(cin>>n>>p) {
cout<<pow(p,(double)1/n)<<endl;
}
return 0;
}[/cpp]
Posted: Fri Jan 02, 2004 7:43 pm
by pavelph
1<=p<10^101
I think that double not support so big numbers.
Posted: Fri Jan 02, 2004 11:36 pm
by Krzysztof Duleba
No, double is enough. I have a similar solution, but with two more lines at the begining of the main function:
[cpp] cout.setf(ios::fixed);
cout.precision(0); [/cpp]
I don't remember why I put them there, but there must have been a reason

Posted: Sat Jan 03, 2004 10:19 am
by Jer
Krzysztof Duleba wrote:No, double is enough. I have a similar solution, but with two more lines at the begining of the main function:
[cpp] cout.setf(ios::fixed);
cout.precision(0); [/cpp]
I don't remember why I put them there, but there must have been a reason

I fix the code
[cpp] cout<<(long)pow(p,(double)1/n)<<endl [/cpp]
and some answers will be decrease like 1234->1233
so i think the answers' form i calculate are wrong......
Posted: Sat Jan 03, 2004 3:18 pm
by Krzysztof Duleba
So you finally got accepted?
Posted: Sat Jan 03, 2004 4:27 pm
by Jer
Oh!!yes....~~thank you~~
Posted: Thu Feb 12, 2004 5:16 pm
by aditya
i am trying to use the double data type but if i input a number having more than say 20 digits and then just print it ( no processing ) , i am not getting the same number that i had entered. after 20 digits the precision is lost.
could anyone pls suggest why it is so?
p.s. i have even tried long double
Posted: Tue Feb 17, 2004 8:57 pm
by Sayutee
Your code is too much complex i think- the problem is not so much complex.
I got WA with double but AC with Long Double.
I used natural log instead of base 10.
k = exp(log(p)/n) is enough to solve it.
best of luck
Posted: Wed Feb 18, 2004 5:57 am
by shamim
I used double and got AC.
I think, the judge's data has no such case where precision will be lost.