Пример #1
0
func isSquareFree(n, k int64) bool {
	factors := euler.Factors(euler.Choose(n, k))
	for i := 0; i < len(factors); i++ {
		if factors[i][1] >= 2 {
			return false
		}
	}
	return true
}
Пример #2
0
func isSpecial(set []int) bool {
	for size := 2; size <= len(set); size++ {
		for i := 0; int64(i) < euler.Choose(int64(len(set)), int64(size)); i++ {
			brett, _ := euler.SplitInts(set, size, i)
			for k := 1; k <= len(brett)/2; k++ {
				for j := 0; int64(j) < euler.Choose(int64(len(brett)), int64(k)); j++ {
					a, b := euler.SplitInts(brett, k, j)
					if sum(a) == sum(b) {
						return false
					}
					if len(b) > len(a) && sum(a) > sum(b) {
						return false
					}
				}
			}
		}
	}
	return true
}
Пример #3
0
func main() {
	starttime := time.Now()

	row := int64(51)
	distinct := make(map[int64]bool)

	for n := int64(2); n < row; n++ {
		for k := int64(1); k < n; k++ {
			if isSquareFree(n, k) {
				distinct[euler.Choose(n, k)] = true
			}
		}
	}

	var total int64
	for key := range distinct {
		total += key
	}
	fmt.Println(total + 1)

	fmt.Println("Elapsed time:", time.Since(starttime))
}
Пример #4
0
func test(repeat string, n, d int) (N int, S int64) {

	for i := 0; int64(i) < euler.Choose(int64(n), int64(d)); i++ {
		indices := euler.SplitSeq(d, i)

		for j := 0; int64(j) < euler.IntExp(10, int64(d)); j++ {
			insertstring := strconv.Itoa(j)
			for len(insertstring) < d {
				insertstring = "0" + insertstring
			}

			merged := ""
			current := 0
			for index := 0; index < n; index++ {
				if current < d && index == indices[d-current-1] {
					merged += insertstring[current : current+1]
					current++
				} else {
					merged += repeat
				}
			}

			mergedint, _ := strconv.ParseInt(merged, 10, 64)

			//exclude leading zeroes
			if mergedint > euler.IntExp(10, int64(n)-1) {

				if euler.IsPrime(mergedint) {
					//fmt.Println(mergedint)
					N++
					S += mergedint
				}
			}
		}
	}
	return
}