DP
转移方程请自行脑补(或者看代码)
#include <ctime>
#include <cstdio>
#include <algorithm>
#define fly(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline int read()
{
int x = 0, f = 1, t = getchar();
while(t < 48 || t > 57) t == 45 ? f = -1 : 0, t = getchar();
while(t > 47 && t < 58) x = (x << 1) + (x << 3) + t - 48, t = getchar();
return x * f;
}
const int maxn = 10005;
const int maxm = 1005;
int n, m, a[maxn], f[maxn];
pair<int, int> from[maxn];
void write(int i)
{
if(from[i].first) write(from[i].first);
printf("%d ", from[i].second);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
register int i, j, k;
n = read(), m = read();
for(i = 1; i <= n; ++i) a[i] = read();
for(i = 1; i <= n; ++i)
{
for(j = 1; j < m; ++j)
if(f[j] && !f[k = j * a[i] % m] && from[j].second != i)
f[k] = 1, from[k] = make_pair(j, i);
if(!f[a[i]]) f[a[i]] = 1, from[a[i]] = make_pair(0, i);
}
for(int i = m-1; i >= 0; --i)
{
if(i == 0) puts("1");
if(f[i])
{
printf("%d\n", i);
write(i);
break;
}
}
fly("%.3f\n", (double)clock() / CLOCKS_PER_SEC);
#ifndef ONLINE_JUDGE
fclose(stdin), fclose(stdout);
#endif
return 0;
}