1294 - Positive Negative Sign
Time Limit: 2 second(s) Memory Limit: 32 MB

Given two integers: n and m and n is divisible by 2m, you have to write down the first n natural numbers in the following form. At first take first m integers and make their sign negative, then take next m integers and make their sign positive, the next m integers should have negative signs and continue this procedure until all the n integers have been assigned a sign. For example, let n be 12 and m be 3. Then we have

-1 -2 -3 +4 +5 +6 -7 -8 -9 +10 +11 +12

If n = 4 and m = 1, then we have

-1 +2 -3 +4

Now your task is to find the summation of the numbers considering their signs.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case starts with a line containing two integers: n and m (2 ≤ n ≤ 109, 1 ≤ m). And you can assume that n is divisible by 2*m.

Output

For each case, print the case number and the summation.

Sample Input

Output for Sample Input

2

12 3

4 1

Case 1: 18

Case 2: 2

#include<stdio.h>
#include<string.h>
#define LL long long
int main()
{
int t,k;
LL n,m,sum;
scanf("%d",&t);
k=1;
while(t--)
{
scanf("%lld%lld",&n,&m);
sum=(n/2)*m;
printf("Case %d: ",k++);
printf("%lld\n",sum);
}
return 0;
}

  

light oj 1294 - Positive Negative Sign的更多相关文章

  1. 1294 - Positive Negative Sign(规律)

    1294 - Positive Negative Sign   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

  2. LightOJ - 1294 - Positive Negative Sign(规律)

    链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m ...

  3. lightoj--1294--Positive Negative Sign(水题,规律)

    Positive Negative Sign Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu ...

  4. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  5. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  6. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  7. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  8. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  9. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

随机推荐

  1. location.search 详解

    JS中location.search什么意思 设置或获取网页地址跟在问号后面的部分 当以get方式在url中传递了请求参数时,可以利用location的search属性提取参数的值,下面的代码把参数的 ...

  2. .net和MVC中的json值和List<T>和DataTable的一些转换

    1.List<T>集合转换为Json值 List<ReportModel> dtList = new List<ReportModel>(); JsonResult ...

  3. ZOJ 3603 Draw Something Cheat

    点我看题目 题意 : 给你n个字符串,让你找出在每个字符串中出现的字母,按字典序输出来. 思路 :一开始想差了,以为记录下每个字符出现次数,然后找次数大于1的,可是我忘了可能在一个字符串中有AA,而另 ...

  4. 查看linux系统的版本

    1. 查看内核版本命令: 1) [root@SOR_SYS ~]# cat /proc/version Linux version 2.6.18-238.el5 (mockbuild@x86-012. ...

  5. float 和 real

      用于表示浮点数值数据的大致数值数据类型.浮点数据为近似值:因此,并非数据类型范围内的所有值都能精确地表示. 注意: real 的 SQL-92 同义词为 float(24). 数据类型 范围 存储 ...

  6. Android UI性能优化详解

    设计师,开发人员,需求研究和测试都会影响到一个app最后的UI展示,所有人都很乐于去建议app应该怎么去展示UI.UI也是app和用户打交道的部分,直接对用户形成品牌意识,需要仔细的设计.无论你的ap ...

  7. [译]GotW #3: Using the Standard Library (or, Temporaries Revisited)

    高效的代码重用是良好的软件工程中重要的一部分.为了演示如何更好地通过使用标准库算法而不是手工编写,我们再次考虑先前的问题.演示通过简单利用标准库中已有的算法来避免的一些问题. Problem JG Q ...

  8. windows上制作懒人版MAC cdr/iso

    本教程以XPS15 L501X机型为例在windows7下讲解Lion纯净系统的制作及安装过程,以及一些后续美化,如果已有mac系统,就更简单了,照猫画虎即可.主楼的帖子对新手来讲信息量太大,所以关于 ...

  9. ☀【动画】过渡 transition

    CSS3 动画系列3-transition(过渡) √http://www.css88.com/archives/5403 如果丘处机没有路过牛家村,中国将是最发达国家 <!DOCTYPE ht ...

  10. apache开源项目--JMeter

    JMeter是Apache组织的开放源代码项目,它是功能和性能测试的工具,100%的用java实现.