LightOJ 1294:Positive Negative Sign

原创 2016年05月31日 14:03:05

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 mintegers 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

2

12 3

4 1

Sample Output

Case 1: 18

Case 2: 2

题意:求前n项的和,可以发现每2m项的和为一个常数。经过推导最终结果为m*n/2。

代码如下:

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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...

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

1294 - Positive Negative Sign PDF (English) Statistics Forum Time Limit: 2 second(...
  • wyjwyl
  • wyjwyl
  • 2015年11月08日 20:02
  • 229

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]-…+...

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

题意:问有没有数对(i,j)(0

False positive and False negative (误报 漏报)

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

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...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LightOJ 1294:Positive Negative Sign
举报原因:
原因补充:

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