floor[1*e] + floor[2*e] + floor[3*e] + ... + floor[n*e],
where
floor[x]
is the largest integer that is not greater than x, and e is Euler's number: 2.7182818284..Input
A single line which contains a single integer:
n
.Output
A single line which contains a single integer which should be the answer.
Constraints
1 ≤ n ≤ 10 ^ 4000
Subtasks
Subtask #1 (50 points): 1 ≤ n ≤ 10 ^ 100
Subtask #2 (50 points): Original constraints.
Example
Input:
3
Output:
15
Explanation
floor[1*e] = floor[2.71828..] = 2. floor[2*e] = floor[5.43656..] = 5. floor[3*e] = floor[8.15484..] = 8.
So the answer is
2+5+8=15
.
My Code
Scanner in=new Scanner(System.in);
int T = in.nextInt();
double e=2.7182818284;
long sum=0;
for (int t_i = 1; t_i <= T; t_i++)
{
sum=Math.floor(sum+t_i*e);
// System.out.println(Math.floor(sum));
}
System.out.printf("%.0f",(sum));
This runs into a time-limit exceeded.
10 ^ 4000
won't fitint
andlong
you probably need some more advanced solution... \$\endgroup\$