import java.util.* ;
import java.lang.* ;
import java.io.* ;
class Brovko
{
public static double fact( int itser) {
return itser < 2 ? 1 : itser * fact( itser - 1 ) ;
}
{
int itser= 0 , itfrac= 1 ;
double series= 0 , epsilon;
Scanner in
= new Scanner
( System .
in ) ; epsilon= in.nextDouble ( ) ;
do {
series+= 1 / fact( itser) ;
itser++;
}
while ( Math .
E - series
> epsilon
) ; System .
out .
format ( "series=%10.10f, itser=%d \n " , series, itser
) ; double sum3= 0 , fraction;
do {
for ( int k = itfrac; k >= 1 ; k-- ) {
if ( ( k % 2 ) == 0 ) {
sum3 = 1 / ( 2 + sum3) ;
}
else {
sum3 = 1 / ( k - sum3) ;
}
}
if ( Math .
abs ( Math .
E - ( sum3
+ 1 ) ) < epsilon
) { break ;
}
itfrac++;
}
while ( itfrac < itser + 10 ) ;
fraction= 1 + sum3;
System .
out .
format ( "fraction=%10.10f, itfrac=%d \n " , fraction, itfrac
) ; if ( itfrac< itser) {
System .
out .
printf ( "С заданной погрешностью epsilon=%5.10f, бесконечная дробь, с количеством итераций itfrac=%d быстрее сходится к числу е, чем ряд, c количевством итераиций itser=%d.\n " , epsilon, itfrac, itser
) ; }
else {
System .
out .
printf ( "С заданной погрешностью epsilon=%5.10f, ряд, с количеством итераций itser=%d быстрее сходится к числу е, чем бесконечная дробь, c количевством итераиций itfrac=%d.\n " , epsilon, itser, itfrac
) ; }
}
}
CmltcG9ydCBqYXZhLnV0aWwuKjsKaW1wb3J0IGphdmEubGFuZy4qOwppbXBvcnQgamF2YS5pby4qOwoKY2xhc3MgQnJvdmtvCnsKCXB1YmxpYyBzdGF0aWMgZG91YmxlIGZhY3QoaW50IGl0c2VyKXsKICAgICAgICByZXR1cm4gaXRzZXIgPCAyPyAxIDogaXRzZXIgKiBmYWN0KGl0c2VyIC0gMSk7Cgl9CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCWludC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