Last active
August 2, 2017 14:40
-
-
Save gt50/1713b1310be54bbfdf46d079c850436d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Enter your query here. | |
Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. | |
*/ | |
declare @maxprime int | |
declare @i int | |
declare @j int | |
declare @answer varchar | |
declare @isprime bit | |
set @maxprime = 10 | |
set @i = 1 | |
set @answer = '&' | |
while @i <=@maxprime | |
begin | |
print @answer | |
set @isprime = 1 | |
set @j = floor(sqrt(@i)) | |
while @j > 1 | |
begin | |
if (@i % @j = 0) set @isprime = 0 | |
set @j = @j - 1 | |
end | |
--print cast(@i as varchar) + ' ' + cast(@isprime as varchar) | |
if (@isprime = 1) | |
begin | |
--print @answer + cast(@i as varchar) | |
set @answer += @i--set @primes = @primes + cast(@i as varchar) + '&' | |
end | |
set @i = @i + 1 | |
end | |
print @answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment