C程序寻找一个数字的最大素数?
质因数-在数论中,正整数的质因数是将整数精确除的质数。查找这些数字的过程称为整数分解或素数分解。
示例-288的主要因子是:288=2x2x2x2x2x2x3x3
Input: n = 124 Output: 31 is the largest prime factor!
说明
您将找到一个数字的所有主要因素,并找到其中的最大因素。质因数124=2x2x31。其中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 !
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短