基于@Daniel 的映射,从 Dec 到基于奇异 3:
x := n; // Original number
y:= 0;
do
y0:= y;
z:= DecToThree(x); // Convert x from Decimal to 3-based.
y:= IllRep(z); // Calculate the number y of numbers with at least 2
// consecutive 0 with a representation in 3- based.
x:= n + y; // Add illegal representations to original number;
until (y = y0);
Result:= DezToThree(x); // Convert x from Decimal to 3-based.
例子:
16 -> 121 y = 2 // {0, 100}
16+2 -> 200 y = 3 // {0, 100, 200}
16+3-2 -> 201 年 = 3
另一种方式:
y:= IllRep(x); // calculate the number y of illegal representations
z:= ThreeToDec(x); // convert x from 3-based to dec
result:= z-y;
现在您所需要的只是一个查找所有非法表示的函数,直到达到一定数量。