这种情况咋办?(求助+壶关)
查看原帖
这种情况咋办?(求助+壶关)
995569
L__B楼主2024/7/1 16:22

代码:

#include<bits/stdc++.h>
using namespace std;
bool f(int x){
    for(int y=2;y*y<=x;y++)
      if(x%y==0) return 0;
    return 1;
}
long n,a[1000000],s;
int main(){
    scanf("%d",&n);
    if(f(n)){printf("%d",n); return 0;}
    for(int i=2;i*i<=n;i++){
        if(f(i)&&n%i==0){
            s=0;
            while(n%i==0) n/=i,s++;
            printf("%d",i);
            if(s>1) printf("^%d",s);
            if(n>1) printf(" * ");
        }
    }
    return 0;
}

输入 #1:

6

样例输出:

2 * 3

我的输出:

2 * 

这是啥问题?

2024/7/1 16:22
加载中...