QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67487#2866. 遗忘的集合alpha1022100 ✓691ms59580kbC++234.7kb2022-12-10 16:27:102022-12-10 16:27:17

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 16:27:17]
  • 评测
  • 测评结果:100
  • 用时:691ms
  • 内存:59580kb
  • [2022-12-10 16:27:10]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define add(a,b) (a + b >= mod ? a + b - mod : a + b)
#define dec(a,b) (a < b ? a - b + mod : a - b)
using namespace std;
const int N = 1 << 19;
const double pi = acos(-1);
const int W = 1 << 15;
int len,mod,n,ans;
int lg2[N + 5],rev[N + 5];
int fac[N + 5],ifac[N + 5],inv[N + 5];
inline int fpow(int a,int b)
{
	int ret = 1;
	for(;b;b >>= 1)
		(b & 1) && (ret = (long long)ret * a % mod),a = (long long)a * a % mod;
	return ret;
}
struct poly
{
	int a[N + 5];
	inline const int &operator[](int x) const
	{
		return a[x];
	}
	inline int &operator[](int x)
	{
		return a[x];
	}
	inline void clear(int x = 0)
	{
		memset(a + x,0,(N - x + 1) << 2);
	}
} f;
struct cp
{
    double a,b;
    inline void operator+=(const cp &o)
    {
        a += o.a,b += o.b;
    }
    inline cp operator+(const cp &o) const
    {
        return (cp){a + o.a,b + o.b};
    }
    inline cp operator-(const cp &o) const
    {
        return (cp){a - o.a,b - o.b};
    }
    inline cp operator*(const cp &o) const
    {
        return (cp){a * o.a - b * o.b,a * o.b + b * o.a};
    }
    inline void operator*=(const cp &o)
    {
        *this = *this * o;
    }
    inline cp operator*(const double &o) const
    {
        return (cp){a * o,b * o};
    }
    inline cp operator~() const
    {
        return (cp){a,-b};
    }
} rt[N + 5];
inline void init(int len)
{
    for(n = 1;n < len;n <<= 1);
    for(register int i = 2;i <= n;++i)
        lg2[i] = lg2[i >> 1] + 1;
    for(register int i = 0;i <= (n >> 1);++i)
        rt[(n >> 1) + i] = (cp){cos(2 * pi * i / n),sin(2 * pi * i / n)};
    for(register int i = (n >> 1) - 1;i;--i)
        rt[i] = rt[i << 1];
	fac[0] = 1;
	for(register int i = 1;i <= n;++i)
		fac[i] = (long long)fac[i - 1] * i % mod;
	ifac[n] = fpow(fac[n],mod - 2);
	for(register int i = n;i;--i)
		ifac[i - 1] = (long long)ifac[i] * i % mod;
	for(register int i = 1;i <= n;++i)
		inv[i] = (long long)ifac[i] * fac[i - 1] % mod;
}
inline void fft(cp *a,int type,int n)
{
    type == -1 && (reverse(a + 1,a + n),1);
    int lg = lg2[n] - 1;
    for(register int i = 0;i < n;++i)
        rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << lg),
        i < rev[i] && (swap(a[i],a[rev[i]]),1);
    for(register int w = 2,m = 1;w <= n;w <<= 1,m <<= 1)
        for(register int i = 0;i < n;i += w)
            for(register int j = 0;j < m;++j)
            {
                cp t = rt[m | j] * a[i | j | m];
                a[i | j | m] = a[i | j] - t,a[i | j] += t;
            }
    if(type == -1)
        for(register int i = 0;i < n;++i)
            a[i].a /= n,a[i].b /= n;
}
inline void mul(poly &a,const poly &b,int n)
{
	static cp f[N + 5],g[N + 5],h[N + 5];
	int lim = 1;
	memset(f,0,sizeof f),memset(g,0,sizeof g);
	for(;lim < (n << 1);lim <<= 1);
	for(register int i = 0;i < n;++i)
		f[i] = (cp){a[i] / W,a[i] % W},g[i] = (cp){b[i] / W,b[i] % W};
    fft(f,1,lim),fft(g,1,lim);
    for(register int i = 0;i < lim;++i)
    	h[i] = ~f[(lim - i) % lim];
    for(register int i = 0;i < lim;++i)
    	f[i] *= g[i],g[i] *= h[i];
    fft(f,-1,lim),fft(g,-1,lim);
    for(register int i = 0;i < lim;++i)
    {
    	long long ac = (f[i].a + g[i].a) / 2 + 0.5;
    	long long bd = g[i].a - ac + 0.5;
    	long long bcad = f[i].b + 0.5;
    	a[i] = ((ac % mod * W % mod * W % mod) % mod + (bcad % mod * W % mod) % mod + bd % mod) % mod;
	}
}
inline poly inverse(const poly &f,int n)
{
	static int s[30];
	static poly g,h,q;
	int top = 0;
	g.clear();
	for(;n > 1;s[++top] = n,n = (n + 1) >> 1);
	g[0] = fpow(f[0],mod - 2);
	for(;top;--top)
	{
		n = s[top];
		q = g,h = f,h.clear(n);
		mul(g,g,n),g.clear(n),mul(g,h,n);
		for(register int i = 0;i < n;++i)
			g[i] = dec(add(q[i],q[i]),g[i]);
		g.clear(n);
	}
	return g;
}
inline void deriv(poly &f,int n)
{
	for(register int i = 1;i < n;++i)
		f[i - 1] = (long long)f[i] * i % mod;
	f[n - 1] = 0;
}
inline void integ(poly &f,int n)
{
	for(register int i = n - 1;~i;--i)
		f[i + 1] = (long long)f[i] * inv[i + 1] % mod;
	f[0] = 0;
}
inline poly ln(const poly &f,int n)
{
	static poly g;
    g = f,deriv(g,n),mul(g,inverse(f,n),n),integ(g,n);
	return g;
}
int main()
{
	scanf("%d%d",&len,&mod),init((len + 1) << 1),f[0] = 1;
	for(register int i = 1;i <= len;++i)
		scanf("%d",f.a + i);
	f = ln(f,len + 1);
	for(register int i = 1;i <= len;++i)
		f[i] = (long long)f[i] * i % mod;
	for(register int i = 1;i <= len;++i)
	{
		ans += (bool)f[i];
		for(register int j = 2 * i;j <= len;j += i)
			f[j] = dec(f[j],f[i]);
	}
	printf("%d\n",ans);
	for(register int i = 1;i <= len;++i)
		f[i] && (printf("%d ",i),1);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 12ms
memory: 33412kb

input:

5 1000003
0 1 1 1 2

output:

3
2 3 5 

result:

ok 2 lines

Test #2:

score: 5
Accepted
time: 12ms
memory: 32956kb

input:

20 483409747
1 1 2 2 2 4 5 5 7 9 10 13 16 19 23 28 34 41 47 57

output:

12
1 3 6 7 10 11 14 15 16 17 18 20 

result:

ok 2 lines

Test #3:

score: 5
Accepted
time: 7ms
memory: 32856kb

input:

25 721428667
1 1 2 2 3 5 5 6 9 10 13 18 19 24 32 36 45 56 62 77 95 108 130 156 177

output:

15
1 3 5 6 9 11 12 14 15 16 17 20 21 22 24 

result:

ok 2 lines

Test #4:

score: 5
Accepted
time: 8ms
memory: 32904kb

input:

25 716854727
1 1 2 3 3 4 5 7 9 11 14 19 22 27 33 41 49 60 72 88 105 125 148 177 207

output:

15
1 3 4 8 9 10 11 12 14 16 17 18 19 21 23 

result:

ok 2 lines

Test #5:

score: 5
Accepted
time: 40ms
memory: 35108kb

input:

4996 1019536027
1 1 2 2 3 5 6 7 10 13 16 22 26 32 42 51 63 79 94 115 143 171 205 250 296 353 427 503 595 711 833 982 1161 1355 1586 1862 2163 2519 2938 3399 3938 4569 5262 6071 7007 8041 9238 10613 12137 13892 15893 18118 20657 23549 26758 30412 34547 39138 44343 50215 56729 64090 72354 81529 91852 ...

output:

26
1 3 5 6 7 9 10 11 12 14 15 16 17 18 20 21 22 24 27 29 30 32 33 35 38 40 

result:

ok 2 lines

Test #6:

score: 5
Accepted
time: 49ms
memory: 35544kb

input:

4983 1073741101
1 2 2 4 5 7 9 13 17 23 28 38 47 61 75 96 118 148 179 224 270 333 399 488 585 707 842 1012 1201 1435 1693 2013 2369 2801 3283 3865 4517 5294 6164 7200 8360 9728 11260 13060 15082 17435 20078 23146 26593 30573 35035 40178 45943 52557 59965 68439 77932 88749 100851 114615 130001 147448 ...

output:

30
1 2 4 5 7 8 9 10 12 13 15 16 18 20 21 22 23 24 25 26 27 29 32 33 34 35 36 37 38 40 

result:

ok 2 lines

Test #7:

score: 5
Accepted
time: 45ms
memory: 33796kb

input:

7992 1000003
1 2 3 5 7 11 15 22 30 41 55 75 97 128 166 215 273 350 439 555 692 862 1066 1320 1616 1982 2416 2939 3556 4303 5175 6224 7451 8906 10610 12631 14972 17738 20953 24713 29073 34170 40047 46894 54787 63924 74445 86608 100541 116611 135017 156142 180292 207975 239517 275594 316656 363456 416...

output:

5479
1 2 3 4 5 6 7 8 9 11 12 15 16 18 20 21 23 24 25 26 27 28 30 31 32 33 36 37 38 39 42 45 47 49 50 51 52 55 56 57 58 60 61 62 63 65 66 67 70 72 73 75 76 77 78 81 83 85 87 88 92 94 95 101 103 104 107 108 110 111 112 113 116 117 118 119 120 121 123 125 126 127 130 131 133 134 136 140 141 142 144 146...

result:

ok 2 lines

Test #8:

score: 5
Accepted
time: 43ms
memory: 34980kb

input:

7971 1000000007
0 1 0 2 0 3 1 5 2 6 4 10 6 14 11 20 16 28 25 40 37 55 54 77 76 105 107 144 149 194 205 261 279 347 376 464 503 611 667 805 878 1051 1153 1368 1503 1768 1947 2281 2513 2924 3228 3738 4124 4755 5253 6029 6665 7614 8418 9590 10598 12031 13299 15054 16630 18773 20734 23346 25777 28947 31...

output:

5111
2 4 6 7 8 9 11 12 14 15 17 19 20 21 22 24 25 29 31 34 36 37 38 40 43 46 48 49 50 51 52 54 55 56 57 60 61 62 63 64 65 66 68 71 74 76 77 78 79 80 81 82 84 87 88 89 90 92 93 94 95 96 97 98 99 101 103 106 108 109 113 114 116 118 119 122 124 126 127 130 131 132 133 134 135 136 137 138 140 142 144 14...

result:

ok 2 lines

Test #9:

score: 5
Accepted
time: 50ms
memory: 34468kb

input:

7997 764144351
0 0 0 1 1 1 1 2 2 3 3 5 5 6 8 11 12 15 17 23 26 32 37 46 54 65 76 92 106 128 147 177 205 242 280 331 381 447 516 605 693 808 927 1078 1237 1427 1634 1886 2155 2478 2827 3244 3691 4225 4807 5487 6230 7092 8043 9150 10353 11746 13277 15040 16978 19194 21638 24424 27496 30988 34837 39213...

output:

7084
4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 25 26 27 28 29 30 32 33 34 35 36 39 40 42 44 45 47 49 50 51 52 54 55 56 57 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 101 102 103 104 105 106 107 108 110 112 114 116 ...

result:

ok 2 lines

Test #10:

score: 5
Accepted
time: 47ms
memory: 34148kb

input:

7957 1073741371
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 173525 204226 239943 281589 329931 386155 451276 526823 614154 ...

output:

7868
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

result:

ok 2 lines

Test #11:

score: 5
Accepted
time: 682ms
memory: 59540kb

input:

261261 590614027
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 173525 204226 239943 281589 329931 386155 451276 526823 614154...

output:

260761
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result:

ok 2 lines

Test #12:

score: 5
Accepted
time: 675ms
memory: 59448kb

input:

261726 1073741237
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 173525 204226 239943 281589 329931 386155 451276 526823 61415...

output:

261218
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result:

ok 2 lines

Test #13:

score: 5
Accepted
time: 656ms
memory: 59580kb

input:

262026 605301607
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 173525 204226 239943 281589 329931 386155 451276 526823 614154...

output:

212390
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result:

ok 2 lines

Test #14:

score: 5
Accepted
time: 654ms
memory: 59560kb

input:

262104 1073741671
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 173525 204226 239943 281589 329931 386155 451276 526823 61415...

output:

233583
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result:

ok 2 lines

Test #15:

score: 5
Accepted
time: 678ms
memory: 59492kb

input:

261943 998244353
1 2 3 5 7 10 14 20 27 36 47 63 81 104 132 168 211 263 326 404 497 608 740 900 1089 1313 1577 1891 2259 2692 3197 3791 4483 5290 6226 7315 8576 10035 11719 13663 15900 18474 21426 24815 28693 33131 38198 43982 50571 58072 66600 76289 87280 99741 113847 129811 147847 168217 191192 217...

output:

168868
1 2 3 4 5 7 8 9 12 13 17 19 20 21 22 23 25 26 27 28 30 31 32 33 34 35 37 39 41 44 45 46 47 48 49 53 54 55 56 58 59 65 70 72 73 74 75 76 77 78 79 80 81 82 85 86 91 92 94 95 96 97 99 100 104 106 107 109 111 113 114 115 116 117 118 119 120 122 124 126 129 130 132 133 135 136 137 138 140 141 142 ...

result:

ok 2 lines

Test #16:

score: 5
Accepted
time: 671ms
memory: 59556kb

input:

262093 991668907
1 2 2 4 5 8 10 15 19 27 34 47 59 79 98 129 160 206 253 322 395 496 604 751 911 1121 1353 1653 1986 2409 2881 3474 4139 4962 5888 7022 8304 9857 11614 13727 16123 18981 22222 26066 30429 35569 41403 48245 56008 65066 75339 87280 100815 116484 134232 154706 177879 204523 234652 269194...

output:

184995
1 2 4 5 6 7 8 9 10 11 12 13 14 16 17 20 21 22 23 24 25 27 28 30 31 32 33 34 35 37 38 41 43 45 47 48 52 53 54 55 56 59 60 63 64 65 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 92 93 95 96 97 99 100 101 102 105 107 110 111 112 113 115 118 119 120 121 122 123 124 125 126 127...

result:

ok 2 lines

Test #17:

score: 5
Accepted
time: 691ms
memory: 59564kb

input:

262104 1000000007
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12309 14882 17975 21634 26010 31178 37327 44568 53152 63231 75133 89078 105481 124653 147138 173349 203995 239646 281204 329441 385528 450484 525821 61289...

output:

254490
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 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok 2 lines

Test #18:

score: 5
Accepted
time: 654ms
memory: 59540kb

input:

262137 579028423
1 1 2 2 3 4 5 7 8 10 12 15 19 23 29 34 41 49 58 70 83 99 115 135 158 183 216 251 292 339 390 450 517 596 685 786 899 1024 1168 1328 1511 1720 1952 2212 2501 2825 3188 3597 4055 4565 5134 5763 6461 7242 8112 9080 10156 11346 12660 14116 15727 17511 19490 21674 24081 26734 29652 32870...

output:

142386
1 3 5 7 8 12 13 14 15 17 19 21 22 27 28 29 30 31 35 36 37 42 43 44 46 47 48 50 51 52 54 55 58 60 61 65 68 72 73 74 75 76 77 78 79 80 82 83 84 88 89 91 93 95 97 98 100 103 104 105 107 108 111 114 115 117 118 119 120 121 124 125 129 132 134 140 142 144 145 146 148 149 150 151 152 154 155 157 15...

result:

ok 2 lines

Test #19:

score: 5
Accepted
time: 681ms
memory: 59512kb

input:

262143 1073741719
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1574 1957 2434 3007 3713 4558 5593 6827 8327 10113 12268 14827 17900 21536 25880 31009 37107 44286 52789 62771 74548 88342 104556 123499 145698 171567 201790 236933 277871 325366 380551 444434 518474 60401...

output:

257633
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97 98 99 100 101 102...

result:

ok 2 lines

Test #20:

score: 5
Accepted
time: 657ms
memory: 59496kb

input:

262143 1073741723
1 2 3 5 7 11 15 22 30 42 56 77 101 135 176 231 297 385 490 627 792 1002 1255 1575 1958 2436 3010 3718 4565 5604 6842 8349 10143 12310 14883 17977 21637 26015 31185 37338 44583 53174 63261 75175 89134 105558 124754 147273 173525 204226 239943 281589 329931 386155 451276 526823 61415...

output:

261577
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 101 ...

result:

ok 2 lines