Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- vector<int>p;
- bool mark[105];
- void sieve()
- {
- int i,j;
- for(i=3; i<=102; i+=2)
- {
- if(mark[i]==0)
- {
- for(j=i*i; j<=102; j+=i);
- {
- mark[j]=1;
- }
- }
- }
- p.push_back(2);
- for(i=3; i<=102; i+=2)
- {
- if(mark[i]==0)
- {
- p.push_back(i);
- }
- }
- }
- int main()
- {
- fellow_junior
- sieve();
- int t,c,n;
- cin>>t;
- for(c=1; c<=t; c++)
- {
- cin>>n;
- cout<<"Case "<<c<<": "<<n<<" = ";
- int a[102]={0},i,j,k,l,q;
- for(i=2; i<=n; i++)
- {
- k=i;
- for(j=0; p[j]<=k; j++)
- {
- while(k%p[j]==0)
- {
- a[p[j]]++;
- k=k/p[j];
- }
- }
- }
- for(l=2,q=0; l<=100; l++)
- {
- if(a[l]>0)
- {
- if(q==0)
- {
- cout<<l<< " ("<<a[l]<<")";
- q++;
- }
- else
- {
- cout<<" * "<<l<< " ("<<a[l]<<")";
- }
- }
- }
- cout<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement