1327. Fuses
Time limit:1.0 Second
Memory limit:64 MB
"Janus Poluektovich (I don ' t remember anymore whether-a or-u) used the machine only once. He brought with him a small semitransparent box, which he connected to the Aldan. In approximately ten seconds of operation with this device, all the circuit breakers blew, and Janus Poluektovich Apologiz Ed, took his box, and departed. "Sasha Privalov, a young programmer working in the srits (scientific. Institute for Thaumaturgy and Spellcraft), fi NDS his job rather enjoyable. Indeed, he is the only programmer of such a wonderful machine as Aldan-3-that's a refreshing shift from a dull job in Le Ningrad. There is just a single problem, and the problem's name is Janus poluektovich.on Privalov ' s first workday, Janus burdened a Ldan with the task of four-dimensional convolution in the conjuration space. Aldan worked for a while, flashing it lights and rewinding tapes, then a fuse blew and the machine shut down. Well, replacing fuses are something even a programmer can do. But Janus was rather absent-minded, and he, being lost in thoughts on his convolution problem, forgot about the weak fus E next day. So, on a third day Janus launched he program again, blowing another fuse. The fourth day went calmly, but on a fifth day one more fuse had to be replaced. And Janus is still not going to give up ... Nevertheless, THESE accidents don ' t bother Sasha, as long as he has enough spare fuses. Your task is to help Sasha in making the requisition for spare parts. The requsition is made for a specific period-from the a-th workday to the b-th workday inclusive. You should calculate, how many fuses Janus are going to blow with he programs in the specified period of time. Inputthe first line contains an integer A. The second line contains an integer b. 1≤a≤b≤10000.outputthe output should contain one number-the amount of fuses That'll be blown by Janus on the interval from day A until day b.samples
| input |
Output |
15 |
3 |
100200 |
50
|
Test instructions: Odd days will change one, even days do not change. Ask how many have changed from a day to B days (including A, b).
Resolution: Use (n + 1)/2 to calculate the number of changes to n days, the same number of M, and then directly minus. But when n is odd, the day is to change, so add the nth day of that!
AC Code:
#include <cstdio>int main () { int n, m, ans; while (scanf ("%d%d", &n, &m) ==2) { ans = (m + 1)/2-(n + 1)/2; if (n & 1) ans + +; Plus the nth Day swap for that printf ("%d\n", ans); return 0;}
URAL 1327. Fuses