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 a59546c commit 42423dbCopy full SHA for 42423db
프로그래머스/약수 갯수의 덧셈 뺄셈.py
@@ -1,31 +1,11 @@
1
+#약수의 갯수가 홀수인 경우는 제곱수인 경우 뿐이다.
2
def solution(left, right):
3
answer = 0
-
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
+ for i in range(left, right+1):
+ if isEven(i) : answer +=1
+ else :answer -= 1
+ return answer
+
+#1/2 제곱수가 정수면 > 홀수의 약수 갯수를 가지게 됌.
+def isEven(num):
+ return True if (num**(1/2))%1 > 0 else False
0 commit comments