#P3764. 签到题 III

    ID: 2707 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学递归洛谷原创O2优化枚举,暴力洛谷月赛

签到题 III

Description

By analogy with the Euclidean algorithm, zzq defined a strange function:

typedef long long ll;
ll f(ll a,ll b)
{
    if(a==b) return 0;
    if(a>b) return f(a-b,b+b)+1;
    else return f(a+a,b-a)+1;
}

After defining this function, zzq excitedly entered two numbers to compute the value of ff, but found that the function fell into an infinite recursion... Therefore, zzq defines the value of ff to be 00 in cases where the recursion would loop infinitely.

Now zzq inputs a number nn, and wants to compute i=1nj=1nf(i,j)\sum_{i=1}^n \sum_{j=1}^n f(i,j).

Input Format

One line containing an integer nn.

Output Format

One line containing an integer i=1nj=1nf(i,j)\sum_{i=1}^n \sum_{j=1}^n f(i,j).

100
1124
2000
68204

Hint

For 10% of the testdata, n300n \leq 300.

For 40% of the testdata, n2000n \leq 2000.

For 70% of the testdata, n5×105n \leq 5 \times 10^5.

For 100% of the testdata, 1n5×10111 \leq n \leq 5 \times 10^{11}.

Translated by ChatGPT 5