For J and L (J<L) I want to find that values of p and q which satisfies mod(((i^b-​i^a)*(i^d-​i^c)),j)~=​0 for all values of 0<=a<b<=J-1 and 0<=c<d<=L-1. If mod(((i^b-​i^a)*(i^d-​i^c)),j)==​0 at any stage we break the loop and go for next values of p and q

3 ビュー (過去 30 日間)
J=input('Value of J: ');
L=input('Value of L: ');
for j = L:6;
for i = 2:j-1;
for a=0:J-1;
for b=a+1:J-1;
for c = 0:L-1;
for d = c+1:L-1;
if mod(((i^b-i^a)*(i^d-i^c)),j)~=0
p_q=[i,j]
end
end
end
end
end
end
end
output:
p_q = 2 3
p_q = 2 3
p_q = 2 4
p_q = 2 4
p_q = 2 4
p_q = 2 5
p_q = 2 5
p_q = 2 5
p_q = 3 5
p_q = 3 5
p_q = 3 5
p_q = 4 5
p_q = 4 5
p_q = 2 6
and so on.
Here the required answer is p=2 and q=5; it is the only combination for which mod(((i^b-i^a)*(i^d-i^c)),j)~=0 for any values of a,b,c,d. But here it is showing so many answers. Kindly help me.
  2 件のコメント
Matt J
Matt J 2019 年 6 月 5 日
What values for J and L did you test here?
Jasvinder Singh
Jasvinder Singh 2019 年 6 月 5 日
Initially I am checking for J=2 and L=3

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

採用された回答

Matt J
Matt J 2019 年 6 月 5 日
編集済み: Matt J 2019 年 6 月 5 日
[a,b,c,d]=ndgrid(0:J-1,0:J-1, 0:L-1, 0:L-1);
k=a<b & c<d;
[a,b,c,d]=deal( a(k), b(k), c(k), d(k)); %all allowed combinations
p_q=cell(6,6);
for j = L:6
for i = 2:j-1
if all( mod( (i.^b-i.^a).*(i.^d-i.^c) ,j) )
p_q{i,j} =[i,j];
end
end
end
p_q=vertcat(p_q{:})
  3 件のコメント
Matt J
Matt J 2019 年 6 月 5 日
But d cannot equal 3 when L=3. In your original post, you say that 0<=d<=L-1, so the maximum value d can assume is 2.
Jasvinder Singh
Jasvinder Singh 2019 年 6 月 5 日
Yes, sir it was actually [a,b,c,d]=ndgrid(0:J,0:J, 0:L, 0:L);
It is working now.
Thank you so much sir

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by