Sort by

recency

|

1298 Discussions

|

  • + 0 comments

    WITH RECURSIVE numbers AS( SELECT 2 AS num UNION ALL SELECT num + 1 FROM numbers WHERE num < 1000 ), Prime AS ( SELECT num FROM numbers n WHERE NOT EXISTS( SELECT 1 FROM numbers n1 WHERE n.num % d.n1.num = 0 AND n.num != n1.num ) )

    SELECT GROUP_CONCAT(num SEPARATOR '&') AS pnumbers FROM Prime;

  • + 0 comments

    with seq as (select level l1 from dual where level>1 connect by level<=1000) select listagg(s1.l1,'&')within group(order by s1.l1) from seq s1 where not exists (select 1 from seq s2 where s2.l1<=sqrt(s1.l1) and mod(s1.l1,s2.l1)=0);

  • + 0 comments

    DELIMITER // CREATE PROCEDURE p1(IN n INT) BEGIN DECLARE i INT DEFAULT 3; DECLARE result VARCHAR(10000) DEFAULT '2'; DECLARE flag INT DEFAULT 0; DECLARE j INT; loop1:LOOP SET flag = 0; SET j = i; loop2:LOOP SET j = j-1; IF j = 1 THEN LEAVE loop2; END IF; IF i%j = 0 THEN SET flag = 1; LEAVE loop2; END IF; END LOOP loop2; IF flag = 0 THEN SET result = CONCAT(result,'&',i); END IF; IF i = n THEN LEAVE loop1; END IF; SET i = i+1; END LOOP loop1; SELECT result; END // DELIMITER ;

    CALL p1(1000);

  • + 0 comments

    -----------------sql server--------------------- declare @x int; declare @y int; declare @z int; declare @count int; declare @output NVARCHAR(MAX) = ''; SET @z = 1000; SET @x = 2; SET @y = 2; SET @count = 0;

    while @x < 1000 begin while @y <= floor(sqrt(@x)) begin if @x % @y = 0 begin SET @count = @count + 1; break; end; SET @y = @y + 1; end; if @count = 0 begin SET @output = CONCAT(@output, CAST(@x as varchar), '&');

    end;
    SET @y = 2;
    SET @x = @x + 1 ;
    SET @count = 0;
    

    end;

    SET @output = LEFT(@output, LEN(@output) - 1); print @output;

  • + 0 comments

    declare @PrimeNumCnt Int = 1, @PrimeNumUpTo int = 1000, @PrimeNumList nvarchar(4000); while @PrimeNumCnt <= @PrimeNumUpTo begin declare @IsPrime int = 0 Declare @N int = 1 while @N <= @PrimeNumCnt begin set @IsPrime = @IsPrime + (select case when @PrimeNumCnt <> @N and @PrimeNumCnt % @N = 0 then 1 else 0 end) if @IsPrime = 0 begin break end set @N = @N+1 end --select @PrimeNumCnt,@IsPrime if @IsPrime = 1 begin set @PrimeNumList = (select concat(@PrimeNumList,'&',@PrimeNumCnt)) end set @PrimeNumCnt = @PrimeNumCnt+1 end select right(@PrimeNumList,len(@PrimeNumList)-1);