天天看點

ZOJ 3629(找規律)

treasure hunt iv

time limit: 2 seconds      memory limit: 65536 kb

alice is exploring the wonderland, suddenly she fell into a hole, when she woke up, she found there are b - a + 1 treasures labled afrom b in front

of her.

alice was very excited but unfortunately not all of the treasures are real, some are fake.

now we know a treasure labled n is real if and only if [n/1] + [n/2] + ... + [n/k] + ... is even.

now given 2 integers a and b, your job is to calculate how many real treasures are there.

the input contains multiple cases, each case contains two integers a and b (0 <= a <= b <= 263-1) seperated by a single space.

proceed to the end of file.

output the total number of real treasure.

        額,找規律的題。看見 (0 <= a <= b <=

263-1) 時,就知道暴力會逾時了,是以就找規律吧!

       先寫一個暴力的程式打表,這樣的事以前也做過,一個循環節為197的規律題,打表隻到100,還以為夠了,結果那題沒找到規律,以後再做這樣的事的時候,先打表到10000再詳談!

  [0^2,1^2)                   1

  [2^2,3^2)                   5

  [4^2,5^2)                   9

  [6^2,7^2)                  13

  [8^2,9^2)                  17

  [10^2,11^2)              21

  [12^2,13^2)              25

  . . . .

  . . . . . .

ZOJ 3629(找規律)