QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239215 | #7688. Alea Iacta Est | ucup-team2303# | TL | 0ms | 3760kb | C++14 | 2.1kb | 2023-11-04 19:13:23 | 2023-11-04 19:13:24 |
Judging History
answer
/*
60 + 0 + 100 + 64 = 224.
*/
#include <bits/stdc++.h>
using namespace std;
#define int 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>
inline int read()
{
int sum = 0, nega = 1;
char ch = getchar();
while (ch > '9'||ch < '0')
{
if (ch == '-') nega = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') sum = sum * 10 + ch - '0', ch = getchar();
return sum * nega;
}
const int N = 1e6 + 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;
vector<int> G1, G2, F, tmp;
inline void dfs(int fx, int fy, int fa, int fb, int nw)
{
if(nw == siz) 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) swap(G1, G2), swap(fa, fb), swap(a, b);
tmp.clear();
x /= fac, a /= fac;
int val = 1;
L(i, 1, fac)
{
for (auto v : G1) tmp.pb(v + val - 1);
val += fx;
}
fx *= fac, fa *= fac; swap(tmp, G1);
// puts("------------------");
// for (auto v : G1) cout << v << " "; cout << endl;
// for (auto v : G2) cout << v << " "; cout << endl;
// puts("-------------------");
dfs(fx, fy, fa, fb, nw); return ;
}
inline void work()
{
// cout << a << " " << b << endl;
siz = F.size();
G1.pb(1); G2.pb(1);
dfs(1, 1, 1, 1, 0);
printf("%lld ", G1.size());
for (auto v : G1) printf("%lld ", v); puts("");
printf("%lld ", G2.size());
for (auto v : G2) printf("%lld ", v);
puts(""); return ;
}
inline void solve()
{
x = read(), y = read();
int t = x * y, f = sqrt(t);
G1.clear(), G2.clear(); F.clear(); siz = F.size();
int ff = t;
L(i, 2, f)
if(ff % i == 0)
{
F.pb(i);
while(ff % i == 0) ff /= i;
}
if(ff != 1) F.pb(ff);
R(i, f, 1)
{
if(t % i != 0) continue;
a = i, b = t / i;
if(a == x || a == y) continue;
work(); return ;
}
puts("0"); puts("0");
return ;
}
signed main()
{
T = read();
L(i, 1, T) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3760kb
input:
3 2 8 1 9 2 9
output:
4 1 3 5 7 4 1 2 2 3 3 1 4 7 3 1 2 3 3 1 4 7 6 1 2 2 3 3 4
result:
ok Correct. (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
1 40013 40013