erastothenes 筛 - 在 C 中初始化大位数组

问题描述 投票:0回答:1

所以我尝试使用 C 中的位数组来实现erastothenes 筛。 我尝试过使用

手动设置位
int x;
   int i;

   x = x | (1 << i );    // Set bit position i in x 

但是,当我进行 10,000 次迭代时,我意识到这会导致太多迭代。如果我使用 32 位无符号 int 数组作为位数组,如何一次初始化所有 32 位?

我尝试过设置

unsigned int[] arr = {[0-100000] = 1};

这显然不起作用。

c sieve-of-eratosthenes
1个回答
0
投票

将 32 位无符号 int 的值设置为 4294967295,或者,如果该数字是有符号 32 位 int,则将其设置为 -1

© www.soinside.com 2019 - 2024. All rights reserved.