mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fix: integer overflow due to multiplication fixed (#886)
* formatting source-code for72c365dcd3
* Fixed Bug [munmap_chunck() core dumped] * formatting source-code forb06bbf4dc6
* fixed line spacing * fixed line spacing * fixed documentation * closed the paranthesis of line 3 * formatting source-code for8233eda889
* Bug Fix heap sort [Fresh Implementation] * formatting source-code fore464ddac36
* Bug Fix heap sort [Fresh Implementation] * formatting source-code for803981c831
* switched to normal functions from lambda * formatting source-code forced5dcd6c4
* Added template and test cases * formatting source-code for7c8617fa46
* fixed docs * fixed line spacing in tests * fix docs * Multiplication result may overflow 'int' before it is converted to 'long'. * fixed cpplint long -> int64 * fixed compiler error Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
445f6722d8
commit
2aec4efdd3
@ -14,9 +14,9 @@ void Sieve(int64_t n) {
|
||||
memset(prime, '1', sizeof(prime)); // intitize '1' to every index
|
||||
prime[0] = '0'; // 0 is not prime
|
||||
prime[1] = '0'; // 1 is not prime
|
||||
for (int p = 2; p * p <= n; p++) {
|
||||
for (int64_t p = 2; p * p <= n; p++) {
|
||||
if (prime[p] == '1') {
|
||||
for (int i = p * p; i <= n; i += p)
|
||||
for (int64_t i = p * p; i <= n; i += p)
|
||||
prime[i] = '0'; // set all multiples of p to false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user