Skip to content

Instantly share code, notes, and snippets.

@kevduc
Created September 25, 2021 22:14
Show Gist options
  • Save kevduc/91d1d1e94cdd924a5bbd18d662a314d1 to your computer and use it in GitHub Desktop.
Save kevduc/91d1d1e94cdd924a5bbd18d662a314d1 to your computer and use it in GitHub Desktop.
function y = isCarmichael(x)
y = false
if isprime(x)
return
end
for b = 2:x-1
if gcd(b,x) ~= 1; continue; end
p = 1;
for i = 1:x-1
p = mod(p*b,x);
end
if p ~= 1; return; end
end
y = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment