Skip to main content
15 events
when toggle format what by license comment
Apr 16, 2014 at 0:00 comment added Ben Voigt True, I didn't notice they were unsigned
Apr 15, 2014 at 23:26 comment added Morwenn @BenVoigt With unsigned integers, -1/prime+1 is generally bigger than prime.
Apr 15, 2014 at 23:15 comment added Ben Voigt @morwenn: even if not, the call to std::max should give the right result
Apr 15, 2014 at 22:42 comment added Morwenn @BenVoigt You're right, it works without the special case for 0 if first is initialized with 3u instead of 0u as it is currently the case :)
Apr 15, 2014 at 22:23 comment added Ben Voigt @morwenn: Ok, since you aren't in danger of overflow, (begin+prime-1)/prime. But I thought 0 wasn't a valid concern, since the smallest prime is 2.
Apr 15, 2014 at 22:19 comment added Morwenn @BenVoigt Your code works except for begin == 0. It needs either a branch or a saturated subtraction to work.
Apr 15, 2014 at 7:43 vote accept Morwenn
Apr 13, 2014 at 22:02 comment added Morwenn @LokiAstari In your code, I suppose that n would be is_prime.size()?
Apr 13, 2014 at 21:36 comment added Loki Astari @BenVoigt: Yes. But integer rounding means that was not enough. Hence the extra conditional. I assume your code works. But have not thought it through.
Apr 13, 2014 at 21:29 comment added Ben Voigt I presume that in your original code, you meant for first = begin/prime*prime ?
Apr 13, 2014 at 21:26 history edited Loki Astari CC BY-SA 3.0
deleted 9 characters in body
Apr 13, 2014 at 21:24 comment added Ben Voigt Integer first = std::max((begin-1)/prime + 1, prime)*prime;
Apr 13, 2014 at 21:23 comment added Loki Astari @BenVoigt: Can you expand on that. I am sure you are correct but cant quite place it in the code.
Apr 13, 2014 at 21:21 comment added Ben Voigt (begin-1)/prime + 1 would remove a branch. And you're missing a multiply by prime.
Apr 13, 2014 at 21:18 history answered Loki Astari CC BY-SA 3.0