lightoj 1294 Positive Negative Sign 【规律】

原创 2016年06月01日 19:28:31

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 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 可以整除2*m,从1开始,每2*m 个数 减加求和

题解:有规律:每2*m个数的和为m*m,共有m*m*(n/(2*m))


代码:

#include <cstdio>
int main()
{
    int t,k=1;
    int n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        printf("Case %d: %d\n",k++,n*m/2);
    }
    return 0;
}


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

相关文章推荐

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

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

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

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

lightoj Basic Math 数论基础题 1414+1010+1020+1078+1116+1148+1179+1214+1275+1294+1297+1311+1323+1349+1354

//1008 - Fibsieve`s Fantabulous Birthday//1008 #include #include #include #define LL long long in...

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
  • 1091

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...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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