Page 1 of 3
701 - The Archeologists' Dilemma
Posted: Sat Mar 23, 2002 4:00 pm
by EggHead
I think I've probed that for each N in the given range, there's a power of 2 satisfied all the conditions. But for some larger N, I don't have a effective algorithm to solve it on time!

So, will anybody give me some tips of the correct algorithm?
Posted: Mon Apr 15, 2002 10:09 am
by rafay
> suppose the prefix is a
> > a*10^n <= 2^x < (a+1)*10^n
> > a <= 2^x/10^n < a+1
> > a <= 2^m/5^n < a+1, where m=x-n
> > 1 <= 2^m/5^n/a < 1+1/a
> >
> > 2^p/5^q = 1
> > plog(2) = qlog(5)
> > q/p = log(2)/log(5) = 0.43067655807339306
> > = [0, 2, 3, 9, 2, 2, ... ] in continuous
> > fraction
> > = 0/1, 1/2, 3/7, 28/65, 59/137, 146/339 ...
> > Accordingly,
> > 2^1/5^0 = 2
> > 2^2/5^1 = 0.8
> > 2^7/5^3 = 1.024
> > 2^65/2^28 = 0.9903520314283045
> > 2^137/2^59 = 1.0043362776618743
> > 2^339/5^146 = 0.9989595361011142
> >
> > Initially,
> > the ratio is 1/5^(d+1)/a < 1, where d is the # of
> > a's digits.
> > so multiply it by 2 until it's greater than 1
> > if the ratio is not in [1, 1+1/a) then
> > multiply it by 0.8 until it's less than 1+1/a
> > if the ratio is not in [1, 1+1/a) then
> > multiply it by 1.024 until it's greater than
> > 1
> > ...
> > */
701 - how far to go?
Posted: Wed Oct 09, 2002 7:34 pm
by turingcomplete
My solution works for exponents up to 1024 (the max long double). I am getting "Wrong Answer". Is it because I need to check exponents higher then that? At what point should you stop? The question doesn't say.
Maybe there is some forumla rather then a brute force method that will give you an answer all the time, however I can't see what it would entail.
Don't stop :D
Posted: Thu Oct 10, 2002 3:01 pm
by junjieliang
There's been some posts on this problem. As far as I know, you have to check until you find a solution, as there is no "no power of 2". I tried using a brute force check from 0 up, and getting the first 10 or so digits using log, but still TLE. Someone once posted a method using partial fractions which I don't understand, so I can't explain that. If I remember correctly, before the "algorithms" field was taken away, people solved it using "brute force logs". I have absolutely no idea what that means...

Posted: Fri Oct 11, 2002 3:30 pm
by Ivan Golubev
I don't remember exactly but main idea is to use logs. We're searching x, and there must be
N*10^k <= 2^x and 2^x < (N+1)*10^k, k -- number of missed digits, so
log2(N*10^k) <= log2(2^x) and log2(2^x) < log2((N+1)*10^k)
log2(N) + k*log2(10) <= x and x < log2(N+1) + k*log2(10)
With these "equations" and brute-forcing on k we can found x fast enough.
(May be I've missed something, sorry, I've solved this one a long time ago).
701
Posted: Thu Jul 24, 2003 9:18 pm
by thechaoshacker
Don't we proceed in this manner :-
number prefix
2^7 = 128 1
2^8 = 256 2
2^9 = 512 5
2^10 = 1024 not possible, since 1 has already been used and 10 is not less than half of the input symbols.
2^11 = 4096 4
.
.
.
2^22 = 4194304 41, 419
I did this by brute force, and still I get a WA. Can nebody help me out ? Thanx.
TheChaosHacker
Posted: Mon Dec 01, 2003 10:01 am
by yiuyuho
hi Ivan,
I used your method and it works for the judge, however, some input N can still cost a long time, for example n=2147483648, or n=7654321. Which means the program can be rejected once better input is given.
if we allow x(or E) to be as big as 2^32, is there better methods?
Anyways, just some though.....
Posted: Tue Jun 29, 2004 6:50 pm
by nashtb1
"To reinforce her belief, she selects a list of numbers on which it is apparent that the number of legible digits is strictly smaller than the number of lost ones..."
You proceed in the following manner:
2^1 == 2 1
2^2 == 4 2
2^3 == 8 3
2^4 == 16 4
...
2^7 == 128 7
...
For input of '1', you must find an exponent such that 2^exponent meets two criteria:
First, the first digits of 2^exponent must match the provided digits.
Second, the number of 'missing digits' must be greater than the number of provided digits.
So, for the input '1', while 2^0 and 2^4 both provide numbers begining with 1, the number of 'missing digits' are less than or equal to the number of provided digits.
As such, you must find a power of two with 2*(number of provided digits)+1.
Hope this clarifies things.
Posted: Fri Jul 02, 2004 11:06 am
by OmegaWarrior
Can somebody tell me how to approach this problem? If numbers go on forever, how can you ever determine whether or not a given string of numbers is the leading string of some factor of 2? Please reply quickly, as I am afraid I am in a hurry. Thank You.
Posted: Fri Jul 02, 2004 11:22 am
by OmegaWarrior
Okay, Never Mind. the board rules say to only have one thread per problem, so I naturally assumed that the first thread I saw on problem 701 would be the only one; however, upon further examination of the board, I see that there are multiple threads for this problem, and that my question has already been answered. My apologies.
Please obey the rules; doing otherwise leads to this kind of confusion.
--
OmegaWarrior
Posted: Sat Oct 16, 2004 10:52 pm
by bhagwati
The way I understand this problem, the input number (a positive integer) is to match a power of two as follows:
1. The length of the input is "strictly" less than half the length of the power of two.
2. The first digits of the power of two are to be matched with the input.
3. The input number cannot be greater than 2147483648 (i.e. less than or equal to 2147483647).
Is this understanding correct?
Posted: Sun Oct 17, 2004 5:06 am
by yiuyuho
3. should be
3. The input number cannot be greater than 2147483649 (i.e. less than or equal to 2147483648).
since 2147483648 is no bigger than 2147483648.
Input / Output verification for Problem 701
Posted: Wed Feb 09, 2005 6:34 pm
by Sedefcho
Can someone verify this input / output ?
It consists of 16 test cases ( 16 numbers in the input ).
INPUT
Code: Select all
1
2
3
4
10
2147
10240
9900
7200
1000000
2000000
14690
14960
10000000
100000000
500000000
OUTPUT
Code: Select all
7
8
15
12
20
31
28748
24559
4813
325147
325148
11036
37937
6432163
198096465
1578339556
Peter Petrov
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:19741
answer for 2^31 ?!
Posted: Wed Feb 09, 2005 6:37 pm
by Sedefcho
Can someone give the answer for input N = 2147483648
( that is N = 2 ^ 31 ).
Thank you in advance.
Posted: Tue Feb 15, 2005 4:06 pm
by emotional blind
> > 2^p/5^q = 1
> > plog(2) = qlog(5)
> > q/p = log(2)/log(5) = 0.43067655807339306
> > = [0, 2, 3, 9, 2, 2, ... ] in continuous
> > fraction
> > = 0/1, 1/2, 3/7, 28/65, 59/137, 146/339 ...
> > Accordingly,
I cant understand properly...
plz help me..