フィルターのクリア

Highest power of 2 that divides n.

4 ビュー (過去 30 日間)
Yuechuan Chen
Yuechuan Chen 2019 年 12 月 9 日
編集済み: Yuechuan Chen 2019 年 12 月 9 日
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 件のコメント
David Hill
David Hill 2019 年 12 月 9 日
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.
Yuechuan Chen
Yuechuan Chen 2019 年 12 月 9 日
Yeah I noticed what I did was very wrong. I was basically trying to set up a loop so that n-1 divides 2 repeatedly until the remainer is not 0.
I tried doing this
while mod(n-1,sym(2)^i)==0
i=i+1;
end
which also didn't get me anywhere cloe to the correct answer.
How would i get around this question? Thanks!

サインインしてコメントする。

採用された回答

James Tursa
James Tursa 2019 年 12 月 9 日
編集済み: James Tursa 2019 年 12 月 9 日
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.
  1 件のコメント
Yuechuan Chen
Yuechuan Chen 2019 年 12 月 9 日
Oh I see, thank you. that why it gave me some stupid numbers. I'm trying to find a way to divide n-1 by 2 repeatedly until the remainder isn't 0 and output how many times it has iterated which would be the answer I want, but I've been trying out all sorts of stuff but it didn't quite work out.

サインインしてコメントする。

その他の回答 (1 件)

Yuechuan Chen
Yuechuan Chen 2019 年 12 月 9 日
n=sym('94315998522576010519588224930693232398146802027362761139521');
a=7;
i=1;
while mod(n-1,2^i)==0
i=i+1;
end
i
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=vpa((n-1)/2^r)
Nevermind I think I've got it, My question was very unclear very sorry about that.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by