diff --git a/yuyu0830/README.md b/yuyu0830/README.md index 094c9ce..aa3d0c6 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -17,5 +17,6 @@ | 13차시| 2024.05.21 | LIS | [가장 긴 증가하는 부분 수열 2](https://www.acmicpc.net/problem/12015) | - | | 15차시| 2024.06.01 | 기하 | [다각형의 면적](https://www.acmicpc.net/problem/2166) | - | | 16차시 | 2024.06.04 | MST | [별자리 만들기](https://www.acmicpc.net/problem/4386) | - | -| 20차시 | 2024.07.22 | LIS | [가장 긴 증가하는 부분 수열 5](https://www.acmicpc.net/problem/4386) | - | +| 20차시 | 2024.07.22 | LIS | [가장 긴 증가하는 부분 수열 5](https://www.acmicpc.net/problem/14003) | - | +| 21차시 | 2024.07.23 | 수학 | [1의 개수 세기](https://www.acmicpc.net/problem/9527) | - | --- \ No newline at end of file diff --git "a/yuyu0830/\354\210\230\355\225\231/9527.cpp" "b/yuyu0830/\354\210\230\355\225\231/9527.cpp" new file mode 100644 index 0000000..3d6db99 --- /dev/null +++ "b/yuyu0830/\354\210\230\355\225\231/9527.cpp" @@ -0,0 +1,48 @@ +#include +#include + +using namespace std; + +typedef unsigned long long int ll; + +ll arr[10000] = {0, }; +int cnt = 1; + +// 0 ~ t 까지의 1의 개수를 반환 +ll f(ll t) { + int ptLog = cnt, tmp = 0; + ll pt = pow(2, ptLog - 1), ans = 0; + + while (pt) { + if (t & pt) { + ans += arr[ptLog - 1] + 1; + ans += pt * tmp++; + } + pt >>= 1; + ptLog--; + } + + return ans; +} + +int main() { + ll a, b, tmp = 1; cin >> a >> b; + + // b까지 arr 배열 누적합 연산 + while (b > tmp) { + arr[cnt] = (arr[cnt - 1] * 2) + tmp; + tmp *= 2; cnt++; + } + + ll ZeroToAVal = f(a); // 0 ~ a - 1 까지의 1의 개수 + ll bVal = f(b); // 0 ~ b 까지의 1의 개수 + ll aVal = 0; // a 의 1의 개수 + + ll pt = pow(2, cnt); + while (pt) { + if (a & pt) aVal++; + pt >>= 1; + } + + printf("%lld\n", bVal - ZeroToAVal + aVal); +} \ No newline at end of file