Codeforces Round #644 (Div. 3) D——Buying Shovels

https://codeforces.ml/contest/1360/problem/D

#include <iostream>
#include <cstdio>
using namespace std;
int T,n,k;
void solve(){
	cin>>n>>k;
	if(k >= n) {cout<<"1"<<endl;return;}
	int ans;
	for(int i = 1; i*i <= n; i++){
		if(n % i == 0){
			if(n/i <= k) {cout<<i<<endl;return;}
			if(i <= k) ans = i;
		}
	}
	cout<<n/ans<<endl;
}
int main()
{
	cin>>T;
	for(int i = 1; i <= T; i++) solve();
	return 0;
}

总结:做了这道题终于意识到 i*i <= n 比 直接枚举到n 所用的时间少得多,以前只意识到当n很小的时候,确实省不了多少,但当n非常大时候,写成 i * i <= n 所省的时间是非常非常多的。

猜你喜欢

转载自www.cnblogs.com/Beic233/p/12969510.html