是否有可能找到以下解:9 ^( - 1)%M即9模M的倒数,其中2 <= M <= 10 ^ 9它可能不是素数和gcd(9,M)可能不是1如果不可能找到这样的解决方案有任何方法要解决:((10 ^ n-1)/ 9)%M 1&lt; = n&lt; = 10 ^ 16
答案 0 :(得分:0)
由于这是标记为wolfram-mathematica,我假设您在Mathematica的上下文中询问,在这种情况下,有一个内置函数来执行此操作:
PowerMod[9,-1,m]
对于你想要的任何m值,这将给出9的倒数,模m,
Table[PowerMod[9,-1,m],{m,2,1000}]
将产生:
PowerMod::ninv: 0 is not invertible modulo 3. >>
PowerMod::ninv: 3 is not invertible modulo 6. >>
PowerMod::ninv: 0 is not invertible modulo 9. >>
General::stop: Further output of PowerMod::ninv will be
suppressed during this calculation. >>
{1, PowerMod[9, -1, 3], 1, 4, PowerMod[9, -1, 6], 4, 1,
PowerMod[9, -1, 9], 9, 5, PowerMod[9, -1, 12], 3, 11,
PowerMod[9, -1, 15], 9, 2, PowerMod[9, -1, 18], 17, 9,
PowerMod[9, -1, 21], 5, 18, PowerMod[9, -1, 24], 14, 3,
PowerMod[9, -1, 27], 25, 13, PowerMod[9, -1, 30], 7, 25,
PowerMod[9, -1, 33], 19, 4, PowerMod[9, -1, 36], 33, 17,
PowerMod[9, -1, 39], 9, 32, PowerMod[9, -1, 42], 24, 5,
PowerMod[9, -1, 45], 41, 21, PowerMod[9, -1, 48], 11, 39,
PowerMod[9, -1, 51], 29, 6, PowerMod[9, -1, 54], 49, 25,
PowerMod[9, -1, 57], 13, 46, PowerMod[9, -1, 60], 34, 7,
PowerMod[9, -1, 63], 57, 29, PowerMod[9, -1, 66], 15, 53,
PowerMod[9, -1, 69], 39, 8, PowerMod[9, -1, 72], 65, 33,
PowerMod[9, -1, 75], 17, 60, PowerMod[9, -1, 78], 44, 9,
PowerMod[9, -1, 81], 73, 37, PowerMod[9, -1, 84], 19, 67,
PowerMod[9, -1, 87], 49, 10, PowerMod[9, -1, 90], 81, 41,
PowerMod[9, -1, 93], 21, 74, PowerMod[9, -1, 96], 54, 11,
PowerMod[9, -1, 99], 89}
您可以使用以下命令清除该列表中的无效输出:
Select[%, IntegerQ]
给出:
{1, 1, 4, 4, 1, 9, 5, 3, 11, 9, 2, 17, 9, 5, 18, 14, 3, 25, 13, 7,
25, 19, 4, 33, 17, 9, 32, 24, 5, 41, 21, 11, 39, 29, 6, 49, 25, 13,
46, 34, 7, 57, 29, 15, 53, 39, 8, 65, 33, 17, 60, 44, 9, 73, 37, 19,
67, 49, 10, 81, 41, 21, 74, 54, 11, 89}
如果你想要聪明,你也可以通过跳过不兼容9的元素来更好地组织这个表。使用更高级的Mathematica语法实现这一点的一种方法是:
Map[{#, PowerMod[9, -1, m]} &, Select[Range[100], GCD[#, 9] == 1 &]]
给你输出:
{{2, 1}, {4, 1}, {5, 4}, {7, 4}, {8, 1}, {10, 9}, {11, 5}, {13, 3},
{14, 11}, {16, 9}, {17, 2}, {19, 17}, {20, 9}, {22, 5}, {23, 18},
{25, 14}, {26, 3}, {28, 25}, {29, 13}, {31, 7}, {32, 25}, {34, 19},
{35, 4}, {37, 33}, {38, 17}, {40, 9}, {41, 32}, {43, 24}, {44, 5},
{46, 41}, {47, 21}, {49, 11}, {50, 39}, {52, 29}, {53, 6}, {55, 49},
{56, 25}, {58, 13}, {59, 46}, {61, 34}, {62, 7}, {64, 57}, {65, 29},
{67, 15}, {68, 53}, {70, 39}, {71, 8}, {73, 65}, {74, 33}, {76, 17},
{77, 60}, {79, 44}, {80, 9}, {82, 73}, {83, 37}, {85, 19}, {86, 67},
{88, 49}, {89, 10}, {91, 81}, {92, 41}, {94, 21}, {95, 74}, {97, 54},
{98, 11}, {100, 89}}
它给出了一对对的列表,每对都有m值,然后是9的倒数,以m为模。例如,{61,34}在该列表中,这意味着9 * 34是1 mod 61.您可以检查this is right。