Jump to content
IPS Community Suite 简体中文
Sign in to follow this  
ipscn

Q5

Recommended Posts

已知: 可被数集[1,10]上的所有整数整除的最小正数是2520;
那么,可以能被数集[1,10]上的所有整数整除的最小正数是多少?

未支持并发的Go语言版本

package main

import (
	"fmt"
	"math/big"
)

func isPrimeNumber(intV int64) bool {

	return big.NewInt(intV).ProbablyPrime(0)

}

func GetPrimeNumberListElThan(intV int64) []int64 {

	var i int64 = 1
	var r []int64
	for ; i <= intV; i++ {

		if isPrimeNumber(i) {
			r = append(r, i)
		}
	}

	return r
}

func GetMinNumberCanBeDividedAllNumberElThan(intV int64) int64 {

	var result int64 = 1
	var div int64
	var primes []int64 = GetPrimeNumberListElThan(intV)
	for i := range primes {
		div = primes[i]
		for div <= intV {
			div *= primes[i]
		}
		div /= primes[i]
		result *= div
	}

	return result
}

func main() {

	var intV int64 = 20

	//fmt.Println(GetPrimeNumberListElThan(intV))

	fmt.Println(GetMinNumberCanBeDividedAllNumberElThan(intV))

}

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×