Problem b:handing out Candiestime limit:1 Sec Memory limit:128 MB
submit:258 solved:19
[Submit] [Status] [Web Board] Description
After the 40th ACM-ICPC, Diao Yang was thinking about finding a girlfriend because he feels very lonely when doing ACM all the time. But because's philandering, he finally decided to find N girlfriends. To achieve him goal, he wanted to find one girlfriend every day for N days continue. That was to say, at the ith Day, he would have I girlfriends exactly.
In order to make his N girlfriends Happy, he decided to buy M candies Everyday for N days Conti Nue. Every day any of his girlfriends can get candies, and he'll give each of the them same of amount and the candies Would be as much as possible. Then if there is some candies left, he'll eat them by himself.
Now the problem are, Diao Yang want to know how many candies he can eat total by himself after N days continue.
Input
The first line contains a integer T, indicating the total number of test cases. Each test case was a line with the integers N 15N "style=" Box-sizing:border-box; width:9pt; height:15.75pt; "> M ( 151 niobium/m:t>n&lolt;231" style= "Box-sizing:border-box; width:63.75pt; height:15.75pt; ">, 150 niobium/m:t>m&lolt;231" style= "Box-sizing:border-box; width:65.25pt; height:15.75pt;" >).
Output
For each test case, the output of the answer in one line.
Sample Input
25 76 4
Sample Output
79
N
Test instructions: Seeking ∑ (m%i);
I=1
Idea: Will find M to a number to model into arithmetic progression;
#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<queue>#include<algorithm>#include<stack>#include<cstring>#include<vector>#include<list>#include<Set>#include<map>using namespacestd;#definell Long Long#defineMoD 1000000007#defineINF 999999999#defineESP 0.00000000001//#pragma COMMENT (linker, "/stack:102400000,102400000")intScan () {intres =0, ch; while( ! (ch = getchar ()) >='0'&& CH <='9' ) ) { if(ch = = EOF)return 1<< - ; } Res= CH-'0' ; while(ch = getchar ()) >='0'&& CH <='9') Res= Res *Ten+ (CH-'0' ) ; returnRes;}intMain () {ll x,y,z,i,t; scanf ("%lld",&x); while(x--) {scanf ("%lld%lld",&y,&z); ll ans=max (Y-Z,0LL) *Z; ll Huan=min (y,z); for(i=2; i<=huan;i++) { if(z%i!=0) {ll d=z/i; LL Maxx=min ((z%i)/d+1, huan-i+1); D=-D; Ans+ = (z%i) *maxx+ (maxx* (maxx-1)/2)*D; } I+=d-1; } printf ("%lld\n", ans); } return 0;}
The handing of the candies remainder of the preliminary round B of Huazhong Agricultural University