Codeforces Round 870 (Div. 2)C. Dreaming of Freedom(数论、约数)

C. Dreaming of Freedom

题意:给定n个程序员,m个算法,每个人只能为一个算法投票,经过每轮投票后都只留下得票最高的程序,问最后会不会陷入循环,即出现几个程序平票的情况。

思路:我们考虑题目中无解的情况,即出现两个即以上的程序平票,也即在2~m中有n的因子,这样我们就可以去枚举n的因子判断是否在[2, m]内,即可,需要注意的是当n是一个质数时需要判断是否n<m,如果n<m也是有解的

cpp 复制代码
#include <bits/stdc++.h>
#define LL long long
#define x first
#define y second
 
using namespace std;
const int N = 2e5 + 10;
LL n, m, t;

void solve()
{
	cin >> n >> m;
	if(n <= m && n != 1)
	{
		puts("NO");
		return;
	}
	for(int i = 2; i <= n / i; ++ i)
		if(n % i == 0 && i <= m)
		{
			puts("NO");
			return;
		}

	puts("YES");
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen("1.in", "r", stdin);
	cin >> t;
	while(t --)	solve();
	return 0;
}
相关推荐
yolo_guo33 分钟前
redis++使用: hmset 与 hmget
c++·redis
凌波粒36 分钟前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
handler011 小时前
拒绝权限报错!三分钟掌握 Linux 权限管理
linux·c语言·c++·笔记·学习
拾贰_C1 小时前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
椰羊~王小美1 小时前
随机数概念及算法
算法
阿Y加油吧2 小时前
算法实战笔记:LeetCode 169 多数元素 & 75 颜色分类
笔记·算法·leetcode
t***5442 小时前
如何在Dev-C++中选择Clang编译器
开发语言·c++
橙子199110162 小时前
Java 基础相关
java·开发语言
不要秃头的小孩2 小时前
力扣刷题——509. 斐波那契数
python·算法·leetcode·动态规划