QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#239372#7688. Alea Iacta Estucup-team2303#TL 1ms7700kbC++172.8kb2023-11-04 20:23:002023-11-04 20:23:00

Judging History

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

  • [2023-11-04 20:23:00]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7700kb
  • [2023-11-04 20:23:00]
  • 提交

answer

/*
60 + 0 + 100 + 64 = 224.
*/

#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>
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 = 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)
{
	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); putchar(' ');
	L(i, 1, ca)
	{
		Write(G[id][i]); putchar(' ');
	}
	puts("");
	Write(cb); putchar(' ');
	L(i, 1, cb)
	{
		Write(G[id ^ 1][i]); putchar(' ');
	}
	puts(""); 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); putchar(' ');
	L(i, 1, a)
	{
		Write(i); putchar(' ');
	}
	puts("");
	Write(b); putchar(' ');
	int nw = 1;
	L(i, 1, b / y)
	{
		L(j, 1, y)
		{
			Write(nw + j - 1); putchar(' ');
		}
		nw += a;
	}
	puts(""); return ;
}
inline void solve()
{
	x = read(), y = read();
	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) {puts("0"); puts("0"); 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(a + b >= 3e6) get(x, y, a, b);
		else 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: 1ms
memory: 7700kb

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

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...

result: