Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 6, 2018 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maehrm/f2c53aecec24a85cd29e331be4037bbb to your computer and use it in GitHub Desktop.
Save maehrm/f2c53aecec24a85cd29e331be4037bbb to your computer and use it in GitHub Desktop.
素因数分解 | アルゴリズムとデータ構造 | Aizu Online Judge http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_A&lang=jp
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;
cin >> n;
cout << n << ":";
for (int i = 2; i <= sqrt(n); i++) {
while (n % i == 0) {
cout << " " << i;
n /= i;
}
}
if (n != 1) {
cout << " " << n;
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment