a010.
因數分解
| From: [111.82.227.32] |
發表日期
:
2023-08-04 16:49
#include <stdio.h>
#include <stdlib.h>
int main(){
long long int a;
while(scanf("%lld",&a)!=EOF){
if(a<1 || a>100000000){
continue;
}
long long int b=2;
long long int *arr = (long long int *)malloc((a + 1) * sizeof(long long int));
if (arr == NULL) {
continue;
}
for(long long int i=0;i<=a;i++){
arr[i]=0;
}
while(a>1){
if(a%b==0){
arr[b]++;
a/=b;
}else{
b++;
}
}
int flag=1;
for(long long int i=2;i<=b;i++){
if(arr[i]>0){
if(flag==0){
printf(" * ");
}
if(arr[i]>1){
printf("%lld^%lld",i,arr[i]);
flag=0;
}else if(arr[i]==1){
printf("%d",i);
flag=0;}
}
}
free(arr);
printf("\n"); }
}能否幫我看看哪裡有問題嗎?