Skip to content

inverse_totient #83

@hvds

Description

@hvds

Is there a link to a description of Max Alekseyev's algorithm somewhere? I can attempt to reverse-engineer it from the code, but a description would be better.

Browsing the code I see that the PP code does an unnecessary (and costly) grep to free memory, I suggest:

-    delete @r{ grep { $_ != $n } keys %r };  # Delete all intermediate results
-    return Mvecsort($r{$n});
+    my $rn = $r{$n};  %r = (); # Delete all intermediate results
+    return Mvecsort($rn);

The C code has this early assert:

  MPUassert(n <= UV_MAX/7.5, "inverse_totient_list n too large");

.. which seems a shame - the Perl code has no such restriction. I guess the issue is that some results in the list can exceed UV_MAX in this case - the assert message is not very clear about that. (53# > 2^64, \prod_{p in P, p < 53}{p/(p-1)} ~= 7.21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions