Post Reply 
Carmichael Numbers (Updated 2/21/2016)
04-24-2020, 06:18 PM (This post was last modified: 04-24-2020 06:59 PM by C.Ret.)
Post: #2
RE: Carmichael Numbers (Updated 2/21/2016)
Hello,

I just compose a code for testing if a number n is a Carmichael Number. By inadvertence, I used exactly the same ifactors instruction. By using it, we don’t need to test if n is prime. The length of the vector produce by ifactors is exactly 2 for any prime number. A prime number always decomposes in the only one factor which is exactly itself.

For example, ifactor(13) returns [ 13 1 ]

This lead to a shorter code :
Code:
EXPORT IsCARMI(n)
 BEGIN
  LOCAL FC,k,l,r;   
  FC:=ifactors(n);    l:=length(FC);    r:=(l>2);
  FOR k FROM 1 TO l STEP 2 DO  r:= r AND FC(k+1)==1 AND irem(n-1,FC(k)-1)==0; END;
  RETURN r;
 END;

ISCARMI(561) returns 1
ISCARMI(2588653081) returns 1

ISCARMI(4991) returns 0 (is prime)
ISCARMI(1.23) returns 0 (not integer)
ISCARMI(-561) returns 0 (negative integer)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Carmichael Numbers (Updated 2/21/2016) - C.Ret - 04-24-2020 06:18 PM



User(s) browsing this thread: 2 Guest(s)