public class Nsieve {static void nsieve(int m) {int count = 0, i, j;byte[] flags = new byte[m];for (i = 2; i < m; ++i)if (flags[i] == 0) {++count;for (j = i << 1; j < m; j += i)// if (flags[j])flags[j] = 1;}System.out.format("Primes up to %8d %8d\n", m, count);}static void nsieve2(int m) {int count = 0, i, j;byte[] flags = new byte[(m + 7) >>> 3];for (i = 2; i < m; ++i) {if (((flags[i >>> 3] >> (i & 7)) & 1) == 0) {++count;for (j = i << 1; j < m; j += i)//noinspection lossy-conversionsflags[j >>> 3] |= 1 << (j & 7);}}System.out.format("Primes up to %8d %8d\n", m, count);}public static void main(String[] args) {int m = Integer.parseInt(args[0]);for (int i = 0; i < 3; i++)nsieve2(10000 << (m - i));}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。