C++
這是我的
---
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a;
while (scanf("%d",&a)){
for (int i=2;i<=sqrt(a);i++){
if (a%i==0){
printf("%d",i);
int a2=0;
while (a%i==0){
a2++;
a/=i;}
if (a==1){
printf("^%d\n",a2);}
else if (a2>1){
printf("^%d * ",a2);}
else if (a2==1 & a>1){
printf(" * ");}
}
}
if (a>1)
printf("%d\n",a);
}
}
------
這是參考的
-------
#include <iostream>
#include <cmath>
using namespace std ;
int main() {
int in0 ;
while (cin >>in0 ){
for (int i=2 ;i<=sqrt(in0);i++ ){
if (in0%i==0){
cout <<i ;
int i2 =0 ;
while (in0%i==0){
i2++ ;
in0/= i;
}
if (in0==1){
cout <<"^" <<i2 <<endl ;
}
else if (i2>1 ){
cout <<"^" <<i2 <<" * ";
}
else if (i2==1&in0>1){
cout <<" * " ;
}
}
}
if (in0>1)
cout <<in0 <<endl ;
}
}
-------
明明一樣的寫法== 我的TLE下面的卻AC
是差在哪裡????求解