The problem below is an extension of a problem I did on brillant.
Let 3 7 = ( a n a n − 1 . . . a 0 ) 3 4 = ( b m b m − 1 . . . b 0 ) 2 3 where ( 0 ≤ a j ≤ 3 ) for ( 0 ≤ j ≤ n ) and ( 0 ≤ b j ≤ 2 ) for ( 0 ≤ j ≤ m ) .
Find j = 0 ∑ n a j + j = 0 ∑ m b j .
Note: Find a general algorithm to write integer expansions in fractional bases whose fractions are improper fractions.
Let A = 1 0 , B = 1 1 , C = 1 2 , D = 1 3 , E = 1 4 and F = 1 5 .
Bonus: Write a program using the algorithm above to represent 1 2 3 4 5 6 7 8 9 in base 1 1 1 6 .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
The simple algorithm below generates the conversion:
To calculate: [ M ] b a , where ( a > b ) .
Let S 1 = M
Repeat
r n = S n m o d a
q n = S n d i v a
S n + 1 = b ∗ q n
Go until S n + 1 < a .
Using the algorithm above:
For ( 3 7 ) 3 4 :
3 7 → 2 7 1 → 1 8 3 1 → 1 2 2 3 1 → 9 0 2 3 1 → 6 1 0 2 3 1 → 3 2 1 0 2 3 1
For ( 3 7 ) 2 3 :
3 7 → 2 4 1 → 1 6 0 1 → 1 0 1 0 1 → 6 1 1 0 1 → 4 0 1 1 0 1 → 2 1 0 1 1 0 1
⟹ ∑ j = 0 6 a j + ∑ j = 0 6 b j = 1 8 .
Below is a program I wrote in Free Pascal::
program fractionalbase;
var myfile:text;
procedure change(var k:string);
begin IF K = '10' THEN K:= 'A';
IF K = '11' THEN K:= 'B';
IF K = '12' THEN K:= 'C';
IF K = '13' THEN K:= 'D';
IF K = '14' THEN K:= 'E';
IF K = '15' THEN K:= 'F';
end;
function fractbase(n,a,b:longint):string;
type myarray = array[1 .. 100] of longint;
var q,s,count,m:longint;
r:myarray;
strvar,strsum:string;
begin
s:= n;
count:= 1;
repeat
r[count]:= s mod a;
q:= s div a;
s:= b * q;
count:= count + 1;
until(s < a);
r[count]:= s mod a;
strsum:= '';
for m:= 1 to count do
begin
str(r[m],strvar);
if r[m] > 9 then
change(strvar);
strsum:= strvar + strsum;
end;
fractbase:= strsum;
end;
begin
assign(myfile,'fract.txt');
rewrite(myfile);
writeln(myfile,fractbase(123456789,16,11));
close(myfile);
readln;
end.
Running the above program we obtain:
( 1 2 3 4 5 6 7 8 9 ) 1 0 = ( B 6 C 2 3 A 7 5 A C C 6 7 2 C 6 A 6 4 2 C C 9 F 1 1 D 9 0 6 1 C F C 3 C 6 E A 5 B 5 ) 1 1 1 6
Below is a program I wrote in Python:
The module below contains the majority of the program: I wrote the module so I could use the function when needed.
import math;
def power(base,exponent):
product = 1;
n=1;
while n <= exponent:
product = product * base;
n = n + 1;
power = product
return power;
def change(k):
if k == 10:
k = 'A'
if k == 11:
k = 'B'
if k == 12:
k = 'C'
if k == 13:
k = 'D'
if k == 14:
k = 'E'
if k == 15:
k = 'F'
if k == 16:
k = 'G'
change = k
return change;
import array
array.array('i')
r = array.array('i',(0 for i in range(0,1000)))
def fractbase(n,a,b):
s = n;
count = 1;
while s >= a:
r[count] = s % a;
q = math.floor(s/a);
s = b * q;
count = count + 1;
r[count] = s % a;
strsum = '';
for m in range(-count,0):
if r[-m] > 9:
strsum = strsum + change(r[-m])
else:
strsum = strsum + str(r[-m]);
fractbase = strsum;
return fractbase;
Calling the function::
print(mathunit.fractbase(123456789,16,11));
Running the above program we obtain:
( 1 2 3 4 5 6 7 8 9 ) 1 0 = ( B 6 C 2 3 A 7 5 A C C 6 7 2 C 6 A 6 4 2 C C 9 F 1 1 D 9 0 6 1 C F C 3 C 6 E A 5 B 5 ) 1 1 1 6
@Rocco Dalto , a nice problem. The bonus part, it should be converting 1 2 3 4 5 6 7 8 9 1 0 to base 1 1 1 6 . and not 1 2 3 4 5 6 7 8 9 1 1 1 6 .
Problem Loading...
Note Loading...
Set Loading...
Let the initial decimal integer be k 0 and the improper fractional base be q p , where p and q are positive coprime integers with p > q . Then the j th digit a j is given by:
a j = k j m o d p where k j = q ⌊ p k j − 1 ⌋ for j ≥ 1
Let us use the formulas above to solve for k 0 = 3 7 , p = 4 , and q = 3 .
\(\begin{array} {} j= 0 & k_0 =37 & \implies a_0 = 37 \bmod 4 = 1 \\ j = 1 & k_1 = 3 \left \lfloor \dfrac {37}4 \right \rfloor = 27 & \implies a_1 = 27 \bmod 4 = 3 \\ j = 2 & k_2 = 3 \left \lfloor \dfrac {27}4 \right \rfloor = 18 & \implies a_2 = 18 \bmod 4 = 2 \\ j = 3 & k_3 = 3 \left \lfloor \dfrac {18}4 \right \rfloor = 12 & \implies a_3 = 12 \bmod 4 = 0 \\ j = 4 & k_4 = 3 \left \lfloor \dfrac {12}4 \right \rfloor = 9 & \implies a_4 = 9 \bmod 4 = 1 \\ j = 5 & k_5 = 3 \left \lfloor \dfrac 94 \right \rfloor = 6 & \implies a_5 = 6 \bmod 4 = 2 \\ j = 6 & k_6 = 3 \left \lfloor \dfrac 64 \right \rfloor = 3 & \implies a_6 = 3 \bmod 4 = 3 \\ j = 5 & k_7 = 3 \left \lfloor \dfrac 34 \right \rfloor = 0 & \implies a_7 = 0 \bmod 4 = 0 \end{array} \)
⟹ 3 7 1 0 = 1 3 2 0 1 2 3 3 4 , Similarly, 3 7 1 0 = 1 0 1 1 0 1 2 2 3 . Therefore, j = 0 ∑ 6 a j + j = 0 ∑ 6 b j = 1 2 + 6 = 1 8 .
The above formula or algorithm can be readily implemented with a Microsoft Excel spreadsheet, using functions =INT( _ ) for ⌊ ⋅ ⌋ , the floor function and =MOD( _ , _ ) for ⋅ m o d ⋅ , the modulo operation . My spreadsheet is as follows. And 1 2 3 4 5 6 7 8 9 1 0 = B6C23A75ACC672C6A642CC9F11D9061CFC3C6EA5B5 1 1 1 6 .