有没有给出“乘法链”的实用算法
澄清一下,目标是产生任意和精确长度的乘法变化
长度为 1 的乘法链是微不足道的。
“乘法链”将定义为 2 个数字,{start} 和 {multiplier},在代码中使用:
Given a pointer to array of size [{count}] // count is a parameter
a = start;
do
{
a = a * multiplier; // Really: a = (a * multiplier) MOD (power of 2
*(pointer++) = a;
}
while (a != {constant} )
// Postcondition: all {count} entries are filled.
我想找到一个采用三个参数的例程
1. 2 的幂
2. 停止 {constant}
3. {count} - 循环将迭代的次数
该例程将返回 {start} 和 {multiplier}。
理想情况下,{Constant} 值 0 应该是有效的。
简单的例子:
power of 2 = 256
stopping constant = 7
number of times for the loop = 1
returns {7,1}
不平凡的例子:
power of 2 = 256
stopping constant = 1
number of times for the loop = 49
returns {25, 19}
给定 2 的幂的最大 {count} 可能相当小。
例如,2^4 (16) 似乎限制为 4