4878485_pe.cpp

来自「部分PKU上的源码」· C++ 代码 · 共 38 行

CPP
38
字号
#include<iostream>
#include<math.h>
using namespace std;
	__int64 n,m,ch;
__int64 get(__int64 a)
{
	__int64 j;
	__int64 all=0;
	for(j=1;j<=n;j++)
	{
		__int64 t=(__int64)(sqrt((double)((ch+j)*(ch+j)-4*(j*j-ch*j-a)))-(ch+j))/(__int64)2;
		if(t>=n) all+=n;
		else if(t>=0) all+=t;
	}
	return all;
}
int main()
{
	int test;
	ch=100000;
	cin>>test;
	for(int count=0;count<test;count++)
	{
		scanf("%I64d%I64d",&n,&m);
		__int64 min,max;
		max=ch*ch*100;
		min=0-max;
		while(min<max-1)
		{
			__int64 mid=(min+max)/2;
			__int64 t=get(mid);
			if(t>=m) max=mid;
			else min=mid;
		}
		printf("%I64d ",max);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?