稻花香里说丰年,听取WA声一片。
查看原帖
稻花香里说丰年,听取WA声一片。
1251905
cao_20115楼主2024/5/1 15:46

Code

#include <cstdio>
int cnt, ct;
bool p(int x) {
    if (x == 1) return 0;
    for (int i = 2; i * i <= x; ++i) {
        if (x % i == 0) return 0;
    }
    return 1;
}

void solve(long long n) {
    if (p(n)) printf("%d", n);
    else {
        for (long long i = 2; i < n; ++i) {
            cnt = 0;
            if (n % i == 0) {
                ct++;
                while (n % i == 0) {
                    cnt++;
                    n /= i;
                }
                if (ct != 1) printf(" * ");
                if (cnt == 1) printf("%lld", i);
                else printf("%lld^%lld", i, cnt);
                if (p(n)) printf(" * %lld", n);
            }
        }
    }
}
long long n;
int main(){
    scanf("%lld", &n);
    solve(n);
    return 0;
}
2024/5/1 15:46
加载中...