QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239499 | #7688. Alea Iacta Est | ucup-team2303# | 0 | 0ms | 9728kb | C++17 | 4.9kb | 2023-11-04 20:58:31 | 2023-11-04 20:58:32 |
answer
/*
60 + 0 + 100 + 64 = 224.
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define L(i, j, k) for (int i = (j); i <= (k); i++)
#define R(i, j, k) for (int i = (j); i >= (k); i--)
#define pb push_back
#define pii pair<int, int>
namespace FastIO {
char buf[1 << 21], buf2[1 << 21], a[20], *p1 = buf, *p2 = buf, hh = '\n';
//一共占了4M 1M=2^20B,2个2M的char数组
//1char占1B(字节)
//a用来临时存每个整数,不会超过20位
int p, p3 = -1; //p临时指针
void read() {}
void print() {} //为空的时候就会调用这玩意而不是下面那个print,于是就退出了循环
inline int getc() { //超快速读入的getchar
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;
}
inline void flush() {
fwrite(buf2, 1, p3 + 1, stdout), p3 = -1;
// 从buf2写,每个写入的元素占1个字节,写入p3+1个,写到标准输出stdout里面
}
template <typename T, typename... T2>
inline void read(T &x, T2 &...oth) {
int f = 0;
x = 0;
char ch = getc();//更快的读入
while (!isdigit(ch)) {
if (ch == '-') f = 1;
ch = getc();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getc();
}
x = f ? -x : x;
read(oth...);
}
// template <typename T, typename... T2>
inline void print(int x, char o) { //没有引用
if (p3 > 1 << 20) //接近超空间自动刷新
flush();
if (x < 0)
buf2[++p3] = 45, x = -x; //45ascii是负号
do {
a[++p] = x % 10 + 48;
} while (x /= 10);
do {
buf2[++p3] = a[p];
} while (--p);
buf2[++p3] = o; //换行
// print(oth...);
}
}
#define read FastIO::read
#define print FastIO::print
const int N = 7e7 + 9, mod = 998244353;
inline void add(int &x, int y) {x = (x + y) % mod;}
inline void del(int &x, int y) {x = (x - y + mod) % mod;}
int T, x, y, siz, a, b, ca, cb;
int G[2][N], F[109], tmp[N], id = 0;
inline void Write(int X)
{
print(X, ' ');
// if(X > 9) Write(X / 10);;
// putchar(X % 10 + '0');
}
inline void dfs(int fx, int fy, int fa, int fb, int nw)
{
if(nw == siz + 1) return ;
int fac = F[nw];
if(x % fac != 0 && y % fac != 0) {dfs(fx, fy, fa, fb, nw + 1); return ;}
if(x % fac != 0) swap(x, y), swap(fx, fy);
if(a % fac != 0) id ^= 1, swap(fa, fb), swap(a, b), swap(ca, cb);
x /= fac, a /= fac;
int val = 1, cn = 0;
L(i, 1, fac)
{
L(j, 1, ca) tmp[++cn] = G[id][j] + val - 1;
val += fx;
}
L(i, 1, cn) G[id][i] = tmp[i]; ca = cn;
fx *= fac, fa *= fac;
// puts("----------------------");
// cout << ca << " " << cb << endl;
// L(i, 1, ca) cout << G[id][i] << " "; cout << endl;
// L(i, 1, cb) cout << G[id ^ 1][i] << " "; cout << endl;
// puts("------------------------");
dfs(fx, fy, fa, fb, nw); return ;
}
inline void work()
{
ca = cb = 1;
G[0][1] = 1, G[1][1] = 1; id = 0;
dfs(1, 1, 1, 1, 1);
Write(ca);
L(i, 1, ca)
{
Write(G[id][i]);
}
FastIO::buf2[++FastIO::p3] = '\n';
// cout << '\n';
Write(cb);
L(i, 1, cb)
{
Write(G[id ^ 1][i]);
}
FastIO::buf2[++FastIO::p3] = '\n';
return ;
}
inline void get(int x, int y, int a, int b)
{
if(x % a != 0 && x % b != 0) swap(x, y);
if(x % a != 0) swap(a, b);
Write(a);
L(i, 1, a)
{
Write(i);
}
FastIO::buf2[++FastIO::p3] = '\n';
Write(b);
int nw = 1;
L(i, 1, b / y)
{
L(j, 1, y)
{
Write(nw + j - 1);;
}
nw += a;
}
FastIO::buf2[++FastIO::p3] = '\n';
return ;
}
inline void solve()
{
read(x), read(y);
ll t = 1ll * x * y, f = sqrt(t); siz = 0;
ll ff = t;
L(i, 2, f)
if(ff % i == 0)
{
F[++siz] = i;
while(ff % i == 0) ff /= i;
}
if(ff != 1)
{
if(ff == t) {print(0, '\n'), print(0, '\n'); return ;}
F[++siz] = ff;
}
R(i, max(1ll, f), 1)
{
if(t % i != 0) continue;
a = i, b = t / i;
if(a == x || a == y) continue;
if(x % a == 0 || y % a == 0 || x % b == 0 || y % b == 0) get(x, y, a, b);
else work();
return ;
}
print(0, '\n'), print(0, '\n');
// puts("0"); puts("0");
return ;
}
signed main()
{
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
read(T);
L(i, 1, T) solve();
FastIO::flush(); //手动输出
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9728kb
input:
3 2 8 1 9 2 9
output:
4 1 2 3 4 4 1 2 5 6 3 1 2 3 3 1 4 7 3 1 2 3 6 1 2 4 5 7 8
result:
ok Correct. (3 test cases)
Test #2:
score: -100
Output Limit Exceeded
input:
1 40013 40013
output:
1 1 1601040169 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...