2016华中农业大学预赛 B 数学
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 数学的更多相关文章
- 2016华中农业大学预赛 E 想法题
Problem E: Balance Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 205 Solved: 64[Submit][Status][We ...
- 华中农业大学预赛 B Handing Out Candies 余数的和
Problem B: Handing Out Candies Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 258 Solved: 19[Submit ...
- 寄生线虫免疫学研究新路径!华中农业大学胡敏团队报道寄生线虫N-糖基化修饰图谱
N-糖基化修饰是真核生物中一种重要的蛋白质翻译后修饰,在许多生物学过程中起着关键作用,包括蛋白质折叠.受体-配体相互作用.免疫应答和疾病发病机制等.近年来,高精度质谱技术的出现促进了糖组和糖蛋白质组的 ...
- 2016/3/17 Mysq select 数学函数 字符串函数 时间函数 系统信息函数 加密函数
一,数学函数主要用于处理数字,包括整型.浮点数等. ABS(X) 返回x的绝对值 SELECT ABS(-1)--返回1 CEll(X),CEILING(x) 返回大于或等于x的最小整数 SELEC ...
- [HZAU]华中农业大学第四届程序设计大赛网络同步赛
听说是邀请赛啊,大概做了做…中午出去吃了个饭回来过掉的I.然后去做作业了…… #include <algorithm> #include <iostream> #include ...
- (hzau)华中农业大学第四届程序设计大赛网络同步赛 G: Array C
题目链接:http://acm.hzau.edu.cn/problem.php?id=18 题意是给你两个长度为n的数组,a数组相当于1到n的物品的数量,b数组相当于物品价值,而真正的价值表示是b[i ...
- 华中农业大学新生赛C题
http://acm.hzau.edu.cn/problem.php?id=1099 题意: 输入两个整数 l 和 n,代表半径和output的保留小数点位数. 输出圆的面积,保留n位小数. 一开始觉 ...
- 华中农业大学第五届程序设计大赛网络同步赛-L
L.Happiness Chicken brother is very happy today, because he attained N pieces of biscuits whose tast ...
- 华中农业大学第五届程序设计大赛网络同步赛-K
K.Deadline There are N bugs to be repaired and some engineers whose abilities are roughly equal. And ...
随机推荐
- php mysql find_in_set函数 检索单子段 逗号分隔序列
FIND_IN_SET($kwd,field) 例如在 表 AA中 numbers 字段 保存列数据 1,4,8,75,41,7 就可以使用 FIND_IN_SET(8,numbers) 查询记 ...
- 简单php实现同一时间内一个账户只允许在一个终端登陆
在账户表的基础上,我新建了一个账户account_session表,用来记录登录账户的account_id和最新一次登录成功用户的session_id,然后首先要修改登录方法:每次登录成功后,要将登录 ...
- Aizu:0005-GCD and LCM
GCD and LCM Time limit 1000 ms Memory limit 131072 kB Problem Description Write a program which comp ...
- SpringMVC文件上传——bean的配置【org.springframework.web.multipart.commons.CommonsMultipartResolver】
一.简介 Spring MVC支持一个通用的多路上传解析器CommonsMultipartResolver,在Spring的配置文件中对CommonsMultipartResolver Bean进行配 ...
- python基础之函数参数、嵌套、返回值、对象、命名空间和作用域
函数的使用原则 函数的使用必须遵循:先定义后使用的原则 函数的定义,与变量的定义是相似的,如果没有事先定义函数而直接引用就相当于在引用一个不存在变量名 定义阶段:只检测语法,不执行代码,当出现语法错误 ...
- 9.3centos7安装python3 以及tab补全功能
1.安装python3 1.1下载python源码包 网址:https://www.python.org/downloads/release/python-362/ 下载地址:https://www. ...
- 7 Django分页器文章分页
1.复习 2.这节课要解决的问题? 3.分页的原理 4.准备工作 (1)创建Django项目 C:\Users\Administrator\Desktop\root3>django-admin ...
- UOJ #2321. 「清华集训 2017」无限之环
首先裂点表示四个方向 一条边上都有插头或者都不有插头,相当于满足流量平衡 最大流 = 插头个数*2时有解 然后求最小费用最大流 黑白染色分别连原点汇点
- python 10月30日复习
1.把一个数字的list从小到大排序,然后写入文件,然后从文件中读取出来文件内容,然后反序,在追加到文件的下一行中 import codecs list1 = [2,23,8,54,86,12] li ...
- (1)strchr
const char * strchr ( const char * str, int character ); char * strchr ( char * str, int character ) ...