tree_new_bee 发表于 2012-5-9 08:45 ![]()
恩, 这确实跟通常意义上说的“一笔画”不同, 所以不能用常用的"奇点数"的方法来判断。
原本我扩展这 ...
我提一个思路,就是之前说过的候选数法
首先改写一下找可用相邻数的sql,原先为- with t as (SELECT LEVEL n FROM DUAL CONNECT BY LEVEL<=:num)
- select t1.n, wm_concat(t2.n) from t t1, t t2
- where t1.n<>t2.n and t1.n+t2.n in (4,9,16,25,36,49,64,81) group by t1.n;
复制代码 改为- with nm as (select :num nm from dual),
- t as (SELECT LEVEL n FROM nm CONNECT BY LEVEL<=nm),
- t1 as (select power(level,2) pf from nm connect by level<=floor(sqrt(2*nm-1)))
- select n, wm_concat(pf-n) from t, t1 ,nm
- where t.n<t1.pf and greatest(t.n, pf-n)<=nm.nm and t.n*2<>t1.pf group by t.n;
复制代码 运行时输入num的值即可(此即为N值)
例如对于n=42,上述sql的结果为
N WM_CONCAT(PF-N)
1 3,35,24,15,8
2 7,34,23,14
3 1,33,22,13,6
4 5,32,21,12
5 4,31,20,11
6 3,30,19,10
7 2,42,29,18,9
8 1,41,28,17
9 7,40,27,16
10 6,39,26,15
11 5,38,25,14
12 4,37,24,13
13 3,36,23,12
14 2,35,22,11
15 1,34,21,10
16 9,33,20
17 8,32,19
18 7,31
19 6,30,17
20 5,29,16
21 4,28,15
22 3,42,27,14
23 2,41,26,13
24 1,40,25,12
25 11,39,24
26 10,38,23
27 9,37,22
28 8,36,21
29 7,35,20
30 6,34,19
31 5,33,18
32 4,17
33 3,31,16
34 2,30,15
35 1,29,14
36 13,28
37 12,27
38 11,26
39 10,42,25
40 9,41,24
41 8,40,23
42 7,39,22
|