Advertisement
Saleh127

spoj prime time

Aug 14th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define maX 100008
  4. #define ll long long
  5. vector<ll>p;
  6. bool marked[maX];
  7. void sieve()
  8. {
  9. marked[0]=1;
  10. marked[1]=1;
  11. for(ll i=4;i<=maX;i+=2)
  12. {
  13. marked[i]=1;
  14. }
  15. p.push_back(2);
  16. for(ll i=3;i<=maX;i+=2)
  17. {
  18. if(marked[i]==0)
  19. {
  20. p.push_back(i);
  21. for(ll j=i*i; j<=maX; j+=i+i)
  22. {
  23. marked[j]=1;
  24. }
  25. }
  26. }
  27. }
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);cout.tie(0);
  32. sieve();
  33.  
  34. ll a,c,d=0,e,i,j=0,k;
  35. cin>>a;
  36. for(i=0;p[i]<=a;i++)
  37. {
  38. c=a;
  39. d=0;
  40. while(c/p[i])
  41. {
  42. d+=(c/p[i]);
  43. c/=p[i];
  44. }
  45. if(j==0)
  46. {
  47. cout<<p[i]<<"^"<<d;
  48. }
  49. else
  50. {
  51. cout<<" * "<<p[i]<<"^"<<d;
  52. }
  53. j++;
  54.  
  55. }
  56. cout<<endl;
  57.  
  58. return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement