QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#814570 | #9799. Magical Palette | YipChip# | Compile Error | / | / | C++23 | 6.4kb | 2024-12-14 18:28:57 | 2024-12-14 18:29:04 |
Judging History
This is the latest submission verdict.
- [2024-12-14 18:29:04]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-12-14 18:28:57]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int primes[N], st[N], phi[N], cnt;
int vis[N], mod;
void init()
{
phi[1] = 1;
for (int i = 2; i < N; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i, phi[i] = i - 1;
for (int j = 0; i * primes[j] < N; j ++ )
{
st[i * primes[j]] = 1;
if (i % primes[j] == 0)
{
phi[primes[j] * i] = phi[i] * primes[j];
break;
}
phi[primes[j] * i] = phi[i] * (primes[j] - 1);
}
}
}
int get(int n, int m)
{
ll res = 1, cnt = 0;
for (int i = 2; i <= mod; i ++ )
{
if (i == n || i == m) continue;
res = res * i % mod, cnt ++ ;
while (res != 1 && cnt <= m) res = res * i % mod, cnt ++ ;
if (cnt == m) return i;
else res = cnt = 1;
}
return 0;
}
void solve()
{
int n, m;
cin >> n >> m, mod = n * m;
if (n == 1)
{
cout << "Yes\n1\n";
for (int i = 1; i <= m; i ++ ) cout << i << " \n"[i == m];
return;
}
if (m == 1)
{
for (int i = 1; i <= n; i ++ ) cout << i << " \n"[i == n];
cout << "Yes\n1\n";
return;
}
if (n > 3 && m > 3) return cout << "No\n", void();
// if (phi[mod] % (n - 1) || phi[mod] % (m - 1)) return cout << "No\n", void();
int pd = 0;
if (n > m) swap(n, m), pd = 1;
int mul = get(n, m);
for (int i = 0; i < n * m; i ++ ) vis[i] = 0;
vector<int> ans1, ans2;
ll res = 1;
res = res * mul % (n * m);
ans2.push_back(1);
while (res != 1) ans2.push_back(res), res = res * mul % mod;
for (int i = 1; i < mod; i ++ )
{
if (!vis[i] && i % n && i % m)
{
ans1.push_back(i);
for (auto t : ans2) vis[t * i % mod] = 1;
}
}
if (pd) swap(ans1, ans2), swap(n, m);
for (int i = n; i < mod; i += n)
{
pd = 0;
for (int j = 0; j < mod; j += n) vis[j] = 0;
for (auto t : ans2)
if (vis[1ll * t * i % mod]) pd = 1;
else vis[1ll * t * i % mod] = 1;
if (!pd)
{
ans1.push_back(i);
break;
}
}
for (int i = m; i < mod; i += m)
{
pd = 0;
for (int j = 0; j < mod; j += m) vis[j] = 0;
for (auto t : ans1)
if (vis[1ll * t * i % mod]) pd = 1;
else vis[1ll * t * i % mod] = 1;
if (!pd)
{
ans2.push_back(i);
break;
}
}
if (ans1.size() != n || ans2.size() != m) return cout << "No\n", void();
cout << "Yes\n";
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < m; j ++ )
cout << ans1[i] * ans2[j] % mod << ' ';
cout << "\n";
}
for (int i = 0; i < n; i ++ ) cout << ans1[i] << " \n"[i == n - 1];
for (int i = 0; i < m; i ++ ) cout << ans2[i] << " \n"[i == m - 1];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int T = 1;
cin >> T;
while (T -- ) solve();
return 0;
}#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int primes[N], st[N], phi[N], cnt;
int vis[N], mod;
void init()
{
phi[1] = 1;
for (int i = 2; i < N; i ++ )
{
if (!st[i]) primes[cnt ++ ] = i, phi[i] = i - 1;
for (int j = 0; i * primes[j] < N; j ++ )
{
st[i * primes[j]] = 1;
if (i % primes[j] == 0)
{
phi[primes[j] * i] = phi[i] * primes[j];
break;
}
phi[primes[j] * i] = phi[i] * (primes[j] - 1);
}
}
}
int get(int n, int m)
{
ll res = 1, cnt = 0;
for (int i = 2; i <= mod; i ++ )
{
if (i == n || i == m) continue;
res = res * i % mod, cnt ++ ;
while (res != 1 && cnt <= m) res = res * i % mod, cnt ++ ;
if (cnt == m) return i;
else res = cnt = 1;
}
return 0;
}
void solve()
{
int n, m;
cin >> n >> m, mod = n * m;
if (n == 1)
{
cout << "Yes\n1\n";
for (int i = 1; i <= m; i ++ ) cout << i << " \n"[i == m];
return;
}
if (m == 1)
{
for (int i = 1; i <= n; i ++ ) cout << i << " \n"[i == n];
cout << "Yes\n1\n";
return;
}
if (n == m) return cout << "No\n", void();
if (phi[mod] % (n - 1) || phi[mod] % (m - 1)) return cout << "No\n", void();
int pd = 0;
if (n > m) swap(n, m), pd = 1;
int mul = get(n, m);
if (!mul) return cout << "No\n", void();
for (int i = 0; i < n * m; i ++ ) vis[i] = 0;
vector<int> ans1, ans2;
ll res = 1;
res = res * mul % (n * m);
ans2.push_back(1);
while (res != 1) ans2.push_back(res), res = res * mul % mod;
for (int i = 1; i < mod; i ++ )
{
if (!vis[i] && i % n && i % m)
{
ans1.push_back(i);
for (auto t : ans2) vis[t * i % mod] = 1;
}
}
if (pd) swap(ans1, ans2), swap(n, m);
for (int i = n; i < mod; i += n)
{
pd = 0;
for (int j = 0; j < mod; j += n) vis[j] = 0;
for (auto t : ans2)
if (vis[1ll * t * i % mod]) pd = 1;
else vis[1ll * t * i % mod] = 1;
if (!pd)
{
ans1.push_back(i);
break;
}
}
for (int i = m; i < mod; i += m)
{
pd = 0;
for (int j = 0; j < mod; j += m) vis[j] = 0;
for (auto t : ans1)
if (vis[1ll * t * i % mod]) pd = 1;
else vis[1ll * t * i % mod] = 1;
if (!pd)
{
ans2.push_back(i);
break;
}
}
if (ans1.size() != n || ans2.size() != m) return cout << "No\n";
cout << "Yes\n";
// for (int i = 0; i < n; i ++ )
// {
// for (int j = 0; j < m; j ++ )
// cout << ans1[i] * ans2[j] % mod << ' ';
// cout << "\n";
// }
for (int i = 0; i < n; i ++ ) cout << ans1[i] << " \n"[i == n - 1];
for (int i = 0; i < m; i ++ ) cout << ans2[i] << " \n"[i == m - 1];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int T = 1;
cin >> T;
while (T -- ) solve();
return 0;
}
Details
answer.code:125:2: error: stray ‘#’ in program 125 | }#include <bits/stdc++.h> | ^ answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:12: error: ‘bits’ was not declared in this scope 125 | }#include <bits/stdc++.h> | ^~~~ answer.code:125:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’? 125 | }#include <bits/stdc++.h> | ^~~~ | std answer.code:125:3: error: ‘include’ does not name a type 125 | }#include <bits/stdc++.h> | ^~~~~~~ answer.code:128:11: error: redefinition of ‘const int N’ 128 | const int N = 1e6 + 10; | ^ answer.code:4:11: note: ‘const int N’ previously defined here 4 | const int N = 1e6 + 10; | ^ answer.code:129:5: error: redefinition of ‘int primes [1000010]’ 129 | int primes[N], st[N], phi[N], cnt; | ^~~~~~ answer.code:5:5: note: ‘int primes [1000010]’ previously declared here 5 | int primes[N], st[N], phi[N], cnt; | ^~~~~~ answer.code:129:16: error: redefinition of ‘int st [1000010]’ 129 | int primes[N], st[N], phi[N], cnt; | ^~ answer.code:5:16: note: ‘int st [1000010]’ previously declared here 5 | int primes[N], st[N], phi[N], cnt; | ^~ answer.code:129:23: error: redefinition of ‘int phi [1000010]’ 129 | int primes[N], st[N], phi[N], cnt; | ^~~ answer.code:5:23: note: ‘int phi [1000010]’ previously declared here 5 | int primes[N], st[N], phi[N], cnt; | ^~~ answer.code:129:31: error: redefinition of ‘int cnt’ 129 | int primes[N], st[N], phi[N], cnt; | ^~~ answer.code:5:31: note: ‘int cnt’ previously declared here 5 | int primes[N], st[N], phi[N], cnt; | ^~~ answer.code:130:5: error: redefinition of ‘int vis [1000010]’ 130 | int vis[N], mod; | ^~~ answer.code:6:5: note: ‘int vis [1000010]’ previously declared here 6 | int vis[N], mod; | ^~~ answer.code:130:13: error: redefinition of ‘int mod’ 130 | int vis[N], mod; | ^~~ answer.code:6:13: note: ‘int mod’ previously declared here 6 | int vis[N], mod; | ^~~ answer.code:132:6: error: redefinition of ‘void init()’ 132 | void init() | ^~~~ answer.code:8:6: note: ‘void init()’ previously defined here 8 | void init() | ^~~~ answer.code:151:5: error: redefinition of ‘int get(int, int)’ 151 | int get(int n, int m) | ^~~ answer.code:27:5: note: ‘int get(int, int)’ previously de...