QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#585#376152#6823. Coffee OverdosezhutianruizhouqixuanFailed.2024-04-04 07:58:032024-04-04 07:58:03

Details

Extra Test:

Invalid Input

input:

1
00 00

output:


result:

FAIL Expected integer, but "00" found (test case 0, stdin, line 2)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376152#6823. Coffee OverdosezhouqixuanAC ✓19ms3948kbC++14565b2024-04-03 21:58:032024-04-08 20:50:09

answer

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
int n,m;
LL calc1(int n,int m){return (LL)n*(n-1)/2*m-(LL)(m-1)*m/2*n;}
LL calc2(int n,int m){return (LL)n*(n-1)/2*m-(LL)(m+1)*m/2*n;}
void calc(){
    scanf("%d%d",&n,&m);
    int k=min(m/2,n/m);
    LL ans1=calc1(m,k);
    k=(n-1)/m;
    int r=n-k*m;
    LL ans2=calc2(m,k)+(LL)m*r-(LL)r*(r+1)/2;
    printf("%lld\n",max(ans1,ans2)+(LL)n*(n+1)/2);
    return;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--) calc();
    return 0;
}