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

Submit
Status

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

Source

Problem Setter: Jane Alam Jan

#include<stdio.h>
#include<string.h>
long long m,n;
int main()
{
int t;
scanf("%d",&t);
int Case=1;
while(t--)
{
long long sum=0;
scanf("%lld%lld",&n,&m);
printf("Case %d: ",Case++);
sum=m*n/2;//就这麽一个简单的规律,超时好多次
printf("%lld\n",sum);
}
return 0;
}

lightoj--1294--Positive Negative Sign(水题,规律)的更多相关文章

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

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

  2. 1294 - Positive Negative Sign(规律)

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

  3. light oj 1294 - Positive Negative Sign

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

  4. LightOJ 1338 && 1387 - Setu && LightOJ 1433 && CodeForces 246B(水题)

    B - B Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status P ...

  5. LightOJ 1245 Harmonic Number (II) 水题

    分析:一段区间的整数除法得到的结果肯定是相等的,然后找就行了,每次是循环一段区间,暴力 #include <cstdio> #include <iostream> #inclu ...

  6. LightOJ 1259 Goldbach`s Conjecture 水题

    不想说了 #include <cstdio> #include <iostream> #include <ctime> #include <vector> ...

  7. LightOJ 1166 Old Sorting 置换群 或 贪心 水题

    LINK 题意:给出1~n数字的排列,求变为递增有序的最小交换次数 思路:水题.数据给的很小怎么搞都可以.由于坐标和数字都是1~n,所以我使用置换群求循环节个数和长度的方法. /** @Date : ...

  8. lightoj 1010 (水题,找规律)

    lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...

  9. LightOJ 1065 - Number Sequence 矩阵快速幂水题

    http://www.lightoj.com/volume_showproblem.php?problem=1065 题意:给出递推式f(0) = a, f(1) = b, f(n) = f(n - ...

随机推荐

  1. Android图片剪裁库

    最近利用一周左右的业余时间,终于完成了一个Android图片剪裁库,核心功能是根据自己的理解实现的,部分代码参考了Android源码的图片剪裁应用.现在将该代码开源在Github上以供大家学习和使用, ...

  2. hdu2680 Choose the best route 最短路(多源转单源)

    此题中起点有1000个,边有20000条.用链式前向星建图,再枚举起点用SPFA的话,超时了.(按理说,两千万的复杂度应该没超吧.不过一般说计算机计算速度 1~10 千万次/秒.也许拿最烂的计算机来卡 ...

  3. epoll的实现与深入思考

    提契 纸上得来终觉浅,绝知此事要躬行. 正文 前段时间写了一篇epoll的学习文章,但没有自己的心得总觉得比较肤浅,花了一些时间补充一个epoll的实例,并浅析一下过程中遇到的问题. 上epoll_s ...

  4. 命令模式 Command design pattern in C++

    参考https://sourcemaking.com/design_patterns/command/cpp/2 Create a class that encapsulates some numbe ...

  5. 动态规划——独立任务最优调度(Independent Task Scheduling)

    题目链接 题目描述 用2 台处理机A 和B 处理n 个作业.设第i 个作业交给机器A 处理时需要时间i a ,若由机器B 来处理,则需要时间i b .由于各作业的特点和机器的性能关系,很可能对于某些i ...

  6. SQL 到 NOSQL 的思维转变

    转自:http://blogread.cn/it/article/3130?f=wb SQL 到 NOSQL 的思维转变 NOSQL系统一般都会宣传一个特性,那就是性能好,然后为什么呢?关系型数据库发 ...

  7. webpack使用中遇到的相关问题

    问题一:使用webpack打包jquery后,在页面使用错误信息:$ is not defined new webpack.ProvidePlugin({ "$": "j ...

  8. file_get_contens POST传值

    <?php echo "<pre>"; print_r($_POST); print_r($_COOKIE); ?> 本文讲述的只是http post请求的 ...

  9. 在Tomcat中配置域名:linux下的配置

    域名的配置 端口要改成80 找到/usr/tomcat/apache-tomcat-8.5.30/conf的目录,找到server.xml文件,到 <Host name="localh ...

  10. [转载]解决/usr/bin/ld: cannot find -lxxx

    在linux环境编译应用程式或lib的source code时常常会出现如下的错误讯息: /usr/bin/ld: cannot find -lxxx 这些讯息会随着编译不同类型的source cod ...