fork(3) download
  1. #include <iostream>
  2. #include <vector>
  3. #include<cstring>
  4. #include <bitset>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8. int best[10000010];
  9. bitset <10000010> isComposite;
  10. void sieve ()
  11. {
  12. for (int i=2 ;i<=3163 ;i++)
  13. {
  14. if (i%2==0 && i!=2) continue;
  15. if (isComposite[i]) continue;
  16. for (int j=i*i ;j<=10000000;j+=i)
  17. {
  18. isComposite[j]=1;
  19. if (best[j]==0) best[j] = j/i;
  20. }
  21. }
  22. return ;
  23. }
  24. void solve (int num)
  25. {
  26. int ans = num;
  27. while (best[ans]!=0)
  28. {
  29. printf(" x %d",ans/best[ans]);
  30. ans = best[ans];
  31. }
  32. printf(" x %d",ans);
  33. return ;
  34. }
  35. int main ()
  36. {
  37. sieve();
  38. int n;
  39. while (cin >> n)
  40. {
  41. printf("1");
  42. if (!(isComposite[n])) printf(" x %d",n);
  43. else solve(n);
  44. cout << endl;
  45. }
  46. return 0;
  47. }
  48.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty