求助大佬!(50ptsRE)
查看原帖
求助大佬!(50ptsRE)
687911
chenyihao2011楼主2024/10/20 19:58

评测记录:https://www.luogu.com.cn/record/183635420

代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;

int t,n,k,l,r,mid,cnt;

signed main(){
	cin>>t;
	while(t--){
		scanf("%lld%lld",&n,&k);
		if(k==0 or n==k){
			printf("1\n");
			continue;
		}
		cnt=0;
		l=1;
		r=n;
		string s;
		while(l<=r){
			mid=(l+r)/2;
			if(n/mid<=k) r=mid-1;
			else if(n/mid>k) l=mid+1;
		}
		while(1){
			bool f=1;
			if(n/l!=k) break;
			int num=n-l*k;
			for(int i=0;i<cnt;i++) if(s[i]==num) f=0;
			if(f) s[cnt]=num,cnt++;
			l++;
		}
		printf("%d\n",cnt);
	}
 	return 0;
}

2024/10/20 19:58
加载中...