a215: 明明愛數數

題目:http://zerojudge.tw/ShowProblem?problemid=a215
程式碼:

import java.util.Scanner;
public class a215 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner sc = new Scanner(System.in);
  while(sc.hasNext()){
   int n = sc.nextInt();
   int m =sc.nextInt();
   int c = 1;
   int sum = n;//從n開始
   while(sum<=m){
    sum += (++n);
    ++c;
   }
   System.out.println(c);
  }

 }

}

留言

熱門文章