Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

how to get atleast 50 points in eulersum? what is wrong in my approach? how to handle precission loss with Big-Integers?

$
0
0

i got AC in 2 subcases of TASK-1,i think this is due to precission loss,anything wrong with my approach?

my code->

class eulernumber {

public static void main(String[] args)

{
    Scanner sc=new Scanner(System.in);

    BigInteger n=new BigInteger("0");

    n=sc.nextBigInteger();

long ii=2;

    BigDecimal e=new BigDecimal("2.718281");

BigDecimal i=new BigDecimal(n);

    BigInteger l=BigInteger.ZERO;

   BigDecimal ll=e.add(i.subtract(BigDecimal.ONE).multiply(e));//find nth term of AP

l=e.add(ll).toBigInteger(); fing sum of nth and first term

BigDecimal bb=new BigDecimal(l);

   System.out.println(i.divide(BigDecimal.valueOf(ii)).multiply(bb).toBigInteger()); //find sum of nth term of AP

}

}


Viewing all articles
Browse latest Browse all 39796

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>