Avoid overflow
This commit is contained in:
parent
12cf4f79ff
commit
cfb18dec75
|
@ -36,8 +36,16 @@ func main() {
|
|||
|
||||
p := nCpus
|
||||
var jnext int64
|
||||
// XXX - i * i can overflow.
|
||||
// bail out before that happens
|
||||
if n / i < i {
|
||||
continue;
|
||||
}
|
||||
for j := i * i; j < n; j = jnext {
|
||||
jnext = ((n-j)/(2*i)/p+1)*(2*i) + j
|
||||
if jnext > n {
|
||||
jnext = n
|
||||
}
|
||||
markGroup.Add(1)
|
||||
go markMultiples(sieve, i, j, jnext)
|
||||
p--
|
||||
|
|
Loading…
Reference in New Issue