F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Shinobu Loves Segment Tree

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/262144 K (Java/Others)
Total Submission(s): 245    Accepted Submission(s): 154


Problem Description
As a cold-blooded, hot-blooded, and iron-blooded vampire, Shinobu likes to build segment trees.

She uses the $build()$ function to build a segment tree, and the process of building the segment tree will increase the value of some numbers.

The specific content of the $build()$ function is as follows:

```
void build(int id, int l, int r){
  value[id] += r-l+1;
  if(l == r) return;
  int mid = (r+l)/2;
  build(id*2, l, mid);
  build(id*2+1, mid+1, r);
  return;
}
```

For example, if Shinobi calls $build(1,1,2)$ once, then $value[1]$ will increase by $2$, $value[2]$ and $value[3]$ will increase by $1$.

In the long life of a vampire, Shinobu builds a segment tree every day. She has been doing this since day $1$, and on the $i$-th day, she will call $build(1,1,i)$ to build a segment tree.

As a fan of Shinobi, playf got a fan number $x$. Now he wants to ask you a question: what the $value[x]$ will be at the end of the $n$-th day ?

Attention: The initial value of all values is 0.
 

Input
The first line of the input contains a single integer $t(1 \le t \le 10^5)$ --- the number of test cases.

Each of the next $t$ lines contains two integers $n, x(1 \le n \le 10^9, 1 \le x \le 4\times n)$ --- playf's question.
 

Output
For each question, print one line contains one integer --- the answer to the $i$-th question.
 

Sample Input
7 2 3 3 3 4 3 26 49 1000000000 4000000000 1000000000 1 11451419 19810
 

Sample Output
1 2 4 9 0 500000000500000000 4004478229
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-08 08:01:03, Gzip enabled