Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //UVA12627ErraticExpansion
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. using namespace std;
  6. const long long MAXN = 30;
  7. inline long long c(int k) {
  8. return k == 0 ? 1 : c(k - 1) * 3;
  9. }
  10. inline long long f(int k, int i) {
  11. if(i == 0) return 0;
  12. if(k == 0) return 1;
  13. if(i <= (1 << (k - 1))) return 2 * f(k - 1, i);
  14. else return 2 * c(k - 1) + f(k - 1, i - (1 << (k - 1)));
  15. }
  16. int main() {
  17. freopen("UVA12627out.txt", "w", stdout);
  18. int T;
  19. scanf("%d", &T);
  20. for(int i = 0; i < T; i++) {
  21. int k, a, b;
  22. scanf("%d%d%d", &k, &a, &b);
  23. printf("Case %d: %lld\n", i + 1, f(k, b) - f(k, a - 1));
  24. }
  25. return 0;
  26. }
  27. /*
  28. 3
  29. 0 1 1
  30. 3 1 8
  31. 3 3 7
  32. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement