ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2025. Line Fighting

AC Visual C
Posted by Ntstharen 17 Aug 2019 21:01
#include<stdio.h>

int main(){
    int N, n, k, i, a, b, x, res;
    scanf("%d\n", &N);
    for(i=0; i<N; i++){
        scanf("%d %d", &n, &k);
        if(n%k==0){
            x=n/k;
            res=n*(n-x)/2;
            printf("%d\n", res);
        }
        else {
            x=n/k;
            b=n-k*x;
            a=k-b;
            res=((n-x)*a*x+(n-x-1)*(x+1)*b)/2;
            printf("%d\n", res);
        }
    }
    return 0;
}