Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: purihorharin

Problemset: แยกตัวประกอบ

Language: cpp

Time: 0.124 second

Submitted On: 2026-03-20 11:41:20

#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main () {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int last_p = 2;
    int count = 0;
    while (n != 1) {
        int i = last_p;
        for (; n % i != 0; i++);
        n /= i;
        if (i == last_p) {
            count++;
        } else {
            if (count != 0) {
                cout << last_p << '^' << count << ' ';
            }
            last_p = i, count = 1;
        }
    }
    if (count != 0) {
        cout << last_p << '^' << count << ' ';
    }
}