我很好奇为什么这段代码找不到最大的素因子。 我无法找到数学和/或逻辑错误。
#include <stdio.h>
int compute( int input ) {
int biggest_primefactor = 1;
while(input > biggest_primefactor) {
int i = 2;
while(input%i != 0) i++; /* find factor, which is a primefactor */
input /= i;
if( i > biggest_primefactor) biggest_primefactor = i;
}
return biggest_primefactor;
}
void main () {
unsigned long long int input = 600851475143;
printf("%d", compute( input ));
}
输出为1