Number of Beautiful Pairs Problem

Number of Beautiful Pairs Problem — ExecCode Easy DSA Practice

Solve the Number of Beautiful Pairs problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a 0-indexedinteger array nums. Your task is to compute the required answer and return the total number of beautiful pairs in 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. 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.

Examples

Input {"nums": [2, 5, 1, 4]}; Output 5. Input {"nums": [11, 21, 12]}; Output 2

Constraints

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

Practice Number of Beautiful Pairs free on ExecCode. Browse DSA problems, topic map, and placement guides.