小编Luc*_*uit的帖子

加速大整数的"基本转换"

我正在使用基本转换算法从大整数生成置换(分成32位字).

我使用相对标准的算法:

/* N = count,K is permutation index (0..N!-1) A[N] contains 0..N-1 */
i = 0;
while (N > 1) {
   swap A[i] and A[i+(k%N)]
   k = k / N
   N = N - 1
   i = i + 1
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,每次迭代的除法和模数加起来,尤其是移动到大整数 - 但是,似乎我可以使用乘法!

/* As before, N is count, K is index, A[N] contains 0..N-1 */
/* Split is arbitrarily 128 (bits), for my current choice of N */
/* "Adjust" is precalculated: (1 << Split)/(N!) */
a …
Run Code Online (Sandbox Code Playgroud)

c algorithm math optimization

7
推荐指数
1
解决办法
580
查看次数

标签 统计

algorithm ×1

c ×1

math ×1

optimization ×1