Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <ctype.h>
- long long int ar[100], ar2[100], ar3[100], ar4[100];
- long long int power(long long int x, long long int n)
- {
- long long int z = 1;
- if (n == 0) return 1;
- else if (n == 1) return x;
- else if (n % 2 == 0) z = (power(x, (n / 2)) * power(x, (n / 2)));
- else z = x * power(x, ((n - 1) / 2)) * power(x, ((n - 1) / 2));
- return z;
- }
- long long int Binary_Count(int a)
- {
- int i, j, l;
- long long int x, y, z;
- l = 0, x = a;
- for (i = 0; ;i++)
- {
- if (x <= 0) break;
- if (ar2[i + 1] > x)
- {
- if (x == 1)
- {
- ar3[l] = 1;
- ar4[l++] = 0;
- break;
- }
- x = x - ar2[i];
- ar3[l] = ar2[i];
- ar4[l++] = i;
- i = 0;
- }
- }
- y = a, x = 0;
- for (i = 0; i < l; i++) x += ar[ar4[i]];
- for (i = 0; i < l; i++)
- {
- y = y - ar3[i];
- x += y;
- }
- return x;
- }
- int main()
- {
- int a, b, t, i, j;
- long long int c, d, x, y, z;
- char str[100];
- ar[0] = 1, ar[1] = 2, ar2[0] = 1, ar2[1] = 2;
- for (i = 2; i <= 33; i++)
- {
- ar[i] = (2 * (ar[i - 1] - 1)) + power(2, (i - 1)) + 1;
- ar2[i] = power(2, i);
- }
- for (t = 1; ;t++)
- {
- a = 0, b = 0, gets(str);
- for (j = 0; str[j] != 0; j++)
- {
- if (isdigit(str[j])) a = (a * 10) + str[j] - 48;
- else break;
- }
- j++;
- for (; str[j] != 0; j++)
- {
- if (isdigit(str[j])) b = (b * 10) + str[j] - 48;
- else break;
- }
- if (a == 0 && b == 0) break;
- x = Binary_Count(a), y = Binary_Count(b);
- z = y - x;
- x = a;
- for (; ;)
- {
- c = x / 2;
- d = x % 2;
- if (d == 1) z++;
- x = c;
- if (c == 0) break;
- }
- printf("Case %d: %lld\n", t, z);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement