37 lines
1.1 KiB
C
37 lines
1.1 KiB
C
#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;
|
||
} |