2016年7月3日 星期日

Q10783: Odd Sum


https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1724

import java.util.*;

public class Main {

 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  int n = scn.nextInt();
  for (int i = 0; i < n; i++) {
   int a = scn.nextInt(), b = scn.nextInt(), tot = 0;
   if (a % 2 == 0)
    a += 1;
   for (int j = a; j <= b; j += 2) {
    tot += j;
   }
   System.out.printf("Case %d: %d\n", i + 1, tot);
  }
 }

 /* 
    題目:Q10783: Odd Sum
    作者:1010
    時間:西元 2016 年 7 月 */
}


困難度 
這題很簡單就是把範圍內(包含自己)所有的奇數加起來

沒有留言:

張貼留言