There’s a task to count a sum, summands which is numbers with an even number of ones in bin and each number raised to the power of 4. The problem is that the last summand is 264, so the usual calculation takes a long time.
I think dynamic programming can help here, but i can’t realize how to use it here.
Here’s an example:

Please, can anyone help me with this problem?
There’s a formula to calculate the sum of the powers of 4 of all integers from 1 to n:
sum(k4) for 1<=k<=n = (6*n5 + 15*n4 + 10*n3 – n) / 30
In your problem you need to sum up only powers of 4 of k’s that have an even number of ones in their binary representation. And this formula doesn’t exclude k’s with odd number of ones.
However, my gut feeling tells me that the sum of powers of 4 of k’s that have an odd number of ones should be about the same as the sum of powers of 4 of k’s with an even number of ones.
It turns out that if you calculate these two sums for a range of k’s, these sums will be exactly the same once in a while, once in every 32 k’s:
Without a formal proof I propose that the answer therefore is:
((6*n5 + 15*n4 + 10*n3 – n) / 30) / 2
where n=264-1.