题解 | 质数因子
#include <math.h> #include <stdio.h> #include <stdlib.h> int judge_prime(int n){//判断质数 int num ; for(num = 2;num * num < n;num++){ if(n % num == 0){ return 0; } } return 1; } void find_fac(int n){ int num = 2; while(num <= sqrt(n)){ if(n % num == 0 ){ printf("%d ",num); n = n / num; num = 2; }else{ num ++; } if(num > sqrt(n)){ printf("%d ",n); } } } int main() { int n; scanf("%d",&n); find_fac(n); //int a = judge_prime(8); //printf("%d",a); return 0; }