RosettaCodeData/Task/Babbage-problem/Go/babbage-problem.go

21 lines
412 B
Go
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
package main
import "fmt"
func main() {
2026-02-01 16:33:20 -08:00
const (
target = 269696
modulus = 1000000
)
for n := 1; ; n++ { // Repeat with n=1, n=2, n=3, ...
square := n * n
ending := square % modulus
if ending == target {
fmt.Println("The smallest number whose square ends with",
target, "is", n,
)
return
}
}
2023-07-01 11:58:00 -04:00
}