예제 #1
0
func main() {
	flag.Parse()
	if len(flag.Args()) != 1 {
		fmt.Println("usage: Problem268 <integer>")
		os.Exit(1)
	}
	n, err := strconv.ParseInt(flag.Arg(0), 10, 64)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	primes := library.Sieve(100)
	tuples := make([]map[int64]bool, 0, 4)
	tup := make(map[int64]bool, 0)
	for _, p := range primes {
		tup[p] = true
	}
	tuples = append(tuples, tup)
	for i := 1; i <= 3; i++ {
		tup := make(map[int64]bool, 0)
		for _, p := range primes {
			for t, _ := range tuples[i-1] {
				if t%p != 0 {
					tup[t*p] = true
				}
			}
		}
		tuples = append(tuples, tup)
	}
	for t, _ := range tuples[3] {
		factors := library.CanonicalForm(t)
		fmt.Println(t, factors)
	}
	fmt.Println(n)
}
예제 #2
0
func main() {
	flag.Parse()
	if len(flag.Args()) != 1 {
		fmt.Println("usage: Problem5 <integer>")
		os.Exit(1)
	}
	n, err := strconv.ParseInt(flag.Arg(0), 10, 64)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	powers := make(map[int64]int, 0)
	var i int64
	for i = 2; i < n; i++ {
		factors := library.CanonicalForm(i)
		for prime, power := range factors {
			p, present := powers[prime]
			if present {
				if power > p {
					powers[prime] = power
				}
			} else {
				powers[prime] = power
			}
		}
	}
	var answer int64 = 1
	for prime, power := range powers {
		answer *= int64(math.Pow(float64(prime), float64(power)))
	}
	fmt.Println(answer)
}
예제 #3
0
func main() {
	flag.Parse()
	if len(flag.Args()) != 1 {
		fmt.Println("usage: Problem3 <integer>")
		os.Exit(1)
	}
	target, error := strconv.ParseInt(flag.Arg(0), 10, 64)
	if error != nil {
		fmt.Println(error)
		os.Exit(1)
	}
	factorization := library.CanonicalForm(target)
	var max int64
	for prime, _ := range factorization {
		if prime > max {
			max = prime
		}
	}
	fmt.Println(max)
}