forked from srikanthmalipatel/Spoj-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN12B-6823183-src.cpp
70 lines (58 loc) · 1.12 KB
/
MAIN12B-6823183-src.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<cstdio>
#include<map>
#include<bitset>
using namespace std;
#define max 1000000
bitset <max+1> p;
int size;
int prime[79000];
void sieve(){
size=0;
long long i,j;
p.set(0,1);
p.set(1,1);
prime[size++]=2;
for(i=3;i<max+1;i=i+2){
if(!p.test(i)){
prime[size++]=i;
for(j=i;j*i<max+1;j++){
p.set(j*i,1);
}
}
}
}
int main()
{
sieve();
int t;
scanf("%d",&t);
for(int w=0;w<t;w++){
int n;
scanf("%d",&n);
long long a[n];
for(int i=0;i<n;i++)
scanf("%lld",&a[i]);
map<long long,int> m;
map<long long,int> :: iterator it;
for(int i=0;i<n;i++){
long long num=a[i];
long long pp;
for(int j=0;(j<size) && ((pp=prime[j])*pp <= num) ;j++){
int c=0;
for(;!(num%pp);num /= pp)
c=1;
if(c)
m[pp]=1;
}
if((num>0)&&(num!=1)){
m[num]=1;
}
}
printf("Case #%d: %d\n",w+1,m.size());
for(it=m.begin();it!=m.end();it++){
printf("%lld\n",(*it).first);
}
}
return 0;
}