Files
2023-02-21 10:56:54 +08:00

37 lines
1.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <stdio.h>
int main() {
int root = 2;// 若一个数有奇数个因子,那么它一定是平方数
int possibleFactor = 0;
int factorCount = 0;
int factors[5] = {0};
int testee = 0;
factors[0] = 1;
printf("1~1000内只包含5个因子的数是:\n");
for (;root < 32; root++) {
//31^2 < 1000 ^ 32^2只用考虑到31
testee = root*root;
factorCount = 0;
factors[2] = root;
factors[4] = testee;
for (possibleFactor = 2; (possibleFactor < root); possibleFactor++) {
if (testee % possibleFactor == 0) {
if (factorCount == 0) {
factors[1] = possibleFactor;
factors[3] = testee / possibleFactor;
factorCount++;
}
else {
factorCount++;
break;
}
}
}
if (factorCount == 1) {
printf("%3d: %4d%4d%4d%4d%4d\n",testee, factors[0], factors[1], factors[2], factors[3], factors[4]);
}
}
return 0;
}