Solution: static long FindBigNum(long n) {
long startTime = System.currentTimeMillis();
long res = 1l;
for(long i=2;i<=n;i++) {
res =((res<<countBits(i))%MOD+i%MOD)%MOD;
}
System.out.println("EndTime: "+(System.currentTimeMillis()-startTime));
return res%MOD;
}
O(n).
Problem is that I for large input ~999999999, I am getting TLE. Need to find a solution with O(n/2) or O(logn) complexity;