Skip to content

Practice Number of Beautiful Pairs

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2748
LeetCode Problem

Number of Beautiful Pairs

Problem Statement

You are given a 0-indexed integer array nums. A pair of indices i, j where 0 <= i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime. Return the total number of beautiful pairs in nums. Two integers x and y are coprime if there is no integer greater than 1 that divides both of them. In other words, x and y are coprime if gcd(x, y) == 1, where gcd(x, y) is the greatest common divisor of x and y.

Source: Number of Beautiful Pairs on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,5,1,4]
Output
5

# Example 2

Input
nums = [11,21,12]
Output
2

Constraints

2 <= nums.length <= 100
1 <= nums[i] <= 9999
nums[i] % 10 != 0

Related LeetCode Problems

Practice more problems similar to Number of Beautiful Pairs.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.