QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401130#2488. Diophantine EquationMassachusetts Institute of Terriers (Yi Du, Mutiraj Laksanawisit)TL 12ms3760kbC++143.1kb2024-04-28 00:55:282024-04-28 00:55:29

Judging History

This is the latest submission verdict.

  • [2024-04-28 00:55:29]
  • Judged
  • Verdict: TL
  • Time: 12ms
  • Memory: 3760kb
  • [2024-04-28 00:55:28]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

/* --------------- fast io --------------- */ // begin
namespace Fread {
const int SIZE = 1 << 21;
char buf[SIZE], *S, *T;
inline char getchar() {
	if (S == T) {
		T = (S = buf) + fread(buf, 1, SIZE, stdin);
		if (S == T) return '\n';
	}
	return *S++;
}
} // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 21;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
	fwrite(buf, 1, S - buf, stdout);
	S = buf;
}
inline void putchar(char c) {
	*S++ = c;
	if (S == T) flush();
}
struct NTR {
	~ NTR() { flush(); }
} ztr;
} // namespace Fwrite
#ifdef ONLINE_JUDGE
#define getchar Fread :: getchar
#define putchar Fwrite :: putchar
#endif
namespace Fastio {
struct Reader {
	template<typename T>
	Reader& operator >> (T& x) {
		char c = getchar();
		T f = 1;
		while (c < '0' || c > '9') {
			if (c == '-') f = -1;
			c = getchar();
		}
		x = 0;
		while (c >= '0' && c <= '9') {
			x = x * 10 + (c - '0');
			c = getchar();
		}
		x *= f;
		return *this;
	}
	Reader& operator >> (char& c) {
		c = getchar();
		while (c == ' ' || c == '\n') c = getchar();
		return *this;
	}
	Reader& operator >> (char* str) {
		int len = 0;
		char c = getchar();
		while (c == ' ' || c == '\n') c = getchar();
		while (c != ' ' && c != '\n' && c != '\r') { // \r\n in windows
			str[len++] = c;
			c = getchar();
		}
		str[len] = '\0';
		return *this;
	}
	Reader(){}
} cin;
const char endl = '\n';
struct Writer {
	template<typename T>
	Writer& operator << (T x) {
		if (x == 0) { putchar('0'); return *this; }
		if (x < 0) { putchar('-'); x = -x; }
		static int sta[45];
		int top = 0;
		while (x) { sta[++top] = x % 10; x /= 10; }
		while (top) { putchar(sta[top] + '0'); --top; }
		return *this;
	}
	Writer& operator << (char c) {
		putchar(c);
		return *this;
	}
	Writer& operator << (char* str) {
		int cur = 0;
		while (str[cur]) putchar(str[cur++]);
		return *this;
	}
	Writer& operator << (const char* str) {
		int cur = 0;
		while (str[cur]) putchar(str[cur++]);
		return *this;
	}
	Writer(){}
} cout;
} // namespace Fastio
#define cin Fastio :: cin
#define cout Fastio :: cout
#define endl Fastio :: endl
/* --------------- fast io --------------- */ // end

typedef long long ll;

void solve_case() {
	ll n;
	cin >> n;
	for (ll i = 2; i <= 2000000; ++i) {
		// i = x + y
		if (n * n % i != 0) {
			continue;
		}
		ll a = 3;
		ll b = -3 * i;
		ll c = i * i - n * n / i;
		if (b * b < 4 * a * c) {
			continue;
		}
		ll sr = sqrt(b * b - 4 * a * c);
		if (sr * sr != b * b - 4 * a * c) {
			continue;
		}
		if ((-b + sr) % (2 * a) == 0 && (-b + sr) / (2 * a) > 0 && (-b + sr) / (2 * a) < i) {
			cout << (-b + sr) / (2 * a) << " " << i - (-b + sr) / (2 * a) << endl;
			return;
		}
		if ((-b - sr) % (2 * a) == 0 && (-b - sr) / (2 * a) > 0 && (-b - sr) / (2 * a) < i) {
			cout << (-b - sr) / (2 * a) << " " << i - (-b - sr) / (2 * a) << endl;
			return;
		}
	}
	cout << "impossible" << endl;
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		solve_case();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 12ms
memory: 3760kb

input:

4
1
2
3
4

output:

impossible
impossible
2 1
2 2

result:

ok correct (4 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

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

output:


result: