Page 2 of 11
Posted: Wed Jul 24, 2002 3:13 pm
by Ivor
I don't know what is your problem, but I used
Code: Select all
while (scanf("%lf", &d) == 1)
{
/* code here */
}
And it got accepted.
Ivor
THIS IS NOT MASSIVE
Posted: Wed Jul 24, 2002 3:28 pm
by NONAME_SUST
Hi,
No..The problem is in ur declare. Declare the variable as double and then use "%lf" to read the inputs. Like this way...
double d;
scanf("%lf",&d);
You may also truncate the zeroes after decimal.
Posted: Thu Jul 25, 2002 7:44 pm
by taj79
i m stiil getting error
my p is 4357186184021382204544
when
double p;
scanf("%Lf",p);
printf("%0.0f",p);
ANS is 0
when
double p;
scanf("%Lf",p);
printf("%0.0Lf",p);
ANS is 280585630299556481757617220275852364727636170628410927600364713659709368033262555286057473837891584000
when
double p;
scanf("%lf",p);
printf("%0.0lf",p);
ANS is 0
when
double p;
scanf("%lf",p);
printf("%0.0f",p);
ANS is 0
what should i do???
Posted: Thu Jul 25, 2002 8:52 pm
by Adrian Kuegel
use:
double p;
scanf("%lf",&p);
printf("%.0lf",p);
Posted: Fri Jul 26, 2002 5:45 am
by zhartley
Any idea why I get wrong answers for both of the following?:
[cpp]
/* @JUDGE_ID: 21301HT 113 C++ */
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
register long long n, p, k;
while (cin >> n >> p) {
k = static_cast<long long>(pow(p, (1.0 / n)));
cout << k << endl;
}
return 0;
}
@end_of_source_code
[/cpp]
or this (same thing using long doubles):
[cpp]
/* @JUDGE_ID: 21301HT 113 C++ */
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
register long double n, p, k;
while (cin >> n >> p) {
k = pow(p, (1.0 / n));
cout << k << endl;
}
return 0;
}
@end_of_source_code
[/cpp]
Any ideas?
Posted: Fri Jul 26, 2002 11:18 am
by taj79
i have tried what adrian has said....but still error.....
my p is 4357186184021382204544
but my prog output is 4357186184021382004736
the difference is in the last few digits......
i have noticed that i had forgotten & in scanf earlier but this time i did what adrian had told me..
Posted: Fri Jul 26, 2002 11:39 am
by Adrian Kuegel
Why do you worry about this? Of course the precision of double is not enough for all these digits, but it would be sufficient if only the 10 first digits were correct. I read the first 10 digits manually into double and got ACCEPTED, I used the exact length of the number in the calculation.
Posted: Fri Jul 26, 2002 11:44 am
by Adrian Kuegel
Long double is not enough if you calculate the answer this way. Try another approach, with log like mentioned above.
Posted: Sat Jul 27, 2002 1:38 am
by zhartley
ok....i tried using logarithms....
[cpp]
@begin_of_source_code
/* @JUDGE_ID: 21301HT 113 C++ */
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
register long double n, p, k;
while (cin >> n >> p) {
k = exp( log(p) / n );
cout << k << endl;
}
return 0;
}
@end_of_source_code
[/cpp]
....and it got me Yet Another Wrong Answer
everything seems to work on this end:
zth@littledaemon$ cat input
2
16
3
27
7
4357186184021382204544
zth@littledaemon$ a.out < input
4
3
1234
Any ideas?
Posted: Sat Jul 27, 2002 1:46 am
by Adrian Kuegel
That can't work if the input contains really big numbers. Consider, how you can use the length of a number when calculating log10 of that number. And I think that log and exp are only defined for double, not for long double, so I would not use long double. I used double and cut off all digits after the tenth.
Posted: Sat Jul 27, 2002 2:42 am
by zhartley
zth@littledaemon$ grep "exp" /usr/include/g++/cmath | grep "long double"
long double exp (long doulbe);
long double frexp(long double, int*);
long double frexp(long double, int*);
zth@littledaemon$ grep "log" /usr/include/g++/cmath | grep "long double"
long double log (long double);
long double log10(long double);
So, apparently, they can use long doubles (FreeBSD 4.5-Release using gcc version 2.95.3 20010315 (release) [FreeBSD])
As far as the rest of your post, I'm confused. you only considered the first ten digits of any number? And I unfortuneately do not know of any way to use the length of a number in regards to logarithms. And I have been re-reading my math textbooks on logarithms to make sure I am not missing anything. (Btw, thanks for taking the time to reply)
Beguiling WA for 113
Posted: Mon Jul 29, 2002 11:49 pm
by zhartley
Yes, I know this problem already has a thread, however this is a slightly different problem...
Does _anybody_ know how to explain how I get an accepted with this:
[c]
#include <stdio.h>
#include <math.h>
int main(void) {
int n;
double p;
while (scanf("%d %lf", &n, &p) == 2) {
printf("%.0lf\n", exp(log(p)/(double)n));
}
return 0;
}
[/c]
while i get a wrong answer with this:
[cpp]
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void) {
int n;
double p;
while (cin >> n >> p) {
cout << setprecision(0) << exp(log(p)/(double)n) << endl;
}
return 0;
}
[/cpp]
Near as I can tell, they are identical.
Posted: Sun Aug 04, 2002 2:01 pm
by Daniel Chia
i get the same problem

and btw..as far as my measly knowledge of c++ is concerned... setprecisio(0) sets it back to the default of infinite precision, no?
Posted: Mon Aug 05, 2002 12:21 am
by zhartley
well, i've been re-reading my copy of The C++ Programming language (and re-reading it and re-reading it...) and I'm still extremely confused (the documentation sucks (or i do

)). In any event, this is what I am working with right now (which still gets a WA)
[cpp]
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void) {
double n, p;
cout.unsetf(ios::showpoint);
while (cin >> n >> p) {
cout << exp(log(p)/n) << endl;
}
return 0;
}[/cpp]
113- power of cryptography - What is the algorithm?
Posted: Sun Sep 15, 2002 5:50 pm
by laboni
this problem is a nightmare! P is Such a big number!!
There must be some easy algorithm in number theory to solve such problem.Can anyone help me plz?
