benchmarks.wiki / Public workspace
..... .··:-=++*******+++=========================================++++++++==--::··.........··:--=++*****+=-:··.
.. ...··:::------::::::::::::::----====++++++====--:::·············:······.... ...··:::-----:--:·..
......................·····:::::::::::::···.... ...... ........::-::·..
..::-:··..
..:·::··..
..··:··..
..·····..
..·.··...
..·.··...
............................ ..........................··....... ...·.·....
..··:::---::::------------::·.. ..··:::----:::::·······::::--------:::···...........·······.·...
.·:--=++*#******########*++=-:·. .·:--=++*****+++===------===++******+++=--:::·······:::::::::··...
.....······::::::----------===++**###%%%@@@@@@@@@@@@%%%%###******+++++++++===--::········::--=++*#########**+==-::·.
.......·······················:::---==+++*************+++==---::::::::::·····..... ...···::---=====----::--::·.
.............. ....····:::::::::::::::···................ ......······...::-::··.
..··:···..
..·.··...
......
. .
......···············.... ..............
...··::---==+++*****+++=--:·.. ....················::::-----:::··... .....··.....
..·::-=+*##%@@@@@@@@@@%#*+=-:·. ..··::--======-----------==++*****++==-:··.. ...···::::::::··..
..··:::--::::····......···::-==++**###%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#**+=--::······:-=+*#%@@@@@@@@@%##**+++==--::·.
...··::::::::····..............···:::---=====++++====================---::··.... ...··:--=++*****+++==-----:=--::·.
....······...... .....···········.............····...... ...····:::::······..::--::·..
..:·:::··.
..·.···...
.....
....·····::::::::·····.... .........
...·::-==++*******++==--::··.........·········.... ..···:::::::··. ..........
.··-==+*#%@@@@@@@@%#**+==--:::::---==+++++++==--:··... ...··:-==+++++=-:··. ..···:::::····...
.··:--==---::····.....····::::------:::::::::::::::--=++*#%@@@@@@@@@@%#*+=-::····::-=+*#%@@@@@@@@%##*++++++++==--:·.
..·::--==----:::···.................................···::--==++*****++=--:··......··::-=++******+++==--------+=--:·.
...···::::·····.... ....····::::····.... ....···::::::::·········-:==-::·.
..::--::·.
..··:··..
.....
......·············.........·······..... .........
.··::---======----:::::::::---=======--:··. .··::::::··.. .... ...
..·:-==+++*++++===--------=++*##%%@@@@%#*+=-·. .·::-====--:··. .....···············...
..·::-==++=====---==========---::··... .·:-=+#%@@@@@@@@%#*=--:······::--=++*******+++++++++**#**++=-:·.
.··:--=+++=====-----::::·····...... .··:-==+*****++=--:···.....···::----===-----------=====*+=-:·.
...···:::::::····...... ..····:::::····.... ......···················=-++=-·.
··--=--:·.
..:·::·..
..·...
..
.................····::::::::···.. .............. ......
...····::·············::--==++*****++=-:·.. ..··:::::::····............... ...·::··.
.·::--====---::···....···:-=+*#%@@@@@@@%*+=:·. .·::--===---::····.......................··::----::·.
..·::--=+++++****####%%####*++=--:·.. .·:-=++*****++=--::·················::::::--==++*##%@%#*+=-:.
.··::-=============------:::::····... .··::--------:::···....................····:::--==+++=*+=-:.
...···:::······...................... ....·······........ ......·····==*+-:·.
··--=-:·..
..:·:··..
......
....
......
.····.
.....····::::::::::···... ...................····....... ..::::··.
..··::::::::····........··::-==+*******++=-::··... .....····:::::::::::::-------::::··... ..···:---::·.
.·:-=+#####*++=-::·........·:-=+*#%@@@@@@@%#*+=-:··.......···::::---------=====+++++++===--::::···::::--=+===--:·.
..··:::-====+++***########**++==-:··. ...···:::::----------:::··.. ..·::-=+*##%%##*=-:·.
..··:::---:::::::::::::::::::::····... ......················... ..··:--====-+=-:·.
............. .............. .............. .....··--=-:·.
..:·::·..
·.··..
......
.......
..·····.
··--::·..
.......................·····:::::::::::·····......... .....·····:::::::····.... ...::==--:·.
.··:-==+====--:::········::--==+++******++++===---::::·····........···::--==+++****+++==--:::········::-----+==-:·
.·:-+*#%@@@@@%#*+=--::::::::-==+*##%%@@@@@@@%%%##***++===--:::·········::-==+**#%%@@@@@%%###**++++++++****##**+=-:·.
...···::::-----======+======--::··... ..·:-=+*###%%##*+=-:·. ..·::--==--::·..
...····························..... ..··::--=====--:··. ...···:··:··..
...... ..... ....······.... ...····..
..·.·..
.....
..·...
..··:···..
..::--::·.
··=-+=-:·.
....····..........······························.... ...··::::::::::::····.........·····:+=*+=-:.
.··:-==++====-----------=======+===========+++++===--::··.. ..·::-==++******+++==----------===+++*+=*+=-:.
.·-=+*#%@@@%%#***+++++++***#############%%%%%@@@@@@%%#*++=-:·... ...·::-=+**##%%%%%###****++++****###%%%@%#*+-:·.
...···:::----========---:::··...........········... .·:-=+#%@@@@@@@@@%#+=-:·. ........
....····················.... .......... ..·:-==+*****++=--:·.. ..........
..···········... ......·...
..·.·.
..:···.
··:::··.
··--=-:·.
··==+=-:·.
::+=*+=:·.
.............·············..............······.... ...··············..........·····::::+=*+=-·.
..··:::---::-----===++++++===--::::::::::--=======--::·.. ..··::---====---:::··········::--==++**+=*+=-·.
.·:-=++***++++++**##%%@@@@@%%#**++======++*##%%@@@@%%#*+=-:··........··::--======---::····...····::-=++*#%%@%#*+=:·.
..··:-==++*******++=--:··.......··:--==++++==-:··.......·:-=+#%@@@@@@@@@@@%#*+=-:··... ......······...
...···:::--------::···... ...··::::::::··.. ..·:--=++*****++==-::··... ...···::::::::::·.·..
................. .......... ...··········.... ....······:······:···.
··-::·..
:·-:-··.
:·=--:·..
:·=-=-:·.
::=-+-:·..
::==+=-:·.
.....·········.... ............ .......·...... ...······==+=-:·.
......·······::--=======--::··........··::--------::···.... ....···:::-----:::··.. ..··:--==+==+=-:·.
.··::::::::---=++*##%%%%##*+=--:······::-=++*#######**++==-------===++++++++=--:·.. ..·:-=+**#**+=-:·.
.·:==+*##%%%%##*++=-:::····::--=++****++=--:···....··::-=+**##%%%%###**++===----------===+++********+++=-:··..
..·::--=========--::···....···:::-------::···.........···::----------:::····.....···::-==++*********++=-:-:·..
....··········..... ......·····..... .............. ....··::::::::::::::::=-=:·..
::=-=:·..
:·=:-:·..
··-:-:·..
··::-:·..
..::::·..
..:·::·..
.............. .............. .....··········.... .....:·::·..
.....···:::----:::···.........···:::::-:::::········:::--==+++***+++=--:·. ..····:··::··..
........····::--=++++++==-::·········::-==+++++++++++++++++*##%%@@@@@@@@@%#*+=-:·. ..··::---:::··..
.·:==+**####***++==----------------:::··.........··:::--======----::::·······:::--==+*##%@@@@@@@@@@@@@@%*+=-:·.
..·:---=======---::::::::::::::::::····............····:::::::····... ...·::-=++***************+=*=-:·.
....············....................... ............ ...··:::::::::::::::::+=+=-:·.
:·=-+=-:·.
··-:--:··.
..:·::··..
..·.····..
..·.....
.....
.........................·······....... .....····:::::::::::···.. .....
......·····::::::·········:::::--------:::··········::--=++***********+=-::·.. ..
.....····::::--------::::::::---===+++++++====--------==+*#%%@@@@@@@@@@@%#*+=-:·..
..·:::--------:::----------::··.. ..··:::------:::···...... .....··::-==+**##%%%%@@@@@@@@@%#*+=-:·.
...··:::::::::····:::::::::::···... ...···:::::::····... ...··::--==++++++++++****+=*+=-:·.
............................... ............... ....················::+=*+=-:·.
··==*+=-:·.
..--++=-:·.
..::==--:·.
.·:::::·.
.··:··..
.····.
....····..............·····::::::::·····..... .....····::::::::::···.... .....
..··::-----:::::·····:::---==++++**+++==--::···......···:--==+++****++==--::··..... ....
..·::-=++++===---::::::--==++*##%%%%%%##*++=--::·····:::-==++**#####***+==--::···.......·····... ...
....... ..·::--==---:·.. ..···:::::::::::::··············:::::------------==++*#%@@%#*+=-:·.
........ ..···::::::··.. ..···:::::::::::···.............····::::::::···::::--=++*+=*+=-:·.
.... ............ .....·······...... ......................···:+=*+=-:·.
··+=*+=-:·.
.·==*+=-:·.
..--*+=-:·.
.:-++=-:·.
·:===-:·.
.·----:·.
...···:···...........···::::::::::::::···..... .......·········........ ............ .:::::·.
.··:-==+++=--:········::-==+**********+==-::··........···:::--------:::···..........·········.. ··::··.
·:-=+*#%@%#*+=-:::::::--=+*#%%@@@@@@%%#*+=--:····.····::---=======---::··.........··::------::·. ..···.
.... .·:-=++*++=-:·.. ...····::::------=================--:::··.......··:-=*#%@%#*+=-:.
... .··::----::··. ..···:::::::::::::::·····::::::::::::···.... ...··:-=+++=*+=-:·
....··..... ....·········............................ ...··:+=*+=-:·.
··+=*+=-:·.
··+=*+=-:·.
.·==*+=-:·.
.·==*+=-:·.
..--*+=-:·.
..:-++=-:·.
...·····.. ...····:::::::::::···...... .................. .....·······... .::===-:·.
.··:-==++=-:··.....···:--==++****++==--::··..........··::::----::::··.... ...··:::------::··. ..··----:·.
.·:-=+*#%@%#+=-:::·:::--==+***##***+==-:··... ...··::-==+++++++=--::·... ..··:-=+++**++=-:·. .·:::::··.
... .·:-=+*#####*+=--:·... .....····::::----====++++++*****+++==-::·.. ..·:-=+*###*+=-:·.
.. .·::--===---::··... ...····:::::---:::::::······::::::::::::···... ..·::-===-+=-:·.
.....···...... .....············..... ............... ....··=-+=-:·.
··--+=-:·.
.·--+=-:·.
.·--+=-:·.
.·--+=-:·.
..--==-:·.
..::==-:·.
......... .....·········..... ................ .....·········.... ...::=--:·.
.··:-==---:·········:::-------:::··.. ..··::--------::···.......···::--======--::··... ...··:::--::·.
.·:-=+*#%%#*+==------========--:··. .·:-==+**###**++=--::·······::-=++**###**+==-:··.......··::--:::··.
██╗ ██╗██╗ ██╗███████╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ███████╗███╗ ██╗ ██████╗██╗ ██╗
██║ ██║██║ ██║██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝████╗ ██║██╔════╝██║ ██║
██║ ██║██║ ██║█████╗ ██║ ██║ ██║██║ ██║█████╗ ██████╔╝█████╗ ██╔██╗ ██║██║ ███████║
██║ ██║╚██╗ ██╔╝██╔══╝ ██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗██╔══╝ ██║╚██╗██║██║ ██╔══██║
███████╗██║ ╚████╔╝ ███████╗╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝███████╗██║ ╚████║╚██████╗██║ ██║
╚══════╝╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝$ open /benchmarks/livecodebench/tasks/release~5fv1--te…▌ posts · files
LiveCodeBench / 2831 / number-of-beautiful-pairs
Problem
Scored by the benchmark’s own harness. Use the benchmark’s own evaluation harness to check your work.
question title
number-of-beautiful-pairs
question content
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
starter code
Code
class Solution:
def countBeautifulPairs(self, nums: List[int]) -> int:
contest date
2023-06-25T00:00:00
contest id
weekly-contest-351
difficulty
easy
platform
leetcode
Discussion
No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
See how this is scored Scored by the benchmark’s own harness
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.
Source and history
- upstream_id / Original problem ID
- 2831
- task_id
a018b437-4bf1-5f49-8090-3a298f617357- task_key
release~5fv1--test--2831- task_revision_id
- 4
- config / split
- release_v1 / test
initial import