10232 - Bit-wise Sequence

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

10232 - Bit-wise Sequence

Post by Caesum »

Can someone explain this problem to me please ? It gives the sample input and output:
Sample Input
0
1
2
31
32

Sample Output
0
1
2
1073741824
3
Shouldnt the sequence be 0,1,2,4,8,16,32,3,5,6,9,.....
in which case 32 is 6th and not 3rd as in the sample ? and 31 would not be that far in to the sequence....... Or am I completely misunderstanding this ?
Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev »

Looks like you've exchanged input and output -- the 31th number of sequence is 1073741824, the 32nd number is 3, etc.
ithamar
Learning poster
Posts: 56
Joined: Mon May 13, 2002 11:58 pm
Location: Venezuela

Post by ithamar »

I dont understan the input - output for this problem. Can anybody explain me why the number 1073741824 is the number 31 in the sequence (not 30 as i believe that should be).

I believe that all the numbers in the sequence between 1 and 30 are 1, 2, 4, 8, 16, 32, .... , 1073741824. But in this way 1073741824. is the number 30 not 31. What is wrong about my reasoning.

Thanxs in advance.
Those Who Don't Know History are doomed to repeat it
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

If you use this sequence, the 30th number is 536870912, the 31th number is 1073741824. Perhaps generate you a list with a program, you will see it.
solver
New poster
Posts: 6
Joined: Fri Jul 12, 2002 6:23 pm

Post by solver »

umm... I'm feeling quite clueless attempting this problem. :roll:
solver
New poster
Posts: 6
Joined: Fri Jul 12, 2002 6:23 pm

10232 -- is this the method?

Post by solver »

I've been thinking about 10232 (Bitwise Sequence), and the only way I could think of doing it was to

Taking 2 to be the only prime number with one 1 in its bin. representation,

1. generate all combinations of two 1s (with 1 in the last placeholder, as even numbers are not to be checked), and check them for primality.
2. Do the same for three 1s, four 1s, .. and so on, UNTIL we get the Nth prime number.


This approach is basically trying all combinations (serialwise however), and doesn't seem quite right if the time limit is less.

Is there any obvious number theory trick I'm missing ( a hint will do ). At least someone can confirm if I'm on the right track?

Thanks
solver
New poster
Posts: 6
Joined: Fri Jul 12, 2002 6:23 pm

Post by solver »

Ulan Degenbayev wrote:How did you attached primes to this problem?
May be you have mixed up some problems?
You are right. I mixed up this problem with another one I saw. And misreading this one, I assumed one has to form a list of prime numbers in ascending order of B(n). That was confusing me a lot. :)

Now that the question is clear to me, the solution seems straightforward. Thanks.
Shahab
New poster
Posts: 24
Joined: Sun Nov 10, 2002 2:17 pm

10232 - Bit-wise sequence

Post by Shahab »

Hi everybody,

I have solved the problem #10232, but I got WA for it. It solves the sample input and my samples in the right way and I really can't understand the problem behind it.

Can anyone give me some sample input and output plz?

Thanks in advance,
Shahab Tasharrofi
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Pretty much random:

Input:

Code: Select all

0
1
2
31
32
6123512
852412
123125
67658153
214155
2147483647
5623674
Output:

Code: Select all

0
1
2
1073741824
3
147227152
1099186184
135856144
1247429124
57624
2147483647
100730919
Shahab
New poster
Posts: 24
Joined: Sun Nov 10, 2002 2:17 pm

Post by Shahab »

Thanks for your inputs Larry, but altough it can solve them in the right way, i got WA another time :( , I'm really getting disappointed of this problem :-?

Shahab Tasharrofi
Shahab
New poster
Posts: 24
Joined: Sun Nov 10, 2002 2:17 pm

Post by Shahab »

ok, let me put my code here, I'll be graceful if you could have a brief look at it :

[pascal]
program P10232;
type Int=LongInt;
var A:array [-1..31,-1..31] of Int;
Bit:array [0..31] of Byte;
function Solve(n:Int):Int;
var i,b,k:Int;
begin
i:=0;
while n>=0 do
begin
n:=n-A[31,i];
Inc(i);
end;
Dec(i);
n:=n+A[31,i];
b:=31;
repeat
if n>=A[b-1,i] then
begin
n:=n-A[b-1,i];
Bit:=1;
Dec(i);
end
else
begin
Bit:=0;
end;
Dec(b);
until b<=0;
for i:=31 downto 1 do
k:=k shl 1+Bit;
Solve:=k;
end;
var i,j,n,k:Int;
begin
A[-1,0]:=0;
A[-1,-1]:=0;
for i:=0 to 31 do
begin
A[i,-1]:=0;
A[i,0]:=1;
for j:=1 to i-1 do
A[i,j]:=A[i-1,j-1]+A[i-1,j];
A[i,i]:=1;
end;
while not Eof(Input) do
begin
ReadLn(n);
k:=Solve(n);
WriteLn(k);
end;
end.
[/pascal]
daveon
Experienced poster
Posts: 229
Joined: Tue Aug 31, 2004 2:41 am
Location: TORONTO, CANADA

Post by daveon »

Hi,

I do not know pascal but here are some boundary IO's:

input:

Code: Select all

0
1
31
32
496
497
4991
4992
36456
36457
206367
206368
942648
942649
3572223
3572224
11460948
11460949
31621023
31621024
75973188
75973189
160645503
160645504
301766028
301766029
508019103
508019104
773201628
773201629
1073741823
1073741824
1374282018
1374282019
1639464543
1639464544
1845717618
1845717619
1986838143
1986838144
2071510458
2071510459
2115862623
2115862624
2136022698
2136022699
2143911423
2143911424
2146540998
2146540999
2147277279
2147277280
2147447190
2147447191
2147478655
2147478656
2147483150
2147483151
2147483615
2147483616
2147483646
2147483647

output:

Code: Select all

0
1
1073741824
3
1610612736
7
1879048192
15
2013265920
31
2080374784
63
2113929216
127
2130706432
255
2139095040
511
2143289344
1023
2145386496
2047
2146435072
4095
2146959360
8191
2147221504
16383
2147352576
32767
2147418112
65535
2147450880
131071
2147467264
262143
2147475456
524287
2147479552
1048575
2147481600
2097151
2147482624
4194303
2147483136
8388607
2147483392
16777215
2147483520
33554431
2147483584
67108863
2147483616
134217727
2147483632
268435455
2147483640
536870911
2147483644
1073741823
2147483646
2147483647
Bunda001
New poster
Posts: 6
Joined: Wed Jan 02, 2008 12:45 pm

Post by Bunda001 »

Hi, i would need that program - can someone please send here solved program in C++? thank you very much... or can send on Bunda001@seznam.cz
Post Reply

Return to “Volume 102 (10200-10299)”