Check the result if it is divisible or not
47 次查看(过去 30 天)
显示 更早的评论
采纳的回答
John D'Errico
2024-4-17,14:31
编辑:John D'Errico
2024-4-17,14:52
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?
2026*log10(7)
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 个评论
John D'Errico
2024-4-17,15:38
Sigh. What does
sym(4)^2026
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!