fork(2) download
  1. #include<bits/stdc++.h>
  2. #define ll long long int
  3. #define mp make_pair
  4. #define pb push_back
  5. #define si(x) scanf("%d",&x)
  6. #define pi(x) printf("%d\n",x)
  7. #define s(x) scanf("%lld",&x)
  8. #define p(x) printf("%lld\n",x)
  9. #define sc(x) scanf("%s",x)
  10. #define pc(x) printf("%s",x)
  11. #define pii pair<int,int>
  12. #define pll pair<ll,ll>
  13. #define F first
  14. #define S second
  15. #define N 10000002
  16. #define M 1000000007
  17.  
  18. using namespace std;
  19.  
  20. bool a[N];
  21. int lpf[N]={0};
  22. void sieve(){
  23. int i,j;
  24. for(i=0;i<N;i++) a[i]=true;
  25. a[0]=false;a[1]=false;
  26. for(i=2;i*i<N;i++){
  27. if(a[i]){
  28. for(j=i*i;j<N;j+=i){
  29. a[j]=false;
  30. }
  31. }
  32. }
  33.  
  34. for(int i=1;i<=N;i++){
  35. if(a[i]) lpf[i]=i;
  36. }
  37.  
  38. lpf[1]=1;
  39. for(i=2;i*i<N;i++){
  40. if(a[i]==true){
  41. for(j=i*i;j<N;j+=i){
  42. if(!lpf[j]) lpf[j]=i;
  43. }
  44. }
  45. }
  46. }
  47.  
  48. int main(){
  49. sieve();
  50. int n;
  51. while(si(n)!=EOF){
  52. vector<int>pf;
  53. pf.pb(1);
  54. while(n>1){
  55. int x=lpf[n];
  56. while(n%x==0){
  57. n/=x;
  58. pf.pb(x);
  59. }
  60. }
  61. for(int i=0;i<pf.size();i++) {
  62. if(i!=pf.size()-1) printf("%d x ",pf[i]);
  63. else pi(pf[i]);
  64. }
  65. }
  66. return 0;
  67. }
  68.  
Success #stdin #stdout 0.17s 51704KB
stdin
1
2
4
8
stdout
1
1 x 2
1 x 2 x 2
1 x 2 x 2 x 2