So I tried using BigDecimal which is giving me the value of Euler's number up to 50 decimal points. But since the constraint value is this high the number can range from 1 to 10^6000, and hence I am not getting any precision(making it optimal is another issue). Here is the block of code:
for(int i=1; i<n+1; i++){
// i is the integer value and bd is the value of the euler's number, so below i am multiplying the value of i with the euler's number
BigDecimal x = BigDecimal.valueOf(i).multiply(bd);
//Here i am taking floor of the above calculated value
x.setScale(0, RoundingMode.HALF_UP);
//and here sum is floor[1*euler's no] + floor[2*euler's number] + ... + floor[n*euler's number]
sum += x.intValue();
}