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代码
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <string>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <queue>
 8 #include <map>
 9 #include <set>
10 #include <stack>
11 #include <sstream>
12 #include <vector>
13 using namespace std;
14 int main()
15 {
16     long long t,n,m,zhong,qi,di,chang;
17     long long ma;
18     scanf("%lld",&t);
19      while(t--)
20      {
21         scanf("%lld %lld",&n,&m);
22         ma=0;
23         if(m==1){
24             printf("%lld\n",n-1);
25             continue;
26         }
27         if(m==0)
28         {
29             printf("0\n");
30             continue;
31         }
32         if(m<=n){
33             ma+=(n-m)*m;
34             n=m-1;
35         }
36         zhong=sqrt(m);
37         for(int i=m/n;i<zhong;i++)
38         {
39             qi=m%n;
40             chang=n-(m/(i+1));
41             di=qi+(chang-1)*i;
42             ma+=(qi+di)*chang/2;
43             n=n-chang;
44         }
45         for(int i=n;i>1;i--)
46             ma+=m%i;
47         printf("%lld\n",ma);
48      }
49     return 0;
50 }
时间: 2024-11-05 12:25:22

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

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

Problem E: Balance Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 205  Solved: 64[Submit][Status][Web Board] Description Every night Diao Ze is dreaming about the gold medal in the 1540th">  ACM-ICPC World Final. Not only does it represent the hon

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

Problem B: Handing Out Candies Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 258  Solved: 19[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

华中农业大学预赛 A

Description Diao Ze likes math very much, especially problems about equation. Now there is a problem for Diao Ze, but he is too lazy to solve it and he asks you for help: Giving two integers a  and b  , which satisfied the equation Then your task is

2014 年全国大学生数学竞赛预赛非数学类试题参考答案

华中农业大学第五届程序设计大赛 (7/12)

今天实在累了,还有的题晚点补.... 题目链接:http://acm.hzau.edu.cn/problemset.php?page=3 题目:acm.hzau.edu.cn/5th.pdf A:Little Red Riding Hood 题意:给你n朵花,每朵花有个权值,然后每次取花最少要间隔k朵,求权值最大: 思路:简单dp: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream&

华中农业大学第五届程序设计大赛网络同步赛解题报告(转)

A.Little Red Riding Hood B.Choosy in Food •F[i]:从第I个点到终点的期望步数 •F[i] = (F[i + k] + k ) * P[k] •F[ed] = 0 •高斯消元求解 •注意存在从起点不能到达终点的情况 C.Friends •F[rt][len] :节点rt的子孙里,距离rt的为len的节点个数 •ans[rt][len] : 整棵树上,距离rt为len的节点个数 •F值一次简单的深搜可以得到 •而ans[rt][len] = F[rt][

华中农业大学新生赛C题

http://acm.hzau.edu.cn/problem.php?id=1099 题意: 输入两个整数 l 和 n,代表半径和output的保留小数点位数. 输出圆的面积,保留n位小数. 一开始觉得用抑制符就可以了,然后发现它保留的时候会四舍五入,所以不行. 知识主要用到了floor函数(返回不大于传参值的最大整数(double)类型)以及sprintf. AC代码: 1 #include <stdio.h> 2 #include <string.h> 3 #include &

[家里蹲大学数学杂志]第435期第七届中国大学生数学竞赛预赛试题(数学类,2015年10月)参考解答

一. ($15'$) 设 $L_1$ 和 $L_2$ 是空间中两异面直线. 设在标准直角坐标系下直线 $L_1$ 过坐标为 $a$ 的点, 以单位向量 $v$ 为直线方向; 直线 $L_2$ 过坐标为 $b$ 的点, 以单位向量 $w$ 为直线方向.   (1). 证明: 存在唯一点 $P\in L_1$ 和 $Q\in L_2$ 使得两点连线 $PQ$ 同时垂直于 $L_1$ 和 $L_2$.   (2). 求 $P$ 点和 $Q$ 点坐标 (用 $a,b,v,w$ 表示). 证明: 由题意,

华中农业大学第五届程序设计大赛网络同步赛题解

A.Little Red Riding Hood B.Choosy in Food •F[i]:从第I个点到终点的期望步数 •F[i] = (F[i + k] + k ) * P[k] •F[ed] = 0 •高斯消元求解 •注意存在从起点不能到达终点的情况 C.Friends •F[rt][len] :节点rt的子孙里,距离rt的为len的节点个数 •ans[rt][len] : 整棵树上,距离rt为len的节点个数 •F值一次简单的深搜可以得到 •而ans[rt][len] = F[rt][