Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

Recently, she was presented with an array aa of the size of 109109 elements that is filled as follows:

a1=−1
a2=2
a3=−3
a4=4
a5=−5
And so on ...
That is, the value of the ii-th element of the array aa is calculated using the formula ai=i⋅(−1)iai=i⋅(−1)i.

She immediately came up with qq queries on this array. Each query is described with two numbers: ll and rr. The answer to a query is the sum of all the elements of the array at positions from ll to rr inclusive.

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

Help her find the answers!

Input

The first line contains a single integer qq (1≤q≤1031≤q≤103) — the number of the queries.

Each of the next qq lines contains two integers ll and rr (1≤l≤r≤1091≤l≤r≤109) — the descriptions of the queries.

Output

Print qq lines, each containing one number — the answer to the query.

Example

input

Copy

5
1 3
2 5
5 5
4 4
2 3
output

Copy

-2
-2
-5
4
-1
Note

In the first query, you need to find the sum of the elements of the array from position 11 to position 33. The sum is equal to a1+a2+a3=−1+2−3=−2a1+a2+a3=−1+2−3=−2.

In the second query, you need to find the sum of the elements of the array from position 22 to position 55. The sum is equal to a2+a3+a4+a5=2−3+4−5=−2a2+a3+a4+a5=2−3+4−5=−2.

In the third query, you need to find the sum of the elements of the array from position 55 to position 55. The sum is equal to a5=−5a5=−5.

In the fourth query, you need to find the sum of the elements of the array from position 44 to position 44. The sum is equal to a4=4a4=4.

In the fifth query, you need to find the sum of the elements of the array from position 22 to position 33. The sum is equal to a2+a3=2−3=−1a2+a3=2−3=−1.

题解:对于多种情况考虑分析即可

---------------------
作者:black_hole6
来源:CSDN
原文:https://blog.csdn.net/lbperfect123/article/details/84449954
版权声明:本文为博主原创文章,转载请附上博文链接!

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; int main()
{
int n;
cin>>n; for(int t=;t<n;t++)
{
int a,b;
long long int sum;
scanf("%d%d",&a,&b);
if(a%==&&b%==)
{
sum=-*((a-b)/+b);
}
else if(a%==&&b%==)
{
sum=(b-a+)/;
}
else if(a%==&&b%==)
{
sum=-*(b-a+)/;
}
else
{
sum=(a-b)/+b;
}
printf("%lld\n",sum); }
return ;
}

Margarite and the best present的更多相关文章

  1. Codeforces Round #524 (Div. 2) B. Margarite and the best present

    B. Margarite and the best present 题目链接:https://codeforces.com/contest/1080/problem/B 题意: 给出一个数列:an=( ...

  2. CF1080B Margarite and the best present 题解

    Content 有 \(t\) 次询问,每次询问给定两个整数 \(l,r\),求 \(\sum\limits_{i=l}^r (-1)^i\times i\). 数据范围:\(1\leqslant t ...

  3. Codeforces Round #524 (Div. 2)

    A. Petya and Origamitime limit per test1 secondmemory limit per test256 megabytesinputstandard input ...

  4. Codeforces Round #524 (Div. 2) Solution

    A. Petya and Origami Water. #include <bits/stdc++.h> using namespace std; #define ll long long ...

  5. CodeForces-Round524 A~D

    A. Petya and Origami time limit per test  1 second   memory limit per test  256 megabytes input stan ...

  6. Codeforces Round #524 (Div.2)题解

    题解 CF1080A [Petya and Origami] 这道题其实要我们求的就是 \[\lceil 2*n/k \rceil + \lceil 5*n/k \rceil + \lceil 8*n ...

  7. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  8. 跳转时候提示Attempt to present on while a presentation is in progress

    出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...

  9. find your present (感叹一下位运算的神奇)

    find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. ajax跨域请求-jsonp

    1. 同源策略 ajax之所以需要“跨域”,罪魁祸首就是浏览器的同源策略.即,一个页面的ajax只能获取这个页面相同源或者相同域的数据. 如何叫“同源”或者“同域”呢?——协议.域名.端口号都必须相同 ...

  2. hadoop-eclipse-plugin-2.6.0-cdh5.4.0 插件编译

    1.JDK配置 1) 安装jdk 2) 配置环境变量 JAVA_HOME.CLASSPATH.PATH等设置 2.Eclipse 1).下载eclipse-jee-juno-SR2.rar 2).解压 ...

  3. dp-最小点对问题

    dp-最小点对问题 //最小点对问题 //采用分治思想,先分成两个子集分别求出最短距离d //再对两个子集进行合并,在一个dx2d的矩形中,最多可能有6个点距离小于d //按y排序,当x增长时求出这6 ...

  4. The Independent JPEG Group's JPEG software Android源码中 JPEG的ReadMe文件

    The Independent JPEG Group's JPEG software========================================== README for rele ...

  5. LINUX oracle dbca无法启动

    LINUX操作系统中执行DBCA无法启动 方法:执行以下命令后再执行DBCA xhost +

  6. Windows中lib和DLL区别和使用

    本文转载自:http://www.cppblog.com/amazon/archive/2009/09/04/95318.html 共有两种库:一种是LIB包含了函数所在的DLL文件和文件中函数位置的 ...

  7. Linux 控制台/终端/tty/shell

    一.简介 使用linux已经有一段时间,却一直弄不明白这几个概念之间的区别.这些概念本身有着非常浓厚的历史气息,随着时代的发展,他们的含义也在发生改变,它们有些已经失去了最初的含义,但是它们的名字却被 ...

  8. idea中解决Error:java: Compilation failed: internal java compiler error的问题

    项目中,使用gradle做项目构建,当我们想更改JDK的版本时,报以下错误: Information:Using javac 1.8.0_111 to compile java sourcesInfo ...

  9. 2016年第七届蓝桥杯省赛试题(JavaA组)

    1.结果填空 (满分3分)2.结果填空 (满分5分)3.结果填空 (满分9分)4.代码填空 (满分11分)5.代码填空 (满分13分)6.结果填空 (满分15分)7.结果填空 (满分19分)8.程序设 ...

  10. linq 事务处理

    首先引用使名空间: using System.Transactions; 然后写入代码: using (TransactionScope ts = new TransactionScope()) { ...