题解:洛谷 AT_abc460_a [ABC460A] Mod While Positive
本文分享的必刷题目是从蓝桥云课、洛谷、AcWing等知名刷题平台精心挑选而来并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。欢迎大家订阅我的专栏算法题解C与Python实现附上汇总贴算法竞赛备考冲刺必刷题C | 汇总【题目来源】洛谷AT_abc460_a [ABC460A] Mod While Positive - 洛谷【题目描述】You are given positive integersN NNandM MM.If the following operation is repeated while the value ofM MMis not0 00, find the number of operations performed.Letx xxbe the remainder whenN NNis divided byM MM. Replace the value ofM MMwithx xx.It can be proved thatM MMbecomes0 00after a finite number of operations.给定正整数N NN和M MM。如果以下操作在M MM不等于0 00时重复执行求执行的操作次数。设x xx为N NN除以M MM的余数。将M MM的值替换为x xx。可以证明经过有限次操作后M MM会变为0 00。【输入】The input is given from Standard Input in the following format:N NNM MM【输出】Output the answer.【输入样例】8 5【输出样例】3【算法标签】#入门【代码详解】#includebits/stdc.husingnamespacestd;intn,m,ans;// n: 第一个数m: 第二个数ans: 步数计数器intmain(){cinnm;// 输入两个正整数while(n%m!0)// 当n不能被m整除时循环{/// n n % m; // 错误的写法应该是m n % mmn%m;// 用n对m取余更新mans;// 步数加1}coutans1endl;// 输出总步数return0;}【运行结果】8 5 3