Advertisement
Saleh127

lo 1035 RE

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