A340069
a(n) is the smallest number k not yet used such that the number of 1-bits in the binary representation of k equals the number of 1-bits in the binary representation of k*n.
Original entry on oeis.org
0, 1, 2, 3, 4, 7, 6, 14, 5, 15, 27, 12, 24, 10, 19, 30, 8, 31, 43, 28, 39, 13, 35, 45, 48, 62, 20, 57, 37, 63, 60, 79, 9, 126, 91, 11, 86, 29, 56, 23, 54, 75, 26, 51, 70, 46, 47, 22, 89, 21, 93, 83, 40, 61, 114, 78, 38, 18, 71, 87, 77, 42, 124, 127, 16, 254, 187, 92, 151, 90, 44, 58, 117
Offset: 0
-
function a = A340069( max_n )
a(1) = 1;
n = 2;
t = 1;
while n <= max_n
% search next number t not yet used in a
while ~isempty(find(a==t, 1))
t = t+1;
end
bits1 = length(find(bitget(t,1:32)== 1));
bits2 = length(find(bitget(t*n,1:32)== 1));
if (bits1 == bits2)
% we found a candidate
a(n) = t;
t = 1;
n = n+1;
else
% number t does not yet fit
t = t+1;
end
end
end
-
lista(nn) = {my(va = vector(nn, k, -1)); for (n=0, nn-1, my(k=0); while(! ((hammingweight(k*n) == hammingweight(k)) && !(#select(x->(x==k), va))), k++); va[n+1] = k;); va;} \\ Michel Marcus, Dec 30 2020
-
def binwt(n): return bin(n).count('1')
def aupto(n):
alst, aset = [], set()
for k in range(n+1):
ak = 0
while True:
while ak in aset: ak += 1
if binwt(ak)==binwt(k*ak): break
ak += 1
alst.append(ak)
aset.add(ak)
return alst
print(aupto(72)) # Michael S. Branicky, Jan 02 2021
A340351
Square array, read by descending antidiagonals, where row n gives all solutions k > 0 to A000120(k)=A000120(k*n), A000120 is the Hamming weight.
Original entry on oeis.org
1, 2, 1, 3, 2, 3, 4, 3, 6, 1, 5, 4, 7, 2, 7, 6, 5, 12, 3, 14, 3, 7, 6, 14, 4, 15, 6, 7, 8, 7, 15, 5, 27, 7, 14, 1, 9, 8, 24, 6, 28, 12, 15, 2, 15, 10, 9, 28, 7, 30, 14, 19, 3, 30, 7, 11, 10, 30, 8, 31, 15, 28, 4, 31, 14, 3, 12, 11, 31, 9, 39, 24, 30, 5, 43, 15, 6, 3, 13, 12
Offset: 1
Eight initial terms of rows 1 - 8 are listed below:
1: 1, 2, 3, 4, 5, 6, 7, 8, ...
2: 1, 2, 3, 4, 5, 6, 7, 8, ...
3: 3, 6, 7, 12, 14, 15, 24, 28, ...
4: 1, 2, 3, 4, 5, 6, 7, 8, ...
5: 7, 14, 15, 27, 28, 30, 31, 39, ...
6: 3, 6, 7, 12, 14, 15, 24, 28, ...
7: 7, 14, 15, 19, 28, 30, 31, 37, ...
8: 1, 2, 3, 4, 5, 6, 7, 8, ...
a(6,3) = 7 because: 7 in binary is 111 and 6*7 = 42 in binary is 101001, both have 3 bits set to 1.
-
function [a] = A340351(max_n)
for n = 1:max_n
m = 1;
k = 1;
while m < max_n
c = length(find(bitget(k,1:32)== 1));
if c == length(find(bitget(n*k,1:32)== 1))
a(n,m) = k;
m = m+1;
end
k = k +1;
end
end
end
A295827
a(n) = least odd k > 1 such that n and n*k have the same Hamming weight, or -1 if no such k exists.
Original entry on oeis.org
-1, -1, 3, -1, 13, 3, 3, -1, 57, 13, 35, 3, 21, 3, 3, -1, 241, 57, 7, 13, 13, 35, 39, 3, 169, 21, 5, 3, 21, 3, 3, -1, 993, 241, 11, 57, 7, 7, 5, 13, 3197, 13, 9, 35, 3, 39, 13, 3, 21, 169, 3, 21, 39, 5, 47, 3, 27, 21, 5, 3, 13, 3, 3, -1, 4033, 993, 491, 241
Offset: 1
The first terms, alongside the binary representations of n and of n*a(n), are:
n a(n) bin(n) bin(n*a(n))
-- ---- ------ -----------
1 -1 1 -1
2 -1 10 -10
3 3 11 1001
4 -1 100 -100
5 13 101 1000001
6 3 110 10010
7 3 111 10101
8 -1 1000 -1000
9 57 1001 1000000001
10 13 1010 10000010
11 35 1011 110000001
12 3 1100 100100
13 21 1101 100010001
14 3 1110 101010
15 3 1111 101101
16 -1 10000 -10000
17 241 10001 1000000000001
18 57 10010 10000000010
19 7 10011 10000101
20 13 10100 100000100
-
f:= proc(n) local k,w;
if n = 2^padic:-ordp(n,2) then return -1 fi;
w:= convert(convert(n,base,2),`+`);
for k from 3 by 2 do
if convert(convert(n*k,base,2),`+`)=w then return k fi
od
end proc:
map(f, [$1..100]); # Robert Israel, Nov 28 2017
-
Table[SelectFirst[Range[3, 10^4 + 1, 2], SameQ @@ Map[DigitCount[#, 2, 1] &, {n, n #}] &] /. m_ /; MissingQ@ m -> -1, {n, 68}] (* Michael De Vlieger, Nov 28 2017 *)
-
A057168(n)=n+bitxor(n, n+n=bitand(n, -n))\n\4+n \\ after M. F. Hasler at A057168
a(n) = n\=2^valuation(n,2); if (n==1, -1, my(w=(n-1)/2); while(1, w=A057168(w); if((2*w+1)%n==0, return((2*w+1)/n))))
-
def A295827(n):
if not(n&-n)^n: return -1
m = n
while True:
m = m^((a:=-m&m+1)|(a>>1)) if m&1 else ((m&~(b:=m+(a:=m&-m)))>>a.bit_length())^b
a, b = divmod(m,n)
if not b and a&1: return a # Chai Wah Wu, Mar 11 2025
A162215
a(n) is the smallest multiple of n that is greater than 2n and contains the same number of 1's in its binary representation as n contains.
Original entry on oeis.org
4, 8, 9, 16, 20, 18, 21, 32, 36, 40, 44, 36, 52, 42, 45, 64, 68, 72, 76, 80, 84, 88, 92, 72, 100, 104, 108, 84, 116, 90, 93, 128, 132, 136, 140, 144, 148, 152, 156, 160, 164, 168, 172, 176, 135, 184, 188, 144, 196, 200, 153, 208, 212, 216, 220, 168, 228, 232, 236
Offset: 1
15 in binary is 1111, which contains four 1's as binary digits. 15*3 = 45, which is 101101 in binary. This also contains four 1's. So a(15) = 3*15 = 45.
-
A000120 := proc(n) add(d,d=convert(n,base,2)) ; end: A162215 := proc(n) local k; for k from 3 do if A000120(k*n)= A000120(n) then RETURN(k*n) ; fi; od: end: seq(A162215(n),n=1..80) ; # R. J. Mathar, Jul 04 2009
-
Array[Block[{k = 3, d = DigitCount[#, 2, 1]}, While[DigitCount[k #, 2, 1] != d, k++]; k #] &, 59] (* Michael De Vlieger, Feb 24 2019 *)
a(4) corrected and sequence extended by
R. J. Mathar, Jul 04 2009
A340349
a(n) is the smallest k such that A292849(k) = 2n-1.
Original entry on oeis.org
1, 3, 13, 5, 57, 35, 21, 9, 241, 219, 49, 45, 169, 83, 73, 17, 993, 59, 941, 53, 3197, 51, 185, 93, 209, 81, 349, 85, 41, 89, 105, 33, 4033, 491, 4749, 247, 449, 227, 429, 363, 3249, 401, 193, 259, 233, 107, 117, 189, 697249, 1355, 173, 517, 473, 1091, 101, 231, 725, 305
Offset: 1
-
function a = A340349(maxA292849)
c = A340351(maxA292849,1);
n = 1; run = 1;
while run == 1
i = find(c==(n*2)-1);
if ~isempty(i);
a(n) = i(1);
n = n+1;
else
run = 0;
end
end
end
function a = A340351(max_n,max_m)
for n = 1:max_n
m = 1; k = 1;
while m < max_m+1
c = length(find(bitget(k,1:32)== 1));
if c == length(find(bitget(n*k,1:32)== 1))
a(n,m) = k;
m = m+1;
end
k = k +1;
end
end
end
-
f(n) = my(k=1); while ((hammingweight(k)) != hammingweight(k*n), k++); k; \\ A292849
a(n) = my(k=1); while(f(k) != 2*n-1, k++); k; \\ Michel Marcus, Jan 09 2021
A381754
Numbers k such that k and 3*k have the same number of zeros in their binary expansions.
Original entry on oeis.org
0, 1, 2, 4, 8, 16, 19, 32, 35, 38, 39, 53, 64, 67, 70, 71, 76, 78, 79, 101, 105, 106, 117, 128, 131, 134, 135, 140, 142, 143, 152, 156, 158, 159, 197, 201, 202, 209, 210, 212, 229, 233, 234, 245, 256, 259, 262, 263, 268, 270, 271, 280, 284, 286, 287, 301, 304
Offset: 1
-
filter:= proc(n) numboccur(0,convert(n,base,2)) = numboccur(0,convert(3*n,base,2)) end proc:
select(filter, [$0..400]); # Robert Israel, Apr 07 2025
-
Select[Range[0, 320], Equal @@ DigitCount[{#, 3*#}, 2, 0] &] (* Amiram Eldar, Mar 06 2025 *)
-
nz(n) = if(n == 0, 1, 1+logint(n, 2) - hammingweight(n))
is(n)=nz(n)==nz(3*n) \\ Charles R Greathouse IV, Mar 06 2025
-
def ok(n): return bin(n).count('0') == bin(n * 3).count('0')
Showing 1-6 of 6 results.
Comments