URAL 1327. Fuses

33 篇文章 0 订阅

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 apologized, took his box, and departed."
Sasha Privalov, a young programmer working in the SRITS (Scientific Research Institute for Thaumaturgy and Spellcraft), finds 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 Leningrad. There is just a single problem, and the problem's name is Janus Poluektovich.
On Privalov's first workday, Janus burdened Aldan with the task of four-dimensional convolution in the conjuration space. Aldan worked for a while, flashing its lights and rewinding tapes, then a fuse blew and the machine shut down. Well, replacing fuses is something even a programmer can do. But Janus is rather absent-minded, and he, being lost in thoughts about his convolution problem, forgot about the weak fuse next day. So, on a third day Janus launched his 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 is going to blow with his programs in the specified period of time.

Input

The first line contains an integer A. The second line contains an integer B. 1 ≤ A ≤ B ≤ 10000.

Output

The output should contain one number - the amount of fuses that will be blown by Janus in the interval from day A until day B.

Samples

input output
1
5
3
100
200
50




题意:第奇数天会换一个,偶数天不变。问从A天到B天(包括A, B)换了多少个。

解析:用(n + 1)/2算出到n天为止一共换了多少,同样算出m的个数,然后直接减。但是当n为奇数的时候,当天是要换的,所以要再加上第n天的那个!




AC代码:

#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 ++;             //加上第n天换的那个
        printf("%d\n", ans);
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值