Back to General discussions forum
Hi, I do not understand, why the server does not consider the right my decision:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int a = scn.nextInt();
for (int i = 0; i < a; i++) {
int b = scn.nextInt();
int c = scn.nextInt();
int d = scn.nextInt();
System.out.println(((2*b + c * (d - 1)) / 2) * d + " ");
}
}
}
My decision is based on this formula:
Hi! Don't think it is useful for you now, one year later, but might be useful for someone else. I've faced same problem while solving this task, so I've checked the output data with a calc. The thing is that variable for output data must be declared as double type, not integer. And then only a final result must be casted to the integer type)
Scanner in = new Scanner(System.in);
System.out.println("Введите кол-во сравниваемых чисел: ");
int n = in.nextInt();
for (int i = 0; i < n+1; i++) {
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int an = a+b*(c-1);
int sn = (((a+an)*c)/2);
System.out.println(sn);
}