fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner in = new Scanner(System.in);
  10. PrintWriter out = new PrintWriter(System.out);
  11.  
  12. double sum = 0;
  13. double numerator = 1, denominator = 1;
  14. int n = in.nextInt();
  15.  
  16. for (int i = 1; i <= n; i++) {
  17. denominator = pow(i,i-1);
  18. sum += (1.0*numerator)/denominator;
  19. numerator*=i;
  20. }
  21. System.out.println("Сумма: " + sum);
  22. System.out.println("Числитель: " + numerator);
  23. System.out.println("Знаменатель: " + denominator);
  24. }
  25. public static double pow(double number, int power)
  26. {
  27. double answer = 1;
  28. for (int i = 0; i < power; i++)
  29. {
  30. answer *= number;
  31. }
  32. return answer;
  33. }
  34. }
Success #stdin #stdout 0.07s 4386816KB
stdin
3
stdout
Сумма: 1.7222222222222223
Числитель: 6.0
Знаменатель: 9.0