QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#401625 | #2488. Diophantine Equation | Massachusetts Institute of Terriers (Yi Du, Mutiraj Laksanawisit) | AC ✓ | 162ms | 3788kb | C++14 | 3.8kb | 2024-04-29 04:12:04 | 2024-04-29 04:12:04 |
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;
ll n;
bool check(ll i) {
if (n * n % i != 0) {
return false;
}
ll a = 3;
ll b = -3 * i;
ll c = i * i - n * n / i;
if (b * b < 4 * a * c) {
return false;
}
ll sr = sqrt(b * b - 4 * a * c);
if (sr * sr != b * b - 4 * a * c) {
return false;
}
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 true;
}
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 true;
}
return false;
}
vector<int> p, c;
bool dfs(int idx, ll val) {
if (idx == (int)p.size()) {
return check(val);
}
for (int i = 0; i <= 2 * c[idx]; ++i) {
if (dfs(idx + 1, val)) {
return true;
}
val *= p[idx];
if (val > 2000000) {
return false;
}
}
return false;
}
void solve_case() {
cin >> n;
int nn = n;
vector<int>().swap(p);
vector<int>().swap(c);
for (int i = 2; i * i <= n; ++i) {
if (nn % i == 0) {
p.push_back(i);
c.push_back(0);
while (nn % i == 0) {
c.back()++;
nn /= i;
}
}
}
if (nn > 1) {
p.push_back(nn);
c.push_back(1);
}
// for (int i = 0; i < (int)p.size(); ++i) {
// cout << p[i] << " " << c[i] << endl;
// }
if (!dfs(0, 1)) {
cout << "impossible" << endl;
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve_case();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
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: 1ms
memory: 3744kb
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: 1ms
memory: 3708kb
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: 38ms
memory: 3636kb
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: 0ms
memory: 3616kb
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: 3548kb
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: 0
Accepted
time: 19ms
memory: 3560kb
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:
77618 38809 139080 66120 298606 230594 97504 75296 427680 199584 2450 2450 93466 31382 40320 8064 58500 9000 7800 4836 99600 72625 163247 11501 37888 11264 468441 107640 79202 39601 98432 52292 17342 15457 218400 154336 117128 117128 100009 92316 374400 316800 125028 21744 316800 118800 43012 28136 ...
result:
ok correct (1000 test cases)
Test #8:
score: 0
Accepted
time: 38ms
memory: 3620kb
input:
1000 4659790 756706755 892782275 5073646 560405840 301378997 703288676 878602620 260517179 695068338 363950680 78798246 521001501 120843464 542026170 716387002 597022800 232311387 999324712 515863465 10772182 606655041 965218020 513679921 926529099 579707361 492672482 807115468 407041680 115903784 2...
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 #9:
score: 0
Accepted
time: 38ms
memory: 3700kb
input:
1000 74085232 438931830 232448941 701818317 32154723 194890998 442009850 223149192 586775286 81972070 406650099 180420864 589967418 466343846 70488633 564320379 592790935 420084347 161176399 780119081 93301185 777537511 50293237 91301813 357341165 181837851 210338703 82136693 626448529 318597694 674...
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 #10:
score: 0
Accepted
time: 39ms
memory: 3696kb
input:
1000 149529727 532537074 540218763 337089971 895728366 984280909 889037403 89133487 492385379 948103763 156330648 977670051 46436989 533988185 310498340 605368806 224497164 670604214 256396846 154827292 732145510 217800547 857192275 71225343 984736122 241891024 880608957 431838058 830971153 56100458...
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 #11:
score: 0
Accepted
time: 38ms
memory: 3604kb
input:
1000 829498612 419176066 348105251 576495408 791966078 456890234 38388898 501283107 534413190 673568033 962468095 696320911 797809469 423608094 175833538 128887066 651155288 491244328 195452313 381112758 443699912 743914232 677398193 598451992 552032668 997294852 981883093 587911607 104645549 299688...
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 #12:
score: 0
Accepted
time: 38ms
memory: 3600kb
input:
1000 832532703 931734901 52618985 663967634 155815551 795421942 692889761 591919395 710665889 701119466 236886042 723567388 717630678 536307451 353077852 194361659 751711096 301902698 468567491 791941313 126293332 550370588 664917510 86524251 505201207 402703936 341263859 923551059 638071102 8592249...
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 #13:
score: 0
Accepted
time: 38ms
memory: 3592kb
input:
1000 356987856 725606135 81168215 553014597 848176887 48977207 82876483 273081810 782507352 444243076 980578298 675745698 436732998 590101594 616828556 917408805 581998157 64437687 660468105 99392050 915758344 617244941 575612231 98798559 393212398 37550214 634921787 868697586 987382663 360416467 40...
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 #14:
score: 0
Accepted
time: 37ms
memory: 3652kb
input:
1000 377873513 49486553 975739372 663689755 441052587 259609372 911537594 802211147 631333550 99608010 19284118 376882787 635753005 755236099 856553163 373074134 311297735 294801283 332372147 215438965 885151424 406044496 974664883 708556628 739470513 666503845 102329511 856563226 370341969 73225851...
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 #15:
score: 0
Accepted
time: 38ms
memory: 3620kb
input:
1000 306792974 373882252 979281347 57507797 834364016 383439209 225915528 865334138 464462735 996401667 960728815 224927504 152168804 589420658 32214993 880500645 488756214 588758993 716599157 609100067 628791020 902557886 154317628 495399170 158140712 109906436 728598944 560001820 116920265 1405292...
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 #16:
score: 0
Accepted
time: 38ms
memory: 3760kb
input:
1000 114065546 943881868 674336930 289433500 328318660 479949429 537612724 282503464 588639103 584864706 12986246 127057356 827305473 361700525 521959392 71259392 630197390 614424158 265162644 221602799 131958650 53669963 208272578 609836110 469910984 346913663 979671424 437091110 834796390 67720849...
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 #17:
score: 0
Accepted
time: 27ms
memory: 3620kb
input:
1000 94613768 865989019 289530920 416522245 79536964 615264952 597771631 30640680 763080294 482609488 1643880 897215216 73670709 732058095 264155500 387737792 639166833 134181860 15876000 426334142 620935638 867466003 111894738 232031840 363785462 322588050 138557039 238314144 282732350 619481207 21...
output:
206340 55024 impossible impossible impossible 182666 61370 impossible impossible 96264 36036 impossible impossible 13928 772 impossible 153586 121745 impossible 410050 94050 476560 347904 impossible impossible 63000 12600 impossible impossible impossible impossible impossible impossible impossible i...
result:
ok correct (1000 test cases)
Test #18:
score: 0
Accepted
time: 32ms
memory: 3764kb
input:
1000 70019040 445644040 161631442 27539784 595698772 362551228 932480812 52802635 465173765 14016566 29302368 904571136 430526760 287691495 125043776 242109000 312694235 383669077 398236937 80704 924886888 45235099 87234174 789602260 705200528 42795105 747302717 13561648 38864924 110132928 881215825...
output:
165956 69244 impossible impossible 89280 36036 impossible impossible impossible impossible impossible impossible 95036 6532 impossible impossible 421337 199738 247312 79872 381150 148050 460306 62769 447785 385784 impossible 1792 912 impossible impossible impossible impossible impossible 122249 1642...
result:
ok correct (1000 test cases)
Test #19:
score: 0
Accepted
time: 56ms
memory: 3612kb
input:
1000 1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991 999999990 999999989 999999988 999999987 999999986 999999985 999999984 999999983 999999982 999999981 999999980 999999979 999999978 999999977 999999976 999999975 999999974 999999973 999999972 9999...
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 #20:
score: 0
Accepted
time: 162ms
memory: 3788kb
input:
3000 1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991 999999990 999999989 999999988 999999987 999999986 999999985 999999984 999999983 999999982 999999981 999999980 999999979 999999978 999999977 999999976 999999975 999999974 999999973 999999972 9999...
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 (3000 test cases)
Test #21:
score: 0
Accepted
time: 93ms
memory: 3704kb
input:
3000 630577376 971315648 219486861 122842167 33422116 829547701 215103567 682243813 495679826 277025127 47805122 53379456 602605537 774607710 165209625 544067179 69450591 258966643 307995801 175934892 331135106 355876290 178229107 380076017 317289506 146089500 559655507 172974204 19652000 867272160 ...
output:
impossible impossible 302841 273240 impossible 103454 21398 impossible 356201 102442 impossible impossible impossible impossible 124168 97784 impossible impossible 300510 53865 impossible 136052 132097 impossible impossible 313978 7658 impossible impossible impossible impossible impossible 275825 70...
result:
ok correct (3000 test cases)
Test #22:
score: 0
Accepted
time: 56ms
memory: 3656kb
input:
3000 143493168 218549097 17732389 237663602 97226325 91714560 9084426 316324008 27722250 139968000 23774016 288294600 290136060 4682688 12857208 82689800 26891200 280973760 106833867 15636615 17322498 149398095 303595656 344935500 31853196 434617407 18626517 28227000 131274675 91378125 322859628 354...
output:
273182 58786 362826 6777 65417 32552 381535 98109 211185 32490 189136 118064 43537 1547 380160 356004 91575 8325 259200 129600 78736 42560 367840 321860 409014 250686 26912 13456 54404 16240 186470 70730 82320 54880 398176 251024 216482 108241 62281 14294 55917 50031 238249 206426 447304 138788 4455...
result:
ok correct (3000 test cases)