FPEvalDataset/LeetCodeProblem
0302
1{2 "id": 2831,3 "name": "number_of_beautiful_pairs",4 "difficulty": "Easy",5 "link": "https://leetcode.com/problems/number-of-beautiful-pairs/",6 "date": "2023-06-18 00:00:00",7 "task_description": "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`. **Example 1:** ``` **Input:** nums = [2,5,1,4] **Output:** 5 **Explanation:** There are 5 beautiful pairs in nums: When i = 0 and j = 1: the first digit of nums[0] is 2, and the last digit of nums[1] is 5. We can confirm that 2 and 5 are coprime, since gcd(2,5) == 1. When i = 0 and j = 2: the first digit of nums[0] is 2, and the last digit of nums[2] is 1. Indeed, gcd(2,1) == 1. When i = 1 and j = 2: the first digit of nums[1] is 5, and the last digit of nums[2] is 1. Indeed, gcd(5,1) == 1. When i = 1 and j = 3: the first digit of nums[1] is 5, and the last digit of nums[3] is 4. Indeed, gcd(5,4) == 1. When i = 2 and j = 3: the first digit of nums[2] is 1, and the last digit of nums[3] is 4. Indeed, gcd(1,4) == 1. Thus, we return 5. ``` **Example 2:** ``` **Input:** nums = [11,21,12] **Output:** 2 **Explanation:** There are 2 beautiful pairs: When i = 0 and j = 1: the first digit of nums[0] is 1, and the last digit of nums[1] is 1. Indeed, gcd(1,1) == 1. When i = 0 and j = 2: the first digit of nums[0] is 1, and the last digit of nums[2] is 2. Indeed, gcd(1,2) == 1. Thus, we return 2. ``` **Constraints:** `2 <= nums.length <= 100` `1 <= nums[i] <= 9999` `nums[i] % 10 != 0`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "nums = [2,5,1,4]",12 "output": "5 "13 },14 {15 "label": "Example 2",16 "input": "nums = [11,21,12]",17 "output": "2 "18 }19 ],20 "private_test_cases": [21 {22 "input": [23 2589,24 416,25 8132,26 718,27 9296,28 3306,29 1258,30 8493,31 1081,32 7335,33 9952,34 3791,35 8418,36 3107,37 9602,38 9979,39 4154,40 3791,41 5243,42 4278,43 1189,44 7207,45 4406,46 6321,47 5226,48 7348,49 3865,50 8301,51 9139,52 5746,53 1283,54 8812,55 2881,56 337,57 2335,58 8802,59 8946,60 3125,61 744,62 905,63 5149,64 3537,65 6498,66 6152,67 593,68 6293,69 7359,70 1844,71 3987,72 8635,73 9905,74 895,75 6266,76 4775,77 2063,78 2691,79 2218,80 2928,81 3723,82 4926,83 3441,84 8752,85 2078,86 909,87 2971,88 5621,89 7526,90 6575,91 5619,92 6609,93 7137,94 2353,95 2725,96 986,97 1868,98 7714,99 887,100 1386,101 1659,102 6762,103 4999,104 4188,105 999,106 2725,107 8302,108 8059,109 2171,110 9442,111 5471,112 8592,113 8029114 ],115 "output": 2799116 },117 {118 "input": [119 9568,120 4468,121 6126,122 5827,123 5061,124 3927,125 7924,126 4233,127 9149,128 6096,129 5542,130 183,131 1587,132 5744,133 2683,134 2566,135 3399,136 5854,137 2663,138 5104,139 5289,140 8874,141 4732,142 2438,143 1737,144 2118,145 888,146 774,147 7576,148 9899,149 7321,150 8013,151 5756,152 1543,153 8629,154 6545,155 661,156 6765,157 1825,158 4298,159 1203,160 9153,161 3962,162 8294,163 4541,164 1505,165 1348,166 2182,167 4861,168 7515,169 2859,170 7268,171 6582,172 3294,173 263,174 8667175 ],176 "output": 1093177 },178 {179 "input": [180 189,181 1442,182 1025,183 5855,184 2345,185 7697,186 9091,187 8139,188 3813,189 2638,190 9984,191 7324,192 723,193 4521,194 9206,195 6646,196 6567,197 1667,198 8443,199 7935,200 6515,201 566,202 1857,203 3678,204 1117,205 1998,206 3079,207 1483208 ],209 "output": 282210 },211 {212 "input": [213 653,214 7825,215 2553,216 3689,217 7419,218 1163,219 8588,220 239,221 405,222 4959,223 1807,224 7928,225 3256,226 5039,227 7751,228 1116,229 3345,230 6622,231 1096,232 3931,233 1107,234 3108,235 1593,236 3615,237 2174,238 7029,239 9643,240 2594,241 1104,242 5459,243 1439,244 4276,245 2173,246 8319,247 5332,248 8338,249 9921,250 2999,251 8215,252 3639,253 1518,254 6172,255 4704,256 6049,257 9599,258 1274,259 7894,260 8023,261 1753,262 9189,263 9743,264 6413,265 6424,266 3327,267 3085,268 9488,269 3903,270 6248,271 6517,272 2345,273 8434,274 9285,275 5527,276 7809,277 23,278 5579279 ],280 "output": 1543281 },282 {283 "input": [284 8509,285 4764,286 273,287 3519,288 5629,289 3926,290 2559,291 6048,292 8119,293 6751,294 3433,295 1296,296 473,297 5707,298 449,299 5347,300 1003,301 1078,302 9882,303 5835,304 6132,305 8925,306 9168,307 3645,308 9618,309 5303,310 4033,311 2144,312 7251,313 5381,314 3153,315 3734,316 3081,317 3949,318 6464,319 4827,320 6547,321 3251,322 6987,323 3759,324 638,325 5329,326 473,327 2389,328 1806,329 6956,330 7795,331 7998,332 7852,333 1614,334 2161,335 2701,336 7735,337 6296,338 1112,339 3958,340 251,341 1167,342 574,343 6005,344 2636,345 2776,346 8183,347 7834,348 3445,349 1957,350 8008,351 6552,352 2985,353 3612354 ],355 "output": 1620356 }357 ],358 "haskell_template": "countBeautifulPairs :: [Int] -> Int\ncountBeautifulPairs nums ",359 "ocaml_template": "let countBeautifulPairs (nums: int list) : int = ",360 "scala_template": "def countBeautifulPairs(nums: List[Int]): Int = { \n \n}",361 "java_template": "class Solution {\n public int countBeautifulPairs(int[] nums) {\n \n }\n}",362 "python_template": "class Solution(object):\n def countBeautifulPairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n "363}