fork download
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <iostream>
  7. #include <string>
  8. #include <vector>
  9. using namespace std;
  10. bool pr[50001];
  11.  
  12. void sieve(int n)
  13. {
  14. memset(pr,0,sizeof(pr));
  15. long i,j,k,l;
  16. pr[1]=1;
  17. for(i=4;i<=n;i+=2)
  18. pr[i]=1;
  19. for(i=3;i*i<=n;i+=2)
  20. {
  21. if(pr[i]==0)
  22. {
  23. for(j=i*i;j<=n;j+=2*i)
  24. pr[j]=1;
  25. }
  26. }
  27. }
  28.  
  29. main()
  30. {
  31. vector<long long>v;
  32. sieve(50000);
  33. long long n,m;
  34. long long k;
  35. long long i;
  36. int j,t;
  37. while(scanf("%lld",&m))
  38. {
  39. if(m==0)
  40. return 0;
  41. if(m<0)
  42. {
  43. n=m*-1;
  44. }
  45. else
  46. n=m;
  47. k=n;
  48. for(i=2;i*i<=n;i++)
  49. {
  50. while(pr[i])
  51. {
  52. i++;
  53. }
  54. while(k%i==0)
  55. {
  56. k/=i;
  57. v.push_back(i);
  58. }
  59. if(k==1)
  60. break;
  61. }
  62. printf("%lld = ",m);
  63. t=0;
  64. if(m<0)
  65. {
  66. printf("-1");
  67. t=1;
  68. }
  69. for(i=0;i<v.size();i++)
  70. {
  71. if(t!=0)
  72. printf(" x ");
  73. printf("%lld",v[i]);
  74. t=1;
  75. }
  76. if(k!=1)
  77. {
  78. if(t!=0)
  79. printf(" x ");
  80. printf("%lld",k);
  81. }
  82. printf("\n");
  83. v.clear();
  84. }
  85. return 0;
  86. }
  87.  
Runtime error #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
Standard output is empty