Notice
Recent Posts
Recent Comments
- Today
- Total
01-11 08:45
Tags
- PS
- μ‘Έμ μν
- BFS
- λ°±μλ
- OOP
- java
- μλ£κ΅¬μ‘°
- Graph
- λ°±μ€
- Algorithm
- dp
- λ¬Έλ²
- 그리λ
- μλ°μμ μ
- μΈν΄
- λ€μ΅μ€νΈλΌ
- leetcode
- 벨λ§ν¬λ
- pytorch
- μλ°
- CS
- array
- database
- MST
- tree
- νλ‘κ·Έλλ¨Έμ€
- ꡬν
- spring
- λ°μ΄ν°λ² μ΄μ€
- μμμ λ ¬
Link
Partially Committed
[μκ° μ½λ μ±λ¦°μ§ μμ¦2] μ½μμ κ°μμ λ§μ λ³Έλ¬Έ
π₯ Algorithm || λ¬Έμ νμ΄/PS
[μκ° μ½λ μ±λ¦°μ§ μμ¦2] μ½μμ κ°μμ λ§μ
WonderJay 2022. 7. 4. 17:59728x90
λ°μν
SMALL
https://programmers.co.kr/learn/courses/30/lessons/77884
μ½μμ κ°μλ₯Ό 리ν΄νλ get_num_of_divisor μ μ μν λ€, left λΆν° right κΉμ§μ μλ₯Ό μννλ©°
get_num_of_divisor μ νμ§ μ¬λΆμ λ°λΌμ answer μ λνκ±°λ λΉΌλ©΄ λλ€.
[C++]
#include <string>
#include <vector>
using namespace std;
int get_num_of_divisor(int x)
{
int num_of_divisor = 0;
for (int i = 1; i <= x; i++)
{
if (x % i == 0)
{
num_of_divisor++;
}
}
return num_of_divisor;
}
int solution(int left, int right) {
int answer = 0;
for (int i = left; i <= right; i ++)
{
if (get_num_of_divisor(i) % 2 == 1)
{
answer -= i;
}
else
{
answer += i;
}
}
return answer;
}
728x90
λ°μν
LIST
'π₯ Algorithm || λ¬Έμ νμ΄ > PS' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Summer/Winter Coding(~2018)] μμ° (0) | 2022.07.04 |
---|---|
[μκ° μ½λ μ±λ¦°μ§ μμ¦1] 3μ§λ² λ€μ§κΈ° (0) | 2022.07.04 |
[2019 KAKAO BLIND RECRUITMENT] μ€ν¨μ¨ (0) | 2022.07.04 |
[μ°ΎμλΌ νλ‘κ·Έλλ° λ§μμ€ν°] ν°μΌλͺ¬ (0) | 2022.07.03 |
[νλ‘κ·Έλλ¨Έμ€] 체μ‘볡 (0) | 2022.07.03 |
Comments