Advertisement
lighted

Factorization (short, space separated) O(sqrt(n))

Feb 26th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.  
  9.     cin >> n;
  10.  
  11.     for (int i = 2; i <= sqrt(n); i++)
  12.         while (n % i == 0)
  13.         {
  14.             cout << i << " ";
  15.  
  16.             n /= i;
  17.         }
  18.  
  19.     if (n > 1)
  20.         cout << n;
  21.  
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement