Problem B: Handing Out Candies

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 272  Solved: 20
[Submit][Status][Web Board]

Description

After the 40th ACM-ICPC, Diao Yang is thinking about finding a girlfriend because he feels very lonely when doing ACM all the time. But because of his philandering, he finally decided to find N girlfriends. To achieve his goal, he wanted to find one girlfriend every day for N days continue. That is to say, at the ith day, he will have i girlfriends exactly.

In order to make his N girlfriends happy, he decided to buy M candies everyday for N days continue. Every day all of his girlfriends can get candies, and he will give each of them the same amount of candies and the amount will be as much as possible. Then if there are some candies left, he will eat them by himself.

Now the problem is, Diao Yang want to know how many candies he can eat total by himself after N days continue.

Input

The first line contains an integer T, indicating the total number of test cases. Each test case is a line with two integers N

15N"> and M (

151鈮?/m:t>N&lolt;231"> ,

150鈮?/m:t>M&lolt;231"> ).

Output

For each test case, output the answer in one line.   n,m在int范围内

Sample Input

2
5 7
6 4

Sample Output

7
9
题意:t组数据 输入n,m 求 m%i(1<=i<=n)的n项和

题解:思想就是 分段成部分等差数列 用求和公式求解

例如 n=60 m=100
m%(m/2)
m%51=49
m%52=48
....
m%60=40; 51~60 为等差为1的数列
....................................
m%(m/3)
m%34=32;
m%35=30;
...
m%49=2; 34~49 为等差为2的数列
....................................
知道m%(m/sqrt(m)) gou代码
 #include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
long long t,n,m,zhong,qi,di,chang;
long long ma;
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld",&n,&m);
ma=;
if(m==){
printf("%lld\n",n-);
continue;
}
if(m==)
{
printf("0\n");
continue;
}
if(m<=n){
ma+=(n-m)*m;
n=m-;
}
zhong=sqrt(m);
for(int i=m/n;i<zhong;i++)
{
qi=m%n;
chang=n-(m/(i+));
di=qi+(chang-)*i;
ma+=(qi+di)*chang/;
n=n-chang;
}
for(int i=n;i>;i--)
ma+=m%i;
printf("%lld\n",ma);
}
return ;
}

2016华中农业大学预赛 B 数学的更多相关文章

  1. 2016华中农业大学预赛 E 想法题

    Problem E: Balance Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 205  Solved: 64[Submit][Status][We ...

  2. 华中农业大学预赛 B Handing Out Candies 余数的和

    Problem B: Handing Out Candies Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 258  Solved: 19[Submit ...

  3. 寄生线虫免疫学研究新路径!华中农业大学胡敏团队报道寄生线虫N-糖基化修饰图谱

    N-糖基化修饰是真核生物中一种重要的蛋白质翻译后修饰,在许多生物学过程中起着关键作用,包括蛋白质折叠.受体-配体相互作用.免疫应答和疾病发病机制等.近年来,高精度质谱技术的出现促进了糖组和糖蛋白质组的 ...

  4. 2016/3/17 Mysq select 数学函数 字符串函数 时间函数 系统信息函数 加密函数

    一,数学函数主要用于处理数字,包括整型.浮点数等. ABS(X) 返回x的绝对值 SELECT ABS(-1)--返回1 CEll(X),CEILING(x)  返回大于或等于x的最小整数 SELEC ...

  5. [HZAU]华中农业大学第四届程序设计大赛网络同步赛

    听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include <algorithm> #include <iostream> #include ...

  6. (hzau)华中农业大学第四届程序设计大赛网络同步赛 G: Array C

    题目链接:http://acm.hzau.edu.cn/problem.php?id=18 题意是给你两个长度为n的数组,a数组相当于1到n的物品的数量,b数组相当于物品价值,而真正的价值表示是b[i ...

  7. 华中农业大学新生赛C题

    http://acm.hzau.edu.cn/problem.php?id=1099 题意: 输入两个整数 l 和 n,代表半径和output的保留小数点位数. 输出圆的面积,保留n位小数. 一开始觉 ...

  8. 华中农业大学第五届程序设计大赛网络同步赛-L

    L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...

  9. 华中农业大学第五届程序设计大赛网络同步赛-K

    K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And ...

随机推荐

  1. php学习【1】

    1:输出语句 <?php echo "hellow world"; print "hellow world"; print_r ("helow ...

  2. FreeBSD--常用命令

    FreeBSD常用命令   查看网络流量 a.systat -if 1 (1表示1s刷新屏幕一次) b.netstat 1 # Traffic 流量 peak 峰值 average 平均值 查看进程p ...

  3. 在ubuntu上安装subline

    Sublime Text is a most popular, lightweight and smart cross-platform text and source code editor wit ...

  4. xml中encoding

    前同天和同事在讨论xml里的encoding属性和文件格式的关系,终于彻底的弄清楚了.以前理解的是,xml里的encoding里定义必须与文件格式相匹配.即有这样的xml Introduction&l ...

  5. Flask初学者:蓝图Blueprint

    蓝图这个名字好像就是根据单词Blueprint字面意思来,跟平常我们理解的蓝图完全挂不上钩,这里蓝图就是指Blueprint. 使用蓝图的好处是可以将不同功能作用的视图函数/类视图放到不同的模块中,可 ...

  6. Block那些事儿

    1.Block底层原理实现 首先我们来看四个函数 void test1() { int a = 10; void (^block)() = ^{ NSLog(@"a is %d", ...

  7. 《Cracking the Coding Interview》——第8章:面向对象设计——题目2

    2014-04-23 17:45 题目:假设有个呼叫中心,有接线员.经理.主管三种角色.如果接线员无法处理呼叫,就上传给经理:如果仍无法处理,则上传给主管.请用代码描述这一过程. 解法:第一眼觉得这题 ...

  8. 油田(DFS)

    //DFS:油田问题 #include <iostream> using namespace std; ][]; int n,m; //一个网格的8个方向 ][] = {{-,-},{-, ...

  9. ASP.NET Core 2.1 源码学习之 Options[3]:IOptionsMonitor 【转】

    原文链接:https://www.cnblogs.com/RainingNight/p/strongly-typed-options-ioptions-monitor-in-asp-net-core. ...

  10. Python——数据类型之str

    本篇主要内容: 1.str元素的访问 2.str内置43个方法使用示例 str就是储存各种东西的字符串. 他的方法也是最多的...有各种各样的神奇魔法. 1.str的访问,str可以想列表那样访问每一 ...