Intro
Jason is an integer k. It generates a special sequence A, and for each Ai in A there is: Ai = i & k.
He needs to find the sum of the frist k elements of the sequence.
Jason thinks it's really an easy task, so he throws it to you.
Input
line 1: three integers k
Output
line 1: the answer
Constraints
1<=k<=1e5
int kth(int k){
//printf("%d\n",k);
int ans=0;
for(int i=0;i<k;++i) ans+=i&k;
//printf("%d\n",ans);
return ans;
}
// TODO: Replace examples and use TDD by writing your own tests
Describe(Tests)
{
It(Sample_Tests)
{
Assert::That(kth(2), Equals(0));
Assert::That(kth(3), Equals(3));
Assert::That(kth(5), Equals(6));
Assert::That(kth(10), Equals(24));
}
};