Light oj 1294 Positive Negative Sign

原创 2016年05月30日 22:19:48
T - T
Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

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 nintegers 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 nis divisible by 2*m.

Output

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

Sample Input

2

12 3

4 1

Sample Output

Case 1: 18

Case 2: 2

light oj不支持%i64d......醉了,再一次被坑到这了。。。。

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


版权声明:本文为博主原创文章,转载请注明出处。

相关文章推荐

Light OJ 1294 - Positive Negative Sign 【规律 水题】

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

LightOJ 1294:Positive Negative Sign

Given two integers: n and m and n is divisible by 2m, you have to write down the first n natural num...

js Number对象:属性MAX_VALUE、MIN_VALUE、NaN、NEGATIVE_INFINITY、POSITIVE_INFINITY

MAX_VALUE 属性是 JavaScript 中可表示的最大的数。它的近似值为 1.7976931348623157 x 10308 Number.MAX_VALUE MIN_VALUE 属...

HDU 5183 Negative and Positive (NP) (set + 读入外挂 乱搞)

HDU 5183 Negative and Positive (NP) (set + 读入外挂 乱搞)

hdu5183---Negative and Positive (NP)(HASHMAP)

Problem Description When given an array (a0,a1,a2,⋯an−1) and an integer K, you are expected to judg...

【Best Coder 】 32 B Negative and Positive (NP)

思路:题目是根据所给的规则,判断是否在一个区间i-j的结果等于k。 其实要求i-j区间的值我们可以采用1-j的值减去1-i的值即可得到i-j的值。 sum[j]-sum[i]=k sum[j]-...

hdu 5183-Negative and Positive (NP) (hash+输入外挂)

题意: 给定一个序列a[0],a[1]….a[n-1]和一个整数k,问是否有这样的两个下标使得 NP-Sum(i,j)=k,这里 NP-Sum(i,j)=a[i]-a[i+1]+a[i+2]-…+...

False positive and False negative (误报 漏报)

False positive和False negative这两个词广泛出现在各种领域,就计算机领域来说,通常出现在与安全有关的技术资料中,是什么意思呢?我们来分析一下。 首先,两个词的共有部分是Fal...
  • jo_say
  • jo_say
  • 2011-05-04 19:03
  • 1109

hdu 5183 Negative and Positive (NP)【fast IO +哈希表】

Negative and Positive (NP) Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja...

HDU 5183 - Negative and Positive (NP)(Hash)

题目: http://acm.hdu.edu.cn/showproblem.php?pid=5183 题意: 给出n个数以及k, 求出是否存在 (i,j) 使得 ai−ai+1+ai+2+⋯...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)