Created
March 6, 2018 12:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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