文題如標題
圖片檔方便閱讀(若圖沒跑出來下面放了網址)
https://imgur.com/XwPqYp2
文字檔方便複製
#include <stdio.h>
#include <stdlib.h>
int main(){
int num;
while(scanf("%d", &num) != EOF){
int pr[19] = {};
int sqre[19] = {};
int divide = 2;
int stack = 0;
while(num != 1){
if(num % divide == 0){
pr[stack] = divide;
sqre[stack]++;
num /= divide;
}
else if(num % divide != 0){
divide++;
stack++;
if(pr[stack-1] == 0 || sqre[stack-1] == 0)stack--;
}
}
int i = 0;
while(i <= stack){
if(pr[i] != 0 & sqre[i] != 1){
printf("%d^%d ", pr[i], sqre[i]);
if(stack != i)printf("* ");
}
else{
printf("%d ", pr[i], sqre[i]);
if(stack != i)printf("* ");
}
i++;
}
}
}
對了 語言用的是C
然後解答上有多餘的字:
您的答案為: 2^2 * 3^2 * 7 * 17 3^2 ...略 正確答案為: 2^2 * 3^2 * 7 * 17