# iscoprime

Check coprime relation

Since R2021a

## Syntax

``iscp = iscoprime(x)``
``[iscp,ispcp,pidx,pgcd] = iscoprime(x)``

## Description

example

````iscp = iscoprime(x)` returns `true` if all elements of `x` are coprime and `false` if two or more elements of `x` have a greatest common divisor (`gcd`) greater than 1.```
````[iscp,ispcp,pidx,pgcd] = iscoprime(x)` checks if pairs of elements of `x` have a greatest common divisor greater than 1. This syntax also returns the indices of all pairs of elements of `x` and the greatest common divisor of each pair.```

## Examples

collapse all

Create an array `x` whose elements are $9=3×3$, $15=3×5$, and $25=5×5$. 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 ```

## Input Arguments

collapse all

Input array, specified as a row vector of positive integers.

Example: `[21 36 49]`

Data Types: `single` | `double`

## Output Arguments

collapse all

True if all elements are coprime, returned as a logical scalar.

True if all elements are pairwise coprime, returned as a logical scalar. `ispcp` is `true` if `x` has no two elements whose greatest common divisor is greater than 1. `ispcp` is `false` if any two elements of `x` have as greatest common divisor a number greater than 1.

Array pair indices, returned as a two-row matrix. `pidx` has $\left(\begin{array}{c}n\\ 2\end{array}\right)=\frac{1}{2}n\left(n-1\right)$ columns. Each column of `pidx` specifies the indices of a pair of elements in `x`.

Pair greatest common divisors, returned as a row vector with a number of elements equal to the number of columns of `pidx`. Each element of `pgcd` is the greatest common divisor of the two elements of `x` identified by the indices in the corresponding column of `pidx`.

## Version History

Introduced in R2021a