Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int power(int a, int b) {
- int ret = 1;
- while(b > 0) {
- ret *= a;
- --b;
- }
- return ret;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- int h, w, k;
- cin >> h >> w >> k;
- vector<int> blocks(31);
- for(int i = k; i >= 0; --i) {
- int power_of_two = power(2, i);
- int tmp_w = w;
- int sum = 0;
- int cnt_blocks = 1;
- while(tmp_w > 0) {
- if(tmp_w >= power_of_two) {
- sum += (tmp_w / power_of_two) * cnt_blocks;
- tmp_w %= power_of_two;
- }
- power_of_two /= 2;
- cnt_blocks *= 2;
- }
- blocks[i] = sum;
- }
- ll ret = 0;
- while(h > 0) {
- if(h >= power(2, k)) {
- ret += (h / power(2, k)) * blocks[k];
- h %= power(2, k);
- }
- --k;
- }
- cout << ret << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment