-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cc6092
commit 9255a94
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |