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;
}