Safe and Sophie Germain primes: Difference between revisions
Content added Content deleted
(Safe and Sophie Germain primes in various BASIC dialents) |
(Added Go) |
||
Line 273: | Line 273: | ||
wend |
wend |
||
end</lang> |
end</lang> |
||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
{{libheader|Go-rcu}} |
|||
<lang go>package main |
|||
import ( |
|||
"fmt" |
|||
"rcu" |
|||
) |
|||
func main() { |
|||
var sgp []int |
|||
p := 2 |
|||
count := 0 |
|||
for count < 50 { |
|||
if rcu.IsPrime(p) && rcu.IsPrime(2*p+1) { |
|||
sgp = append(sgp, p) |
|||
count++ |
|||
} |
|||
if p != 2 { |
|||
p = p + 2 |
|||
} else { |
|||
p = 3 |
|||
} |
|||
} |
|||
fmt.Println("The first 50 Sophie Germain primes are:") |
|||
for i := 0; i < len(sgp); i++ { |
|||
fmt.Printf("%5s ", rcu.Commatize(sgp[i])) |
|||
if (i+1)%10 == 0 { |
|||
fmt.Println() |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
The first 50 Sophie Germain primes are: |
|||
2 3 5 11 23 29 41 53 83 89 |
|||
113 131 173 179 191 233 239 251 281 293 |
|||
359 419 431 443 491 509 593 641 653 659 |
|||
683 719 743 761 809 911 953 1,013 1,019 1,031 |
|||
1,049 1,103 1,223 1,229 1,289 1,409 1,439 1,451 1,481 1,499 |
|||
</pre> |
|||
=={{header|jq}}== |
=={{header|jq}}== |