E. Klee's SUPER DUPER LARGE Array!!!
E. Klee's SUPER DUPER LARGE Array!!!
# Klee's SUPER DUPER LARGE Array!!!
题面翻译
题目大意
你将得到一个长度为
输入格式
本题存在多组测试数据。第一行为一个正整数
输出格式
对于每组数据,输出一行一个整数
题目描述
Klee has an array
Output the minimum possible value of
输入格式
The first line contains
Each test case contains two integers
输出格式
For each test case, output the minimum value of
样例 #1
样例输入 #1
4
2 2
7 2
5 3
1000000000 1000000000
样例输出 #1
1
5
1
347369930
提示
In the first sample,
In the third sample,
题解
#include <bits/stdc++.h>
#define int long long
using namespace std;
int f(int x,int b,int c){
return (int)abs(x*x+b*x-c);
}
signed main(){
int t,n,k;
cin>>t;
while(t--){
cin>>n>>k;
int b=2*k-1,c=(n*(2*k+n-1)/2);
double delta=1.0*b*b+4.0*c;
double x=1.0*(sqrt(delta)-1.0*b)/2.0;
int nx=(int)x;
cout<<min(f(nx,b,c),f(nx+1,b,c))<<endl;
}
return 0;
}