master
mn32byusv 3 years ago
parent c0e6d2c492
commit fb1d52a1c4

72
C

@ -0,0 +1,72 @@
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int isPrime(int x)
{
int flag1 = 0;
for(int i = 2; i < x; i++)
{
if(x % i == 0)//判断x是否有除了1和本身以外的因子
{
flag1 = 1;//若有将flag置为1x不是质数
break;
}
}
if(flag1 == 0)//x没有除了1和本身以外的因子
return 1;//x是质数
else
return 0;
}
int main()
{
int K;
while(scanf("%d",&K) != EOF)
{
for(int i = 0; i < K; i++)
{
int flag = 1;//标记是否是开头的数
int j;
int x;
scanf("%d",&x);
if(isPrime(x))
{
cout << x << endl;
}
else
{
int n = x;
for(j = 2; j < x; )
{
if(isPrime(j))
{
if(n % j == 0)//j是n的因子
{
n = n / j;//计算n除了j以外的因子
if(flag == 1) //这个j是第一个数
{
cout << j;
flag = 0;
}
else
{
cout << "*" << j ;
}
}
else
{
j++;
}
}
else
{
j++;
}
}
cout << endl;
}
}
}
return 0;
}
Loading…
Cancel
Save