From fb1d52a1c4c3afe206055484f6b0f4f179005d25 Mon Sep 17 00:00:00 2001 From: mn32byusv <2602452814@qq.com> Date: Sun, 19 Feb 2023 15:10:34 +0800 Subject: [PATCH] Add C --- C | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 C diff --git a/C b/C new file mode 100644 index 0000000..6a4be40 --- /dev/null +++ b/C @@ -0,0 +1,72 @@ +#include +#include +#include +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置为1,x不是质数 + 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; + }