(SPOJ) 3742 - Feynman - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String valor = br.readLine();
int vInt = Integer.parseInt(valor);
while(vInt != 0) {
int resultado = (vInt*(vInt+1)*(vInt+vInt+1))/6;
bw.write(resultado+"\n");
valor = br.readLine();
vInt = Integer.parseInt(valor);
}
bw.flush();
bw.close();
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String valor = br.readLine();
int vInt = Integer.parseInt(valor);
while(vInt != 0) {
int resultado = (vInt*(vInt+1)*(vInt+vInt+1))/6;
bw.write(resultado+"\n");
valor = br.readLine();
vInt = Integer.parseInt(valor);
}
bw.flush();
bw.close();
return;
}
}
Comments
Post a Comment