当前位置: 首页 > news >正文

每日一题(小白)暴力娱乐篇31

首先分析一下题意,需要求出2024的因子,因为我们要求与2024互质的数字,为什么呢?因为我们要求互质说直白点就是我和你两个人没有中间人,我们是自然而然认识的,那我们怎么认识呢,就是直接见面对吧,这里我们把公因子想象成媒介,与你有接触的人排除掉,那就不可能有媒介,因为我的所有朋友都不可能是你的朋友了,你的朋友都排除了。求出2024的因子,然后循环排除2024次接触,就是第2024小的与2024互质的数字啦。分析好了就很简单了,只需要学学怎么找因子,接下来的估计你就可以用暴力去解出来了!!!

求因子的代码👇

	public static void main(String[] args) {Scanner scan = new Scanner(System.in);int n=scan.nextInt();int count=0;for (int i = 2; i < n; i++) {//自己试试if (n%i==0) {System.out.print(i+" ");}}scan.close();}

①找到2024的因子

②循环递增i,i取余2024的因子,若不能取余ans++

③ans=2024即找到2024小的互质数字,返回

④输出结果

代码如下👇

	public static void main(String[] args) {Scanner scan = new Scanner(System.in);
//	    int n=scan.nextInt();int count=0;int[] arr=new int[14];for (int i = 2; i < 2024; i++) {if (2024%i==0) {arr[count++]=i;}}
//	    for (int i = 0; i < arr.length; i++) {
//			System.out.print(arr[i]+" ");
//		}测试点int ans=0;for (int i = 1; ; i++) {for (int j = 0; j < arr.length; j++) {if (i%arr[j]!=0) {ans++;break;}}if (ans==2024) {System.out.println(i);break;}}scan.close();}
	public static void main(String[] args) {Scanner scan = new Scanner(System.in);
//	    int n=scan.nextInt();int count=0;int[] arr=new int[14];for (int i = 2; i < 2024; i++) {if (2024%i==0) {arr[count++]=i;}}
//	    for (int i = 0; i < arr.length; i++) {
//			System.out.print(arr[i]+" ");
//		}测试点int ans=0;for (int i = 1; ; i++) {if (judice(i, arr)) {ans++;}if (ans==2024) {System.out.println(i);break;}}scan.close();}public static boolean judice(int num,int[] arr) {for (int i = 0; i < arr.length; i++) {if (num%arr[i]==0) {return false;}}return true;}

第一段代码错误,你能找出来为什么错误吗?

4655   //结果

相关文章:

  • Electricity Market Optimization(VI) - 机组组合问题的 GAMS 求解
  • 论文研读: LLaVA, 微调大模型以理解图像内容
  • pycharm配置python编译器,安装第三方库 (通俗易懂)
  • 【web考试系统的设计】
  • 前端开发 + Vue 2 + 卡片拖拽(带坐标系、左右互拖、多卡同容器)+ 学习参考
  • QT日历控件重写美化
  • T113S3学习记录—软件说明(三)
  • Linux:初学者的简单指令
  • CST仿真天线流程
  • 【Linux】第十章 配置和保护SSH
  • 探索Adobe软件的冷门技巧
  • Spring DI 详解
  • @Autowird 注解与存在多个相同类型对象的解方案
  • 【英语语法】基本句型
  • 大模型如何改变我们的日常生活
  • vue3 el-dialog新增弹窗,不希望一进去就校验名称没有填写
  • LeetCode hot 100—单词搜索
  • 泛微E10自定义“批准”按钮点击事件 —— 拦截逻辑实战分享
  • Agent2Agent(A2A)开放协议:构建智能代理协同生态的标准架构
  • 动态规划 -- 简单多状态dp,打家劫舍问题
  • 秦洪看盘|浮现新预期,存量资金积极调仓
  • 美乌总统梵蒂冈会谈,外交部:望有关各方继续通过对话谈判解决危机
  • 上海市市管干部任职前公示:赵亮拟为地区区长人选
  • QFII一季度现身超300家公司:持有南京银行市值最高,5家青睐立航科技
  • 伊朗外长:美伊谈判进展良好,讨论了很多技术细节
  • “冲刺万亿城市”首季表现如何?温州领跑,大连GDP超徐州