题解:CF2173C Kanade's Perfect Multiples
thousands_of_years · · 题解
solution
解法很简单,因为最小的数肯定在
复杂度如何呢?我们从每个点被跳的次数来考虑,肯定只有从自己的因子处跳过来,于是
code
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace fast_IO {
#define IOSIZE 100000
char ibuf[IOSIZE], obuf[IOSIZE], *p111 = ibuf, *p222 = ibuf, *p333 = obuf;
#define getchar() ((p111==p222)and(p222=(p111=ibuf)+fread(ibuf,1,IOSIZE,stdin),p111==p222)?(EOF):(*p111++))
#define putchar(x) ((p333==obuf+IOSIZE)&&(fwrite(obuf,p333-obuf,1,stdout),p333=obuf),*p333++=x)
#define isdigit(ch) (ch>47&&ch<58)
#define isspace(ch) (ch<33)
template<typename T> inline T readdd() { T s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s * w; }
template<typename T> inline bool readdd(T &s) { s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s *= w, true; }
template<typename T> inline void printtt(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) printtt(x / 10); putchar(x % 10 + 48); }
inline bool readdd(char &s) { while (s = getchar(), isspace(s)); return true; }
inline bool readdd(char *s) { char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) *s++ = ch, ch = getchar(); *s = '\000'; return true; }
inline void printtt(char x) { putchar(x); }
inline void printtt(char *x) { while (*x) putchar(*x++); }
inline void printtt(const char *x) { for (int i = 0; x[i]; i++) putchar(x[i]); }
inline bool readdd(std::string& s) { s = ""; char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) s += ch, ch = getchar(); return true; }
inline void printtt(std::string x) { for (int i = 0, n = x.size(); i < n; i++) putchar(x[i]); }
inline bool readdd(bool &b) { char ch; while(ch=getchar(), isspace(ch)); b=ch^48; return true; }
inline void printtt(bool b) { putchar(b+48); }
template<typename T, typename... T1> inline int readdd(T& a, T1&... other) { return readdd(a) + readdd(other...); }
template<typename T, typename... T1> inline void printtt(T a, T1... other) { printtt(a), printtt(other...); }
struct Fast_IO { ~Fast_IO() { fwrite(obuf, p333 - obuf, 1, stdout); } } iooo;
template<typename T> Fast_IO& operator >> (Fast_IO &iooo, T &b) { return readdd(b), iooo; }
template<typename T> Fast_IO& operator << (Fast_IO &iooo, T b) { return printtt(b), iooo; }
#define cout iooo
#define cin iooo
#define endl '\n'
} using namespace fast_IO;
const int N=2e6+9,inf=1e9+7;
int a[N],n,k;
map<int,int> vis;
map<int,int> mm;
void solve()
{
mm.clear();
vis.clear();
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
mm[a[i]]++;
}
vector<int> V;
for(int j=1;j<=n;j++)
{
int v=a[j];
if(vis[v]) continue;
if(v<k/(n+1))
{
cout<<-1<<endl;
return ;
}
for(int i=2;;i++)
{
if(i*v>k) break;
if(mm.find(v*i)==mm.end())
{
// cout<<v*i<<"!";
cout<<-1<<endl;
return ;
}
vis[v*i]=1;
}
vis[v]=1;
V.push_back(v);
}
cout<<V.size()<<endl;
for(int v:V)
cout<<v<<" ";
cout<<endl;
}
signed main()
{
int T;
cin>>T;
while(T--)
{
solve();
}
}