close

Problem Description

文文很喜歡偶數,他甚至有收集偶數的習慣。你給他一個範圍的連續整數,他就會把其中的偶數留下來收藏。如今他又拿到了一個範圍的整數,請問他這次收藏了幾個偶數?對文文來說,0 也算是一個偶數哦!    

The Input

輸入只有一行,其中含有兩個由空白隔開的整數 a, b (0 ≤ a ≤ b ≤ 2147483647)。

The Output

輸出一個整數,代表 a 與 b 之間 (含 a 與 b) 一共有多少個偶數。

Sample Input

1     4

Sample Output

2

-----* Problem from【ZeroJudge, an Online Judge System For Beginners

My Answer

 
1
2
3
4
5
6
7
8
9
10
11
  #include<iostream>
using namespace std;
int main(void)
{
  int a, b;
  while(cin>>a>>b){
    (a%2==0) ? cout<<(b/2)-(a/2)+1<<endl
      : cout<<(b/2)-(a/2)<<endl;
  }
  return 0;
}
 

 


arrow
arrow
    全站熱搜

    兔老大 發表在 痞客邦 留言(0) 人氣()