フィルターのクリア

Euler totient function of number

2 ビュー (過去 30 日間)
Mohsin Shah
Mohsin Shah 2017 年 6 月 3 日
コメント済み: Mohsin Shah 2017 年 6 月 3 日
I want to calculate Euler totient function for a number N. Euler function should give me an array of integers that are relatively prime to N. Let N=6 then Euler totient function should give a vector [1,2,4,5,7,8]. There are many user defined functions written by people but they all just count the numbers relatively prime to N. How can I get such a vector? Is there any MATLAB builtin command for Euler Totient function?
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 6 月 3 日
Why is 1 considered relatively prime to 6? 6/1 is an integer.
David Goodmanson
David Goodmanson 2017 年 6 月 3 日
Hi Walter, it's because the greatest common divisor of those two is 1.

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

採用された回答

David Goodmanson
David Goodmanson 2017 年 6 月 3 日
編集済み: David Goodmanson 2017 年 6 月 3 日
Hi Mohsin, try
N = 48; % for example
n = 1:N-1;
ind = gcd(n,N)==1;
tot = n(ind)
% check
gcd(tot,N) % all should be 1
not_tot = setdiff(n,tot)
gcd(not_tot,N) % none should be 1
Your example actually has N=9 not N=6.
  1 件のコメント
Mohsin Shah
Mohsin Shah 2017 年 6 月 3 日
Thank you so much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by