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;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!