|
本帖最后由 〇〇 于 2022-12-5 14:50 编辑
发现一个规律,如果要求两两异或4个及以上1,那么选出来的4个数的异或结果为0
with recursive n as (select i-1 n from generate_series(1,64)t(i))
,b as (select 1<<(i-1) b from generate_series(1,6)t(i))
,p as(select n1.n n1,n2.n n2
,count(*) cnt
from n n1, n n2, b
where n1.n<n2.n
and (n1.n#n2.n)&b.b>0
group by n1.n ,n2.n
having count(*)>=4)
,t as(select 1 lv,array[n1,n2]a from p
union all
select lv+1,a||array[n] from t,n where a[lv+1]<n and lv+1= ( select count(*) from p q, unnest(a) u(c) where n1=c and n2=n)
)
select a from t where lv=3;
{13,16,38,59}
{13,16,42,55}
(240 行记录)
postgres=# select 13#16#42#55;
?column?
----------
0
(1 行记录)
postgres=# select 13#16#42;
?column?
----------
55
(1 行记录)
postgres=# select 13#16#38;
?column?
----------
59
(1 行记录)
with recursive n as (select i-1 n from generate_series(1,64)t(i))
,b as (select 1<<(i-1) b from generate_series(1,6)t(i))
,p as(select n1.n n1,n2.n n2
,count(*) cnt
from n n1, n n2, b
where n1.n<n2.n
and (n1.n#n2.n)&b.b>0
group by n1.n ,n2.n
having count(*)>=4)
,t as(select 1 lv,array[n1,n2]a from p
union all
select lv+1,a||array[n] from t,n where a[lv+1]<n and lv+1= ( select count(*) from p q, unnest(a) u(c) where n1=c and n2=n)
)
select distinct a[1]#a[2]#a[3]#a[4] from t where lv=3;
?column?
----------
0
(1 行记录)
|
|