Esempio n. 1
0
// Divisors returns int64 slice of divisors of n
func Divisors(n int64) []int64 {
	f, t := []int64{}, int64(math.Sqrt(float64(n)))

	for i := int64(1); i <= t; i++ {
		if n%i == 0 {
			f = append(f, i)
			if i*i != n {
				f = append(f, n/i)
			}
		}
	}

	sortutil.Int64Slice(f).Sort()
	sortutil.Dedupe(sortutil.Int64Slice(f))
	return f
}
Esempio n. 2
0
//ApplyBatchSort: Applies the hash to a batch and sorts the output in increasing order.
//Takes and input and an output array, and leaves the sorted output values in the output array.
func (h *Hash) ApplyBatchSort(xarr []int64, yarr []int64) {
	var result int64
	for i, x := range xarr {
		result = (h.a*x + h.b)
		//take the highbits 64bit+ lowbits and make sure what is left is less than 2^31-1
		result = ((result >> HL) + result) & MOD
		yarr[i] = result
	}
	sortutil.Int64Slice(yarr).Sort()
}