Highest power of 2 that divides n.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yuechuan Chen
am 9 Dez. 2019
Bearbeitet: Yuechuan Chen
am 9 Dez. 2019
Never mind I messed up.
n=sym('94315998522576010519588224930693232398146802027362761139521');
a=7;
i=1;%this is a counter that starts from 1.
for i=1:inf
remainder=mod(n-1,2^i);
if remainder~=0
break
end
end
r=i-1%r takes the second last value of i because 2 raised to the last value is not divisible by n-1
s=rdivide(n-1,2^r)%this is the integer we get after n-1 is divided by the 2^(i-1)
2 Kommentare
David Hill
am 9 Dez. 2019
I am very confused. If you factor n-1, you get:
[ 2, 2, 2, 2, 2, 2, 3, 3, 3, 5, 13, 64763, 36377857, 478202419, 745336575801888629040192801767759];
How is a power of two ever going to be divisible by n-1? I obviously don't understand what you are trying to do.
Akzeptierte Antwort
James Tursa
am 9 Dez. 2019
Bearbeitet: James Tursa
am 9 Dez. 2019
In addition to David's comments, you need to do all of the calculations symbolically, so all of these should be sym: 2, i, r.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!