light oj 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的更多相关文章
- 1294 - Positive Negative Sign(规律)
1294 - Positive Negative Sign PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- LightOJ - 1294 - Positive Negative Sign(规律)
链接: https://vjudge.net/problem/LightOJ-1294 题意: Given two integers: n and m and n is divisible by 2m ...
- lightoj--1294--Positive Negative Sign(水题,规律)
Positive Negative Sign Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
随机推荐
- Spring MVC 注解和XML的区别
注解与XML配置的区别 注解:是一种分散式的元数据,与源代码紧绑定. xml:是一种集中式的元数据,与源代码无绑定. 因此注解和XML的选择上可以从两个角度来看:分散还是集中,源代码绑定/无绑定. ...
- 图片上传iOS
//图片上传 - (void)upLoadImage{ if(self.frontImage && self.backImage){ //性别 NSString *sexStr; if ...
- 在asp.net中如何自己编写highcharts图表导出到自己的服务器上来
1.准备工作:网上下载highcharts导出的关键dll. 1).Svg.dll:因为highcharts的格式其实就是一个xml,采用svg的方式画图: 2).itextsha ...
- 深入研究java.lang.ProcessBuilder类
深入研究java.lang.ProcessBuilder类 一.概述 ProcessBuilder类是J2SE 1.5在java.lang中新添加的一个新类,此类用于创建操作系统进程,它 ...
- 下拉框点链接js
$("#input_text").click(function(){ $("#input_fonts").show(); }); $("#input_ ...
- eclipse, Log4j配置(真心的详细~)
转自: http://www.cnblogs.com/alipayhutu/archive/2012/06/21/2558249.html a). 新建Java Project>>新建pa ...
- Android开发之PackageManager类
PackageManger,可以获取到手机上所有的App,并可以获取到每个App中清单文件的所有内容. 设置应用程序版本号在应用程序的manifest文件中定义应用程序版本信息.2个必须同时定义的属性 ...
- Android开发UI之去掉title bar
去掉屏幕上的title bar有3个方法: 1.java代码实现: @Override publicvoid onCreate(Bundle savedInstanceState) { super.o ...
- DedeCMS 5.7 config.php 跨站脚本漏洞
漏洞版本: DedeCMS 5.7 漏洞描述: DeDeCMS v5.7 在/include/dialog/config.php文件中存在XSS漏洞,攻击者可以利用该漏洞盗取用户Cookie.挂马等. ...
- NOI2010超级钢琴 2
2006: [NOI2010]超级钢琴 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 1296 Solved: 606[Submit][Status ...