社区讨论

81pts WA on #41~49 玄关求调

P14955元素选择参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mjy6zi0y
此快照首次捕获于
2026/01/03 19:00
2 个月前
此快照最后确认于
2026/01/03 19:05
2 个月前
查看原帖
CPP
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll M=8e8;
int t;
ll n,m,k,p;
ll upp(ll a,ll b) {
	if(b==0) return -999;
	ll res=a/b;
	if(a%b) res++;
	return res;
}
bool chk(ll tot,ll s) {
	ll nd=upp(tot,s);
	if(nd>m) return false;
	ll w=(tot/s)*(tot/s-1ll)/2ll*s+tot/s*(tot%s);
	return w<=k&&w>0;
}
int main() {
	cin>>t;
	while(t--) {
		cin>>n>>m>>k;
		if((m==1||k==0)&&n!=1) {
			cout<<-1<<endl;
			continue;
		}
		ll ans;
		if(n>=k) ans=n/k-1,n=k+n%k;
		else ans=0;
		ll l=1,r=n/2+1;
		while(n!=1) {
			//p hezi
			//n*(p-1)/2
			l=max(1ll,n/M),r=min(r,n/2+1);
			ll mid,res=-1;
			while(l<=r) {
				mid=(l+r)/2;
				if(chk(n,mid)) r=mid-1,res=mid;
				else l=mid+1;
			}
			r=res;
			if(res==-1) n=max(n-k,k);
			else n=res;
			ans++;
		}
		cout<<ans<<endl;
	}
}

回复

0 条回复,欢迎继续交流。

正在加载回复...