fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception{
  10. Scanner in = new Scanner(System.in);
  11. int n = in.nextInt();
  12. int[] a = new int[n];
  13. for (int i=0; i<n; i++){
  14. a[i] = in.nextInt();
  15. }
  16. double sum=0;
  17. int f=1;
  18. for (int i=1; i<=n; i++){
  19. f*=i;
  20. double sign = (i%2==0) ? 1 : -1;
  21. sum+=(sign*a[i-1])/f;
  22. }
  23. System.out.println(sum);
  24. }
  25. }
Success #stdin #stdout 0.08s 711680KB
stdin
2
5
8
stdout
-1.0