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. 基于WSAAsyncSelect模型的两台计算机之间的通信

    任务目标 编写Win32程序模拟实现基于WSAAsyncSelect模型的两台计算机之间的通信,要求编程实现服务器端与客户端之间双向数据传递.客户端向服务器端发送"请输出从1到1000内所有 ...

  2. 39条常见的Linux系统简单面试题

    39条常见的Linux系统简单面试题 本文主要分享39条常见的Linux系统简单面试题,其中包括如何看当前Linux系统有几颗物理CPU和每颗CPU的核数.如何实时查看网卡流量为多少等等,希望对你有所 ...

  3. JAVA / MySql 编程——第二章 初始MySQL

    1. MySQL:        ●  MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.            MySQL最流行的关系型数据库管理系统, ...

  4. 【yii2】rules规则的默认值

    ExampleModel.php /** * {@inheritdoc} */ public function rules() { return [ ['updated_at','default',' ...

  5. PHP 微信公众号真正正确的客服头像上传

    首先我们来看官方文档 这TM的搞笑呢 什么破玩意儿! 需要条件 1 需要有一个客服的账号 (废话) 2 一致jpg格式的图片(扯蛋) 完整流程 1 获取access_token 2获取账号 3 $ur ...

  6. iOS-delegate设计模式

    1. 使用场合 1> A想让B帮忙做一些事情,就让B成为A的代理 2> A想通知一下B发生了某些事情,或者想传递一些数据给B,就让B成为A的代理 3> B想监听A所做的一些事情, 就 ...

  7. Numpy基础数据结构 python

    Numpy基础数据结构 NumPy数组是一个多维数组对象,称为ndarray.其由两部分组成: 实际的数据 描述这些数据的元数据 1.一维数组 import numpy as np ar = np.a ...

  8. Partitioning by Palindromes UVA - 11584 简单dp

    题目:题目链接 思路:预处理出l到r为回文串的子串,然后如果j到i为回文串,dp[i] = min(dp[i], dp[j] + 1) AC代码: #include <iostream> ...

  9. Clion 不能杀死进程

    描述 自己使用时发现点了结束按钮后,打开任务管理器,发现刚才运行的程序还在,并没有被杀死. 有时如果一个程序写了死循环,就会出现疯狂占用内存,最后不得不关机重启. 解决方案 这是他的社区有人也有这样的 ...

  10. Java线程---简介

    实现方式 在java中线程有两种实现方式: 1.继承thread类 2.实现runnable接口 Thread类 Thread类时在java.lang包中定义的,继承thread类必须重写run()方 ...