# include <stdio.h>
# include <math.h>
int main(void)
{
int val,i;
do
{
scanf("%d", &val);
printf("%d = 1", val);
for (i=2; i<=(int)sqrt(val); ++i)
if (val%i == 0)
{
printf(" * %d", i);
val = val/i;
i = 1;
}
printf("\n");
} while (1);
return 0;
}
做了点小改动i<=(int)sqrt(val) 可以减少运算量
# include <math.h>
int main(void)
{
int val,i;
do
{
scanf("%d", &val);
printf("%d = 1", val);
for (i=2; i<=(int)sqrt(val); ++i)
if (val%i == 0)
{
printf(" * %d", i);
val = val/i;
i = 1;
}
printf("\n");
} while (1);
return 0;
}
做了点小改动i<=(int)sqrt(val) 可以减少运算量