#P8574. Summation of Star Function Reciprocals

    ID: 21741 Type: Default 1000ms 256MiB

Summation of Star Function Reciprocals

Summation of Star Function Reciprocals

When the celestial figure Bai Jiying transforms into Ligan, he brings the star function \(f(x)=\left\lfloor\sqrt[4]{x}+\frac{1}{2}\right\rfloor\). For a positive integer \(n\), you are to calculate:

\[ S(n)=\sum_{i=1}^{n}\frac{1}{f(i)} \]

Here, \(f(x)\) returns the integer closest to \(\sqrt[4]{x}\). The range of \(n\) can be as large as \(10^{18}\), so you must compute the sum efficiently by grouping terms. Notice that for each integer \(k\), \(f(i)=k\) if and only if \[ k-0.5\leq\sqrt[4]{i}<k+0.5 \] which implies \[ (k-0.5)^4\leq i<(k+0.5)^4. \] Thus, if you define \[ L_k=\lceil(k-0.5)^4\rceil \quad\text{and}\quad R_k=\lfloor(k+0.5)^4\rfloor, \] then for \(i\) in \([L_k,\min(n,R_k)]\) the term \(1/f(i)=1/k\) and you can add \(\frac{\min(n,R_k)-L_k+1}{k}\) to the sum.

The queries are processed online. You are given \(t\) queries. For the first query the integer \(n\) is provided in plain text. For each subsequent query, the given number is encrypted using the previous query's answer as follows:

// C++ decryption function

typedef long long ll; char buf_ans[114]; ll next_n(double last_ans=0, ll get_n=0){ // last_ans < n <= 1e18 sprintf(buf_ans,"%.6f", last_ans); for(ll i=0,x=0;;i++){ if(buf_ans[i]=='.') return get_n ^ x; if(i & 1) x *= 10; else x = x * 10 + (buf_ans[i] ^ 48); } }

</p>

This decryption works as follows: the previous answer is printed with 6 decimal places. Then, reading the string from the start until a dot is encountered, for each character in an even position (0-indexed) update \(x=x\times10+((\text{character})\oplus48)\) and for each character in an odd position update \(x=x\times10\). The decrypted number is \(n=\text{encrypted}\oplus x\) (\(\oplus\) denotes bitwise XOR). For the first query, since \(last_ans=0\) and its printed representation begins with "0.", the decryption returns the original value.

Your task is to process the queries online and, for each query, output \(S(n)\) with exactly 6 decimal digits.

inputFormat

The first line contains an integer \(t\), the number of queries. The following \(t\) lines each contain a single integer. For the first query, this is the actual value of \(n\) (\(1 \leq n \leq 10^{18}\)). For every subsequent query, the integer is encrypted as described using the previous answer.

outputFormat

For each query, output a single line with the value of \(S(n)=\sum_{i=1}^{n}\frac{1}{f(i)}\) printed with 6 decimal places.

sample

3
10
1
10
7.500000

5.500000 10.000000

</p>