Untitled
unknown
java
a year ago
569 B
9
Indexable
import java.util.Scanner;
public class P1 {
public static float Sol(int x, int n) {
float sumValue = 1;
int sumtmp = 1;
for (int i = 2; i <= n; i++) {
sumtmp += i;
sumValue += 1.0 / (Math.pow(-1, i + 1) * sumtmp);
}
return sumValue;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int n = sc.nextInt();
System.out.println(Sol(x, n));
// Sol(x, n);
// if (Sol(n)) {
// System.out.println("YES");
// } else {
// System.out.println("NO");
// }
}
}Editor is loading...
Leave a Comment