Find adjacent primes which differ by a square integer: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Added Go) |
||
Line 475: | Line 475: | ||
981823 981887 64 |
981823 981887 64 |
||
997813 997877 64 |
997813 997877 64 |
||
</pre> |
|||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
{{libheader|Go-rcu}} |
|||
<lang go>package main |
|||
import ( |
|||
"fmt" |
|||
"math" |
|||
"rcu" |
|||
) |
|||
func main() { |
|||
limit := 999999 |
|||
primes := rcu.Primes(limit) |
|||
fmt.Println("Adjacent primes under 1,000,000 whose difference is a square > 36:") |
|||
for i := 1; i < len(primes); i++ { |
|||
diff := primes[i] - primes[i-1] |
|||
if diff > 36 { |
|||
s := int(math.Sqrt(float64(diff))) |
|||
if diff == s*s { |
|||
cp1 := rcu.Commatize(primes[i]) |
|||
cp2 := rcu.Commatize(primes[i-1]) |
|||
fmt.Printf("%7s - %7s = %3d = %2d x %2d\n", cp1, cp2, diff, s, s) |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Same as Wren example. |
|||
</pre> |
</pre> |
||