Giuga numbers: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
(Added Go) |
||
Line 25: | Line 25: | ||
<br><br> |
<br><br> |
||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
{{libheader|Go-rcu}} |
|||
<lang go>package main |
|||
import ( |
|||
"fmt" |
|||
"rcu" |
|||
) |
|||
func main() { |
|||
const limit = 4 |
|||
var giuga []int |
|||
for n := 4; len(giuga) < limit; n += 2 { |
|||
factors := rcu.PrimeFactors(n) |
|||
if len(factors) > 2 { |
|||
isSquareFree := true |
|||
for i := 1; i < len(factors); i++ { |
|||
if factors[i] == factors[i-1] { |
|||
isSquareFree = false |
|||
break |
|||
} |
|||
} |
|||
if isSquareFree { |
|||
isGiuga := true |
|||
for _, f := range factors { |
|||
if (n/f-1)%f != 0 { |
|||
isGiuga = false |
|||
break |
|||
} |
|||
} |
|||
if isGiuga { |
|||
giuga = append(giuga, n) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
fmt.Println("The first", limit, "Giuga numbers are:") |
|||
fmt.Println(giuga) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
The first 4 Giuga numbers are: |
|||
[30 858 1722 66198] |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |