Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active February 28, 2025 07:43
Show Gist options
  • Save thinkphp/299f13ccd73bc2b824a795629fbac454 to your computer and use it in GitHub Desktop.
Save thinkphp/299f13ccd73bc2b824a795629fbac454 to your computer and use it in GitHub Desktop.
BreakingDownn!factorizationPrime1.txt
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment