|
〇〇 发表于 2013-8-15 09:17 ![]()
每个平方数至少差7,要么差9,(36也不可能,所以最多差11不存在),因此若存在差11的第1个和第5个必须是一 ...
奇怪,怎么找不到匹配的
SQL> with t as(
2 select level-1 l from dual connect by level<=10
3 ),
4 t2 as(
5 select a.l||b.l||c.l||t.l c4
6 from t,t a,t b,t c where a.l+b.l+c.l+t.l in(9,16,25)
7 and a.l<>0
8 and find2(a.l||b.l||c.l||t.l)=1)
9 select count(a.c4||substr(t2.c4,1,1))
10 from t2,t2 a
11 where
12 substr(a.c4,2,3)=197 and
13 substr(t2.c4,1,3)=197;
COUNT(A.C4||SUBSTR(T2.C4,1,1))
------------------------------
0
已用时间: 00: 00: 02.08
SQL> with t as(
2 select level-1 l from dual connect by level<=10
3 ),
4 t2 as(
5 select a.l||b.l||c.l||t.l c4
6 from t,t a,t b,t c where a.l+b.l+c.l+t.l in(9,16,25)
7 and a.l<>0
8 and find2(a.l||b.l||c.l||t.l)=1)
9 select * from t2 where substr(t2.c4,1,3)=197;
C4
----------------------------------------------------------------
1978
已用时间: 00: 00: 00.03
SQL> 9
9* select * from t2 where substr(t2.c4,1,3)=197
SQL> c/1/2
9* select * from t2 where substr(t2.c4,2,3)=197
SQL> /
C4
----------------------------------------------------------------
8197
create or replace function find2(a varchar2)
return number
as
type tc is table of number index by varchar2(1);
c tc;
begin
for i in 0..9 loop
c(chr(ascii(0)+i)):=0;
end loop;
for i in 1..length(a) loop
c(substr(a,i,1)):=c(substr(a,i,1))+1;
if c(substr(a,i,1))>2 then
return 0;
end if;
end loop;
return 1;
end;
/ |
|