不知道还有没有更优的算法……虽然我的能过……
求教QAQ。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <ctime>
#define X CLOCKS_PER_SEC
using namespace std;
typedef long long LL;
bool Judge(LL x)
{
if(x <= 1)
return false;
if(x <= 3)
return true;
for(LL i = 2; i <= sqrt(x); i ++)
if(x%i == 0)
return false;
return true;
}
int main()
{
LL n;
cin >> n;
printf("%lld=", n);
if(Judge(n))
{
printf("%lld\n",n);
return 0;
}
bool first = 1;
LL i = 2;
while(n && n != 1)
{
if(!Judge(i))
{
i ++;
continue;
}
LL cnt = 0;
while(n%i == 0)
{
cnt ++;
n/= i;
}
while(cnt --)
{
if(!first)
printf("*%lld", i);
else {
printf("%lld", i);
first = 0;
}
}
i ++;
}
return 0;
}
// 1000000007