Saleh127

LO 1035 self

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