Source

euler / go / 3.go

/*
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Answer: 6857
*/
package main

import (
	"big"
	"fmt"
	"math"
)

const (
	n = 600851475143
)

func main() {
	for start := int64(math.Sqrt(n)); start > 0; start-- {
		if !big.ProbablyPrime(big.NewInt(start), 10) {
			continue
		}
		if n%start == 0 {
			fmt.Println(start)
			break
		}
	}
}