Advertisement
Farjana_akter

Untitled

Mar 23rd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define x 10000000
  4.  
  5. bool mark[x+5]= {false};
  6. long long int isprime[x],i,k,j;
  7. void sieve()
  8. {
  9. mark[0]=true;
  10. mark[1]=true;
  11. for(i=2; i*i<=x; i++)
  12. {
  13. if(mark[i]==false)
  14. {
  15. for(j=i*i; j<=x; j+=i)
  16. mark[j]=true;
  17. }
  18. }
  19. k=0;
  20. for(i=2; i<=x; i++)
  21. {
  22. if(mark[i]==false)
  23. isprime[k++]=i;
  24. }
  25. }
  26. int main()
  27. {
  28. sieve();
  29. long long int n;
  30. while(cin>>n && n)
  31. {
  32. bool flag=true;
  33. cout<<n<<" = ";
  34. if(n<0)
  35. cout<<"-1";
  36. if(n<0)
  37. {
  38. n*=-1;
  39. flag=false;
  40. }
  41. for(i=0; isprime[i]*isprime[i]<=n; i++)
  42. {
  43. if(n%isprime[i]==0)
  44. {
  45.  
  46. while(n%isprime[i]==0)
  47. {
  48. if(flag)
  49. {
  50. cout<<isprime[i];
  51. flag=false;
  52. }
  53. else
  54.  
  55. cout<<" x "<<isprime[i];
  56. n/=isprime[i];
  57.  
  58. }
  59. }
  60. }
  61. if(n>1)
  62. {
  63. if(flag)
  64. cout<<n;
  65. else
  66. cout<<" x "<<n;
  67. }
  68. cout<<endl;
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement