Skip to content

Commit

Permalink
21-yuyu0830
Browse files Browse the repository at this point in the history
21-yuyu0830
  • Loading branch information
yuyu0830 authored Aug 5, 2024
2 parents bb05371 + c2c129f commit 88f6b71
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
| 18μ°¨μ‹œ | 2024.07.06 | κ΅¬ν˜„ | [2048 (Easy)](https://www.acmicpc.net/problem/12100) | - |
| 19μ°¨μ‹œ | 2024.07.12 | μž¬κ·€ | [μš°μˆ˜λ§ˆμ„](https://www.acmicpc.net/problem/1949) | - |
| 20μ°¨μ‹œ | 2024.07.22 | LIS | [κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆ˜μ—΄ 5](https://www.acmicpc.net/problem/14003) | - |
| 21μ°¨μ‹œ | 2024.07.23 | μˆ˜ν•™ | [1의 개수 μ„ΈκΈ°](https://www.acmicpc.net/problem/9527) | - |
---
48 changes: 48 additions & 0 deletions yuyu0830/μˆ˜ν•™/9527.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <math.h>

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);
}

0 comments on commit 88f6b71

Please sign in to comment.