Last active
October 16, 2023 09:07
-
-
Save FantasticJZI/234a9503a62afd7768af26a3a745a1a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int factor(int input) //取質因數 | |
{ | |
for(int i=2;i<input;i++) | |
{ | |
if(input%i==0) | |
return i; | |
} | |
return input; | |
} | |
void main() | |
{ | |
int input; | |
scanf("%d",&input); | |
int arr[10000],count=0; | |
while(factor(input)!=1) | |
{ | |
arr[count++]=factor(input); | |
input=input/factor(input); | |
} | |
/*for(int i=0;i<count;i++) //test | |
{ | |
printf("%d ",arr[i]); | |
}*/ | |
int pow=1; | |
if(count>1) | |
{ | |
for(int i=1;i<count;i++) | |
{ | |
if(arr[i]==arr[i-1])//計算次方 | |
pow++; | |
if(arr[i]!=arr[i-1] && pow!=1) //印段落 | |
{ | |
printf("%d^%d",arr[i-1],pow); | |
if(i==count-1) | |
printf(" * %d",arr[i]); | |
else | |
{ | |
printf(" * "); | |
pow=1; | |
} | |
} | |
else if(arr[i]!=arr[i-1] && pow==1) //印段落 | |
{ | |
printf("%d",arr[i-1]); | |
if(i==count-1) | |
printf(" * %d",arr[i]); | |
else | |
printf(" * "); | |
} | |
if(i==count-1 && pow!=1) //特殊情況 | |
printf("%d^%d",arr[i-1],pow); | |
} | |
} | |
else | |
printf("%d",arr[0]); | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment