Borrar filtros
Borrar filtros

Check the result if it is divisible or not

5 visualizaciones (últimos 30 días)
stealgirlfriend el 17 de Abr. de 2024
Comentada: John D'Errico el 17 de Abr. de 2024
Steven Lord ha marcado con alerta este/a pregunta
ty everyone

Respuesta aceptada

John D'Errico
John D'Errico el 17 de Abr. de 2024
Editada: John D'Errico el 17 de Abr. de 2024
Do you understand that you are using DOUBLE precision arithmetic to compute that mod? Do you understand that 7^2026 is a number with roughly 1700 decimal digits?
ans = 1.7122e+03
So hoping to compute that modulus using double precision arithmetic, which will effectively require computing the least significant digit of a number with 1700 and more digits is a silly thing? Not to mention that it will overflow (as you clearly found.) The point is, this assignment was given to you to explicitly force you to think about how you might achieve the result, WITHOUT trying to compute that number via brute force. Actually, you are lucky, had I given out the assignment, I'd have made the exponent MUCH MUCH larger, so that even trying to compute those powers using syms directly would have been difficult. Your teacher was being nice. ;-)
You could use syms though, as a hint.
Even better would be to use powermod. Since this is your homework assignment, I'll stop here.
And, of course, a little creative thinking and some mathematics would allow you to determine that result in a very pretty way, without even resorting to either approach. Would a binomial expansion help you? Again though, since it is homework ... this is your task to solve. As it is, I've already told you two direct ways to accomplish the task.
  2 comentarios
stealgirlfriend el 17 de Abr. de 2024
I manage to solve every tasks but can not for this one. It might be i forgot it is not only about how to code in Matlab to get the answer. I appreciate it, thank you so much
John D'Errico
John D'Errico el 17 de Abr. de 2024
Sigh. What does
ans = 
do? This is the simplest thing you could try, but it will give you the result. Again, I said your teacher was being nice. Were it me assigning the problem, these numbers would have Avogadro's number of digits.
Better yet, is to learn to use powermod.
help sym/powermod
POWERMOD Modular power B = POWERMOD(A, N, M) computes MOD(A.^N, M) Examples: powermod(2, 100, 101) ans = 1 See also MOD.
Finally, consider if this is always true?
4^n == (5-1)^n
Does that help you in any way? Think about a binomial expansion now. What does thta tell you in terms of mod 5 arithmetic? Admittedly,
7^n = (5+2)^n
is a little more complicated, but it gets you much closer to an answer. You can now prove a nice result using mathematical induction.
All of those ideas will give you the answer. Take a shot at it. If you can at least come close, show what you tried, and I will see if I can help you more.

Iniciar sesión para comentar.

Más respuestas (0)


Community Treasure Hunt

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

Start Hunting!

Translated by