我寫了這個算法來檢查一個數是否是素數,以及哪個數字將其分開。現在我想知道什麼是600851475143除數(例如),並輸出一個負數。 這是我的代碼:如何操縱C中的大數字?
#include <stdio.h>
/* Discover what numbers divide the one read as input, then show if it's prime */
int main() {
long checker;
long step = 1;
int divisors = 0;
printf("Enter with the number you want know the divisors: ");
scanf("%d", &checker);
while(step <= checker){
/* check which numbers divide the number read*/
if (checker % step == 0) {
printf("%d divides %d\n", step, checker);
step +=1;
divisors +=1;
}
else{
step+=1;
}
}
/*Now check if it is prime*/
if (divisors == 2) {
printf("ADDITIONAL INFO: %d IS a prime number.\n", checker);
}
else {
printf("ADDITIONAL INFO: %d IS NOT a prime number.\n", checker);
}
printf("Done!\n");
return 0;
}
有趣的是,人們甚至沒有讀我之前downvoting我。我已經在使用長型變量。 –