QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401132 | #2488. Diophantine Equation | Massachusetts Institute of Terriers (Yi Du, Mutiraj Laksanawisit) | WA | 58ms | 3724kb | C++14 | 3.1kb | 2024-04-28 00:56:56 | 2024-04-28 00:56:56 |
Judging History
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 <= 20000; ++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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
4 1 2 3 4
output:
impossible impossible 2 1 2 2
result:
ok correct (4 test cases)
Test #2:
score: 0
Accepted
time: 57ms
memory: 3700kb
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:
impossible impossible 2 1 2 2 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 8 4 impossible impossible impossible impossible impossible im...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 54ms
memory: 3580kb
input:
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 ...
output:
impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 91 65 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossib...
result:
ok correct (1000 test cases)
Test #4:
score: 0
Accepted
time: 58ms
memory: 3652kb
input:
1000 247757905 960577391 178241140 964243209 972616426 907455375 140900159 140627928 402419086 298350695 631415660 417560469 561576156 905633503 449222404 662125716 507262669 255811119 902129591 734930237 340169307 197443442 758463177 544759251 702352772 356479786 253292154 454046907 14403458 225277...
output:
impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible imp...
result:
ok correct (1000 test cases)
Test #5:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
1000 4644 525 4 312 784 1225 1225 8281 6292 375 9310 6877 6696 1344 6292 8424 5368 10125 1183 4644 9765 8775 9765 1029 5368 10088 1536 1323 648 6696 9548 6776 3993 648 1225 9747 6292 9464 1029 168 1536 8232 8281 4200 192 2888 375 2646 312 1323 1372 4536 1029 2646 10088 3993 4536 8232 312 4563 24 518...
output:
249 183 65 10 2 2 46 2 84 28 105 70 105 70 364 273 330 154 50 25 371 329 345 184 354 78 104 88 330 154 414 18 260 224 450 225 104 65 249 183 433 242 345 330 433 242 98 49 260 224 448 228 128 64 105 84 72 36 354 78 450 34 352 132 242 121 72 36 105 70 456 57 330 154 416 260 98 49 26 22 128 64 392 196 ...
result:
ok correct (1000 test cases)
Test #6:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
1000 9747 32 4 525 8281 6776 4225 8232 4704 2496 375 8424 2646 3993 3993 648 648 8281 9765 4536 6292 4200 4 1183 2048 4225 4225 98 6877 1536 1261 10125 1261 10088 256 168 525 1372 10125 9800 5324 6877 648 6776 8112 2916 6591 6877 671 81 9310 3993 1536 2646 2187 2646 1824 1824 1344 8112 5368 847 168 ...
output:
456 57 8 8 2 2 65 10 364 273 352 132 260 65 392 196 280 56 184 8 50 25 414 18 189 63 242 121 242 121 72 36 72 36 364 273 433 242 234 198 330 154 260 40 2 2 104 65 128 128 260 65 260 65 21 7 345 184 128 64 112 57 450 225 112 57 448 228 32 32 26 22 65 10 98 98 450 225 420 280 242 242 345 184 72 36 352...
result:
ok correct (1000 test cases)
Test #7:
score: -100
Wrong Answer
time: 56ms
memory: 3724kb
input:
1000 22936119 54583200 197197560 36794880 293559552 171500 29110392 8128512 14175000 766584 37028375 65969582 7471104 322552989 23641797 33116216 2984709 118716416 56689952 42273035 290304000 44325144 182952000 10091928 40265652 227952900 2584320 59768832 10698240 95067648 39000000 266149608 1925586...
output:
impossible impossible impossible impossible impossible 2450 2450 impossible impossible impossible 7800 4836 impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible impossible 18832 368 imposs...
result:
wrong output format Expected integer, but "impossible" found (test case 1)