解題絲路 fn = f(n) , gn=g(n) 至於 f(n) = n + f(n-1)
f(n-1)就會是 上一個迴圈的fn
n 是 i
import java.util.Scanner;
public class a216 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
while (input.hasNextInt()) {
int n = input.nextInt();
long fn = 0;
long gn = 0;
for (int i = 1; i <= n; i++) {
fn = i + fn;
gn = fn + gn; //gn 跟現在的fn會跟上一個gn
}
System.out.print(fn + " ");
System.out.println(gn);
}
}
}