my error in the write n!+1 = 0 mod n

n=1:500;
n_true = [];
for i=1:length(n)
x = 2:n(i);
nq=factorial(n(i)))+1;
x3 = mod(0,n(i));
if ~any(x3 == nq)
n_true(end+1) = n(i);
end
end
i want find all n values by n!+1 = 0 mod n

3 comentarios

I did not look for errors in your code, but be aware that factorial(n) will return Inf, for values larger than 169:
factorial(168:172)
so your code will likely not do what you expect. Even for smaller values of n, it might not be accurate.
Steven Lord
Steven Lord el 5 de Mzo. de 2023
By the definition of the factorial function, factorial(n) is equivalent to 0 mod n as it is n*factorial(n-1). [The base case where n = 0 is handled by the convention, listed on the mod documentation page, that mod(x, 0) is x.] So you're looking for values of n for which 1 is also equivalent to 0 mod n. That would mean 1 is an integer multiple of n. For how many values of n is this true?
Dipankar
Dipankar el 11 de Jun. de 2024
it was tried to found out the solution of Brocards problem

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 5 de Mzo. de 2023
Editada: Jan el 5 de Mzo. de 2023
nq=factorial(n(i)))+1;
% ^
Here are more closing then opening parentheses.
Whenever you mention an error in the forum, attach a copy of the complete message.
This is strange also:
x3 = mod(0,n(i))
This checks, if 0 is divisable by n(i). Even the equation n!+1 = 0 mod n looks confusing.

4 comentarios

the cyclist
the cyclist el 5 de Mzo. de 2023
Editada: the cyclist el 5 de Mzo. de 2023
I think he is trying to find n where
mod(factorial(n)+1,n) == 0
Note that for small n, this can be done without any loop:
n = 1:10;
find(mod(factorial(n)+1,n) == 0)
ans = 1
One might need to resort to the Symbolic Toolbox for larger n. I actually tried to do this, and did not find any more values than n==1, but I am not confident enough in my use of that toolbox to be sure that I did not make a mistake, so I did not post an answer. But this is the code I used:
syms n
tf = mod(factorial(n)+1,n)==0;
n = 1:500;
find(eval(subs(tf)))
ans = 1
I searched values of n up to 100,000.
Walter Roberson
Walter Roberson el 5 de Mzo. de 2023
n factorial is divisible by n for positive n. Adding 1 is going to give something not divisible by n except for the case where 1 is divisible by n
the cyclist
the cyclist el 5 de Mzo. de 2023
Of course. Now I feel dumb. Well, dumber than usual. :-)
Mohammed AL Rashedi
Mohammed AL Rashedi el 5 de Mzo. de 2023
Dear the cyclist exactly, "I think he is trying to find n where" .Thank you Walter Roberson .
Thank you guys. I love you

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 5 de Mzo. de 2023

Comentada:

el 11 de Jun. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by