a216: 數數愛明明
題目:http://zerojudge.tw/ShowProblem?problemid=a216
程式碼:
程式碼:
import java.util.Scanner;
public class a216 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
System.out.println(f(n) + " " + g(n));
}
}
public static int f(int n){ //規律
return ((1 + n) * n) / 2;
}
public static long g(int n){
if(n==1){
return 1;
}else{
return f(n)+g(n-1);
}
}
}

留言
張貼留言