Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- const int mx=1e6+123;
- bitset<mx> is_prime;
- vector<ll>primes;
- set<ll>st;
- void prime_gen(ll n)
- {
- is_prime[2]=1;
- for(ll i=3;i<=n;i+=2) is_prime[i]=1;
- for(ll i=3;i*i<=n;i+=2)
- {
- if(is_prime[i]==1)
- {
- for(ll j=i*i;j<=n;j+=2*i)
- {
- is_prime[j]=0;
- }
- }
- }
- primes.push_back(2);
- for(int i=3;i<=n;i+=2)
- {
- if(is_prime[i]==1) primes.push_back(i);
- }
- }
- vector<ll> find_prime_fact(ll n)
- {
- vector<ll>v;
- for(auto prime:primes)
- {
- if(1ll * prime*prime>n) break;
- if(n%prime==0)
- {
- v.push_back(prime);
- while(n%prime==0)
- {
- n/=prime;
- }
- }
- }
- if(n>1) v.push_back(n);
- return v;
- }
- int main()
- {
- prime_gen(1e6);
- ll t;
- cin>>t;
- for(ll i=1;i<=t;i++)
- {
- ll n;
- cin>>n;
- set<ll>st;
- while(n--)
- {
- vector<ll>v;
- ll a;
- cin>>a;
- v=find_prime_fact(a);
- for(auto u:v) st.insert(u);
- }
- cout<<"Case #"<<i<<": "<< st.size()<<endl;
- for(auto u:st ) cout<<u<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement