Think of this problem as an extension to
Repeating decimals.
Determine the minimum value of base 14 positive integer q such that the tetradecimal representation of 1/q has a repetition length of n for each of {1, 2, ..., 9, A, B, C, D, 10}
Is there a simple way of finding such a number?
The explanation, or method, is based on the solution to the older problem, but instead of using 9 and repeated 9's, use 1 less than the base, whatever that is -- in this case 13, one less than 14.
clearvars,clc
b=(14);
p=sym(b); pow=(1); didThat=[]; donep=repmat(false,1,20);
while p<b^17
divs=divisors(p-1);
for s=length(divs)-1:-1:1
if ismember((p-1)/divs(s),didThat)
didThat(end+1)= (p-1)/divs(s);
continue
end
didThat(end+1)=(p-1)/divs(s);
if donep(pow)==false
disp([string(pow) string((p-1)/divs(s)) dec2bse(eval((p-1)/divs(s)),b) string(divs(s)) dec2bse(eval(divs(s)),b,pow)])
end
donep(pow)=true;
end
pow=pow+1;
p=p*b;
end
where dec2bse is a replacement for the builtin function dec2base, as the latter can't handle numbers larger than the maximum integer even if the variable is a sym. The dec2bse function is:
function inbase=dec2bse(d,b,minlen)
outval=''; s='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
d2=d;
while d2>0
r=mod(d2,b);
outval=[s(r+1) outval];
d2=(d2-r)/b;
end
if ~exist('minlen','var')
minlen=1;
end
if length(outval)<minlen
outval=[repmat('0',1,minlen-length(outval)) outval];
end
inbase=outval;
end
"1" "13" "D" "1" "1"
"2" "3" "3" "65" "49"
"3" "211" "111" "13" "00D"
"4" "197" "101" "195" "00DD"
"5" "11" "B" "48893" "13B65"
"6" "9" "9" "836615" "17AC63"
"7" "8108731" "1111111" "13" "000000D"
"8" "41" "2D" "35994855" "04ACD931"
"9" "397" "205" "52042939" "006CAA12B"
"10" "25" "1B" "11570186199" "07BA8D6235"
"11" "67" "4B" "60441271189" "02CD531C485"
"12" "37" "29" "1532267902035" "05423AD89BA3"
"13" "157" "B3" "5055508109899" "013698B8415D9"
"14" "7027567" "D0D0D1" "1581202545" "0000010DDDDDCD"
"15" "31" "23" "5018325663155233" "0647323881B40C9"
"16" "17" "13" "128114902224080655" "0B75A9C4D2683419"
>>
cycle divisor (q) repeated value
length ---------------------- ----------------------------------
decimal base-14 decimal base 14
1 13 D 1 1
2 3 3 65 49
3 211 111 13 00D
4 197 101 195 00DD
5 11 B 48893 13B65
6 9 9 836615 17AC63
7 8108731 1111111 13 000000D
8 41 2D 35994855 04ACD931
9 397 205 52042939 006CAA12B
10 25 1B 11570186199 07BA8D6235
11 67 4B 60441271189 02CD531C485
12 37 29 1532267902035 05423AD89BA3
13 157 B3 5055508109899 013698B8415D9
14 7027567 D0D0D1 1581202545 0000010DDDDDCD
15 31 23 5018325663155233 0647323881B40C9
16 17 13 128114902224080655 0B75A9C4D2683419
|
Posted by Charlie
on 2022-10-25 13:29:52 |