Given a sequence of NN positive integers A=(A_1,A_2,\dots,A_N)A=(A1,A2,…,AN), find every integer kk between 11 and MM (inclusive) that satisfies the following condition:
- \gcd(A_i,k)=1gcd(Ai,k)=1 for every integer ii such that 1 \le i \le N1≤i≤N.
Constraints
- All values in input are integers.
- 1 \le N,M \le 10^51≤N,M≤105
- 1 \le A_i \le 10^51≤Ai≤105
Input
Input is given from Standard Input in the following format:
NN MM A_1A1 A_2A2 \dots… A_NAN
Output
In the first line, print xx: the number of integers satisfying the requirement.
In the following xx lines, print the integers satisfying the requirement, in ascending order, each in its own line.
Sample 1
Inputcopy | Outputcopy |
---|---|
3 12 6 1 5 | 3 1 7 11 |
For example, 77 has the properties \gcd(6,7)=1,\gcd(1,7)=1,\gcd(5,7)=1gcd(6,7)=1,gcd(1,7)=1,gcd(5,7)=1, so it is included in the set of integers satisfying the requirement.
On the other hand, 99 has the property \gcd(6,9)=3gcd(6,9)=3, so it is not included in that set.
We have three integers between 11 and 1212 that satisfy the condition: 11, 77, and 1111. Be sure to print them in ascending order.
思路:取质因数,筛掉倍数,剩下的就是答案
/*Where there is light, in my heart.*/
/*SUMMER_TRAINING DAY 15*/
#include<bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
//
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 0x3f3f3f
#define ll long long
//#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define unmap(a,b) unordered_map<a,b>
#define unset(a) unordered_set<a>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define _rep(i, a, b) for (int i = (a); i >= (b); --i)
#define mode 1e4+7
#define pi acos(-1)
typedef double db;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> vi;
const int N=2e5+5;
//
int mark[N];
int a[N];
int n,m;
//
signed main(){
mem(mark,0);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
set<int> s;
for(int i=1;i<=n;i++){
for(int j=1;j*j<=a[i];j++){//记录因子;
if(a[i]%j==0){
if(j>1) s.insert(j);
if(a[i]/j>1) s.insert(a[i]/j);
}
}
}
for(auto i:s){
for(int j=i;j<=m;j+=i){//累加倍数;
mark[j]=1;
}
}
vector<int> ans;
for(int i=1;i<=m;i++){
if(!mark[i]) ans.pb(i);
}
cout<<ans.size()<<endl;
for(auto i:ans){
cout<<i<<endl;
}
}
//made by shun 20220718