Check coprime relation
Coprime Array Elements
Create an array
x whose elements are , , and . Verify that all elements of
x are coprime.
x = [9 15 25]; iscp = iscoprime(x)
iscp = logical 1
Verify that at least one pair of elements of
x has a greatest common divisor greater than 1. Output the pairs and their greatest common divisors.
[~,ispcp,pidx,pgcd] = iscoprime(x)
ispcp = logical 0
pidx = 2×3 1 1 2 2 3 3
pgcd = 1×3 3 1 5
x — Input array
row vector of positive integers
Input array, specified as a row vector of positive integers.
[21 36 49]
iscp — True if all elements are coprime
True if all elements are coprime, returned as a logical scalar.
ispcp — True if elements are pairwise coprime
True if all elements are pairwise coprime, returned as a logical scalar.
no two elements whose greatest common divisor is greater than 1.
false if any two elements of
x have as greatest common divisor a number greater than 1.
pidx — Array pair indices
Array pair indices, returned as a two-row matrix.
pidx has columns. Each column of
pidx specifies the
indices of a pair of elements in
pgcd — Pair greatest common divisors
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Introduced in R2021a