반응형
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
arr__ = [0]*(2*len(A)+1)
arr = []
saved = [-1]*(2*len(A)+1)
for i in range(len(A)):
arr__[A[i]] += 1
for i in range(len(A)):
divisor = 0
if saved[A[i]] != -1:
arr.append(saved[A[i]])
continue
for j in range(1,int(A[i]**0.5)+1):
if A[i]%j == 0:
divisor += arr__[j]
if A[i]/j != j:
divisor += arr__[A[i]//j]
j += 1
arr.append(len(A)-divisor)
saved[A[i]] = len(A)-divisor
return arr
pass
반응형
'Codility' 카테고리의 다른 글
에라토스테네스의 체 (0) | 2021.01.04 |
---|---|
Codility - CountSemiprimes 문제풀이 - Henry's Algorithm (0) | 2020.10.14 |
Codility - Peaks 문제 풀이 - Henry's Algorithm (2) | 2020.09.08 |
Codility - MinPerimeterRectangle 문제풀이 (0) | 2020.08.25 |
Codility - Flags 문제풀이 (0) | 2020.07.03 |