You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.0 KiB
68 lines
1.0 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
|
|
void findFactors(int num)
|
|
{
|
|
int i, exponent = 0;
|
|
printf("%d =", num);
|
|
|
|
while (num % 2 == 0)
|
|
{
|
|
exponent++;
|
|
num /= 2;
|
|
}
|
|
if (exponent > 1)
|
|
{
|
|
printf(" 2^%d *", exponent);
|
|
}
|
|
else if (exponent == 1)
|
|
{
|
|
printf(" 2 *");
|
|
}
|
|
for (i = 3; i * i <= num; i += 2)
|
|
{
|
|
exponent = 0;
|
|
while (num % i == 0)
|
|
{
|
|
exponent++;
|
|
num /= i;
|
|
}
|
|
if (exponent > 1)
|
|
{
|
|
printf(" %d^%d *", i, exponent);
|
|
}
|
|
else if (exponent == 1)
|
|
{
|
|
printf(" %d *", i);
|
|
}
|
|
}
|
|
if (num != 1)
|
|
{
|
|
printf(" %d *", num);
|
|
}
|
|
printf("\b \n");
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int num;
|
|
|
|
if (argc != 2)
|
|
{
|
|
printf("Usage: %s <Integer>\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
num = atoi(argv[1]);
|
|
if (num <= 1)
|
|
{
|
|
printf("%d\n", num);
|
|
}
|
|
else
|
|
{
|
|
findFactors(num);
|
|
}
|
|
|
|
|
|
return 0;
|
|
} |