Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active February 28, 2025 07:43

Revisions

  1. thinkphp renamed this gist Feb 28, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. thinkphp created this gist Feb 26, 2025.
    24 changes: 24 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #include <iostream>
    using namespace std;

    int vec[1001], d, m, n, x;

    int main() {
    cout << "n ( <=1000 ) = ";
    cin >> n;

    for (int tt = 2; tt <= n; ++tt) {
    x = tt;
    for (d = 2; x > 1; d++) {
    for (m = 0; (x % d) == 0; m++, x /= d);
    vec[d] += m; // Accumulate the factor counts
    }
    }

    cout << n << "! prime factorization:\n";
    for (d = 2; d <= n; ++d) {
    if (vec[d]) cout << d << "^" << vec[d] << endl;
    }

    return 0;
    }