LMA1 - Editorial

Problem Link:

Practice

Contest

Difficulty:

Easy

Pre-requisites:

Basic math

Explanation:

Sub task 1:

In this subtask the summands will decrease very fast because a is actually small, so it’s enough just to calculate the sum
for all n smaller of equal to 100 and this should be enough.

All the sub tasks:

The following fact is important: all the fractions are given with exactly two digits after the decimal point. Because
of this, we can convert the input to common fractions with denominator not exceeding 100. So, we’ve got rid of the
floating point numbers.

Then, let’s make some observations regarding the sum itself:

alt text

So, now we see that the answer can be represented as a common fraction. Outputting the first D digits of a common fraction is a
standard and a well known trick, you can see the problem APPROX or setter’s solution for details.

Setter’s Solution:

Can be found here

Tester’s Solution:

Can be found here

1 Like

whats wrong in my solution ?

Can this question will be explained a little more in terms of code.

I calculated the formula correct and solved it directly putting the values in the formula.
and printed result to D decimal places using

rem=sol-(int)sol;
for(i=0;i<d;i++) {
rem=rem*10;
cout<<(int)rem;
rem=rem-(int)rem;
}