二维数组

package main

import (
	"fmt"
	"math"
	"sync"
	"time"
)

var maxInt64Float float64
var maxNum int64
var resultChan chan bool
var wg sync.WaitGroup

func main() {
	startTime := time.Now()
	defer func() {
		cost := time.Since(startTime)
		fmt.Println("Run Time=", cost)
	}()
	resultChan = make(chan bool, 1)
	var numResult []int64
	numResult = append(numResult, 0)
	maxInt64Float = float64(math.MaxInt64)
	maxNum = int64(math.Pow(maxInt64Float, float64(1)/3))
	var i int64
	for i = 1; i <= maxNum; i++ {
		numResult = append(numResult, i*i*i)
	}

	size := maxNum / 10
	wg.Add(10)
	for start := int64(0); start < maxNum; start += size {
		end := start + size
		if end > maxNum {
			end = maxNum
		}
		if start < 3 {
			start = 3
		}
		go fermat(numResult, start, end)

	}
	wg.Wait()

}
func fermat(numResult []int64, start, end int64) {

	var n int64
	//升序排列前两个最小数没有可能 等于另外2个数相加和
	for n = start; n < end; n++ {
		fmt.Println("n=", n, "numResult[n]=", numResult[n])
		var i, j int64
		i = 1
		j = n - 1
		for i < j {
			if numResult[i]+numResult[j] == numResult[n] {
				resultChan <- true
				return
			}
			if numResult[i]+numResult[j] > numResult[n] {
				j--
			}
			if numResult[i]+numResult[j] < numResult[n] {
				i++
			}
		}
	}
	wg.Done()

}

  

上一篇:C# - VS2019 DataGridView导出到Excel的三种方法


下一篇:LeetCode 动态规划入门第7天