Example #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)
}
Example #2
0
func main() {
	flag.Parse()
	if len(flag.Args()) != 1 {
		fmt.Println("usage: Problem10 <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(n)
	var sum int64 = 0
	for _, p := range primes {
		sum += p
	}
	fmt.Println(sum)
}
Example #3
0
func main() {
	flag.Parse()
	if len(flag.Args()) != 1 {
		fmt.Println("usage: Problem7 <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(n)
	if len(primes) > 10001 {
		// primes[0] is the first prime, so we're off by one.
		fmt.Printf("10001st prime: %d.\n", primes[10000])
	} else {
		fmt.Printf("Only %d primes up to %d.\n", len(primes), n)
	}
}