A. Deadline,数论分块

Educational Codeforces Round 80 (Rated for Div. 2) A. Deadline

https://codeforces.com/contest/1288/problem/A
思路:dx+1=d+xx+1=1+d1x+1\lceil \frac{d}{x+1} \rceil=\lfloor\frac{d+x}{x+1}\rfloor=1+\lfloor\frac{d-1}{x+1}\rfloor,直接数论分块求出最小值即可
其他解法见:https://blog.csdn.net/xing_mo/article/details/103982101

#include<bits/stdc++.h>
using namespace std;
int n,d;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&d);
		--d;
		int minn = 1e9+5;
		if(d == 0)
			minn = 1;
		for(int l = 1,r;l <= d;l = r+1)
		{
			r = d/(d/l);
			minn = min(minn,l+d/l);
		}
		if(minn <= n)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}
发布了47 篇原创文章 · 获赞 1 · 访问量 2602
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览