找到此方程为真的系统基:99 * 99 = 1210

  • 本文关键字:1210 系统 方程 真的 c# algorithm
  • 更新时间 :
  • 英文 :


我想解决这种问题:

我想找到这个方程为真的系统的基础:99 * 99 = 1210。

这个方程似乎写在底座上,超过 10 个,所以对我来说有点混乱。

对于低于 10 的基数,我使用以下方法从基数 P 转换为基数 10,反之亦然,但对于高于 10 的基数,它们似乎不起作用。

static int ConvertToPBase(int numberInTenBase, int P)
{
List<int> list = new List<int>();
while (numberInTenBase > 0)
{
list.Add((numberInTenBase % P));
numberInTenBase /= P;
}
list.Reverse();
string x = "";
foreach (var item in list)
{
x += item;
}
return Convert.ToInt32(x);
}
static int ConvertTo10BaseFromP(int P, int number)
{
int answer = 0;
string num = number.ToString();
for (int i = 0; i < num.Length; i++)
{
answer = answer * P + Convert.ToInt32(num[i].ToString());
}
return answer;
}

你可以直接解决这个问题。请记住,某些基b中的位置表示法利用了b的(整数(幂。例如,以 10 为底的 1210 可以使用(1*10)^3 + (2*10)^2 + (1*10)^1 + (0*10)^0

如果使用基数作为变量,则会得到变量 b 的方程来求解:

(9b^1 + 9b^0) * (9b^1 + 9b^0) = 1b^3 + 2b^2 + 1b^1 + 0b^0

或者,可能更接近你感兴趣的,你可以尝试每个碱基,直到你找到一个方程成立的碱基。伪代码如下:

start-base = 9; lhs = 0; rhs = 0;
repeat {
# convert to base 10 for arithmetic
lhs = to-base(from-base('99', start-base), 10) ** 2;
rhs = to-base(from-base('1210', start-base), 10);
start-base += 1;
} until lhs == rhs;
print start-base - 1;

注意:这不考虑方程在任何基数中都不成立的情况。

最新更新