需求
两个0-10000的数组,循环遍历两个数组,获取两个元素,打印出乘积为56213的所有元素
Python实现
import datetime
s = datetime.datetime.now()
for i in range(10000):
for j in range(10000):
if i * j == 56213:
print(f"{i} * {j} = {i * j}")
print(datetime.datetime.now() - s)
# 结果
# 67 * 839 = 56213
# 839 * 67 = 56213
# 0:00:09.320285
Go实现
package main
import (
"fmt"
"time"
)
func generateList(n int) []int {
list := make([]int, n+1)
for i := 0; i <= n; i++ {
list[i] = i
}
return list
}
func main() {
start := time.Now()
list1 := generateList(10000)
list2 := generateList(10000)
for _, n1 := range list1 {
for _, n2 := range list2 {
if n1*n2 == 56213 {
fmt.Printf("%d * %d = 56213 \n", n1, n2)
}
}
}
fmt.Println(time.Now().Sub(start))
}
# 结果
# 67 * 839 = 56213
# 839 * 67 = 56213
# 66.757ms
标签:10000,Python,datetime,56213,int,多少倍,Go
From: https://www.cnblogs.com/JentZhang/p/17712843.html