
Prime Factor− In number theory, the prime factors of a positive integer are the prime numbers that divide that integer exactly. The process of finding these numbers is called integer factorization, or prime factorization.
Example− Prime factors of 288 are: 288 = 2 x 2 x 2 x 2 x 2 x 3 x 3
Input: n = 124 Output: 31 is the largest prime factor!
您将找到一个数字的所有质因数,并找到其中最大的质因数。124的质因数为2 x 2 x 31,其中31是最大的质因数。
#include <stdio.h>
int main() {
long int n;
n=3453;
long int div=2, ans = 0, maxFact;
while(n!=0) {
if(n % div !=0)
div = div + 1;
else {
maxFact = n;
n = n / div;
if(n == 1) {
printf("%d is the largest prime factor !",maxFact);
ans = 1;
break;
}
}
}
return 0;
}1151 is the largest prime factor !
以上就是C程序用于找到一个数的最大质因子的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号