微软SQL服务器,826个 786 *字节
*我回想起了Microsoft Sql Server 2012中引入的IIF函数
set nocount on
use rextester
go
if object_id('dbo.n','IF')is not null drop function dbo.n
go
create function dbo.n(@ bigint,@f bigint)returns table as return
with a as(select 0 c union all select 0),b as(select 0 c from a,a t),c as(select 0 c from b,b t),
d as(select 0 c from c,c t),e as(select 0 c from d,d t),f as(select 0 c from e,e t),
v as(select top(@f-@+1)0 c from f)select row_number()over(order by(select 0))+@-1 n from v
go
with u as(select cast(a as bigint)a from(values(11),(11431),(13201),(13360),(13450),(1019410),(1019510),(22),(1431),
(15621),(14641))u(a)),v as(select a,a c from u union all select a,c+reverse(str(c,38))from v
where 0=any(select c%n from dbo.n(2,c/2))and c%11>0)select a,iif(0=any(select max(c)%n from dbo.n(2,max(c)/2)),0,1)
from v group by a option(maxrecursion 0)
在线检查
更整齐的格式
SET NOCOUNT ON;
USE rextester;
GO
IF OBJECT_ID('dbo.n', 'IF') IS NOT NULL DROP FUNCTION dbo.n;
GO
CREATE FUNCTION dbo.n(@ BIGINT,@f BIGINT)RETURNS TABLE AS RETURN
WITH
a AS(SELECT 0 c UNION ALL SELECT 0),
b AS(SELECT 0 c FROM a,a t),
c AS(SELECT 0 c FROM b,b t),
d AS(SELECT 0 c FROM c,c t),
e AS(SELECT 0 c FROM d,d t),
f AS(SELECT 0 c FROM e,e t),
v AS(SELECT TOP(@f-@+1)0 c FROM f)
SELECT ROW_NUMBER()OVER(ORDER BY(SELECT 0))+@-1 n FROM v;
GO
WITH u AS(
SELECT CAST(a AS BIGINT) a
FROM(VALUES (11), (11431), (13201), (13360), (13450), (1019410), (1019510),
(22), (1431), (15621), (14641)) u(a)
),
v AS(
SELECT a, a c FROM u
UNION ALL
SELECT a, c + reverse(str(c, 38))
FROM v
WHERE 0 = ANY(SELECT c % n FROM dbo.n(2, c / 2)) AND c % 11 > 0
)
SELECT a, IIF(0 = ANY(SELECT MAX(c) % n FROM dbo.n(2, MAX(c) / 2)), 0, 1)
FROM v
GROUP BY a
OPTION (MAXRECURSION 0);