对我说的问题是这样的:
“数字 600851475143 的最大质因数是多少?”
该程序用于使用 C 来找到答案:
#include<math.h> // for remainder because % does not work with double or floats
#include<stdio.h>
main()
{
double x=600851475143,y=3.0;
while(x!=y) // divide until only the number can divide itself
{
if(remainder((x/y),1)==0.0) // if x is divisible by y which means it is a factor then do the magic
{
x=x/y; // divide the number x by y thereby reducing one constituent factor
}
y=y+2; // add 2 simply because only odd numbers can be prime and hence only prime numbers can be prime factors
}
printf("%lf",y); // do the printing magic
}
问题正是要问你,我试图检查 x 除以所有奇数,但请注意,并非所有奇数都不是素数,算法中的这个缺陷应该导致答案错误,因为实际上我应该是检查主要因素(不是奇数因素)。
令人惊讶的是,这个程序吐出的答案是正确的,我检查了答案。
我该如何解决这个问题?它没有任何意义。