链接:https://ac.nowcoder.com/acm/contest/10166/C
来源:牛客网

题目描述
牛牛最近学会了异或操作,于是他发现了一个函数f(x)=x\oplus (x-1)f(x)=x⊕(x−1),现在牛牛给你一个数\mathit nn,他想知道\sum_{i=1}^n f(i)∑
i=1
n

f(i)的值是多少,请你告诉他。

暴力过了。。。。

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     * 
     * @param n int整型 
     * @return long长整型
     */
    public long Sum (int n) {
        // write code here
        long sum = 0;
        for(int i=1; i<=n; i++){
            sum += i^(i-1);
        }
        return sum;
    }
}