Tap here to switch tabs
Problem
Submissions

Problem: Number of Beautiful Pairs

med
30 min
Try to solve the Number of Beautiful Pairs problem.

Statement

You are given a 00 indexed integer array nums.

A pair of indices (i, j) is considered beautiful if 0≤i<j<0 \leq i < j < nums.length and the first digit of nums[i] and the last digit of nums[j] are coprime.

Return the total number of beautiful pairs in nums.

Note: Two integers xx and yy are coprime if gcd⁡(x,y)=1\gcd(x, y) = 1, where gcd⁡(x,y)\gcd(x, y) denotes the greatest common divisor of xx and yy.

Constraints:

  • 2≤2 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤9999\leq 9999

  • nums[i] % 10 ≠0\neq 0

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Beautiful Pairs

med
30 min
Try to solve the Number of Beautiful Pairs problem.

Statement

You are given a 00 indexed integer array nums.

A pair of indices (i, j) is considered beautiful if 0≤i<j<0 \leq i < j < nums.length and the first digit of nums[i] and the last digit of nums[j] are coprime.

Return the total number of beautiful pairs in nums.

Note: Two integers xx and yy are coprime if gcd⁡(x,y)=1\gcd(x, y) = 1, where gcd⁡(x,y)\gcd(x, y) denotes the greatest common divisor of xx and yy.

Constraints:

  • 2≤2 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤9999\leq 9999

  • nums[i] % 10 ≠0\neq 0