ABC 296 D - M<=ab

该编程问题要求找到最小的正整数X,它能表示为1到N之间两个整数a和b的乘积,并且至少等于M。解决策略是枚举因子i(小于1e6),然后计算与之相乘大于等于M的因子y,检查y是否在范围内,从而找到最小的X。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Statement

You are given positive integers N and M.
Find the smallest positive integer X that satisfies both of the conditions below, or print −1 if there is no such integer.

  • X can be represented as the product of two integers a and b between 1 and N, inclusive. Here, a and b may be the same.
  • X is at least M.

Constraints

  • 1≤N≤1e12
  • 1≤M≤1e12
  • N and M are integers.

数学,思维小题

思路:容易发现必有一个因子小于等于1e6

所有我们可以枚举这个因子x,看看另一个与之相乘大于等于m的因子y(这个因子的求法其实就是m/x上取整)看看y在不在要求的范围内就可以了~

int T;
ll n,m;
void solve()
{
	cin>>n>>m;
	ll w=INF_LONG;
	for(ll i=1;i<=min(n,(ll)1e6);i++)
	{
		ll tem = (m+i-1)/i;
		
		if(tem<=n)
		 w=min(w,tem*i);
		 
	}
	
	if(w==INF_LONG)cout<<-1;
	else cout<<w<<endl;
	
}
int main()
{
	
	//IOS;
	//T=read();
	T=1;
	while(T--){solve();};
	
	
	return 0;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值