We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9b70ab5 commit a59546cCopy full SHA for a59546c
프로그래머스/약수 갯수의 덧셈 뺄셈.py
@@ -0,0 +1,31 @@
1
+def solution(left, right):
2
+ answer = 0
3
+
4
+ def count(x):
5
+ cnt=0
6
7
+ if x == 1:
8
+ return 1
9
10
11
+ for i in range(1, ((x+1)//2)+1):
12
+ if x%i == 0:
13
+ cnt += 1
14
15
+ if cnt % 2 != 0:
16
+ cnt -= 1
17
+ cnt *= 2
18
19
+ else :
20
+ cnt *=2
21
22
+ return cnt+2
23
24
25
+ for num in range(left, right+1):
26
+ if count(num) % 2 == 0:
27
+ answer -= num
28
+ else:
29
+ answer += num
30
31
+ return answer
0 commit comments