只用判断100以内的范围,因为1-100内的质数也少于1/3.

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <set>
using namespace std;

bool divide(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x % i == 0)
			return false;
	}
	return true;
}

//void Prime() {
//	for (int i = 2; i <= 1e3; i++) {
//		if (is[i])
//			continue;
//		printf("%d ", i);
//		for (int j = 2; i * j <= 1e3; j++)
//			is[i * j] = 1;
//	}
//}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		int l, r;
		scanf("%d%d", &l, &r);
		if (r - l + 1 > 100) {
			printf("Yes\n");
			continue;
		}
		int cnt = 0;
		for (int i = l; i <= r; i++) {
			if (divide(i)) {
				cnt++;
			}
		}
		if (3 * cnt < r - l + 1)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐