← Home
For problem statement at 1000-1999/1700-1799/1740-1749/1744/problemE2.txt this is a correct solution, but verifier at 1000-1999/1700-1799/1740-1749/1744/verifierE2.go ends with wrong answer
input:
100
721622 629873 1411705 1413832
84513 314062 292484 1069199
301302 143806 687888 178134
870992 800290 1167830 914960
908880 314893 984544 997778
130944 525678 513721 531303
841127 808505 1398466 1524676
192975 336622 711310 729468
599242 328144 1111112 953712
420269 24604 592173 675308
8661 511099 218999 1001005
617273 976011 641736 1866998
674504 192561 1660088 1151833
202120 862894 645358 1861167
114955 666671 319240 1167221
683394 444434 788259 539414
892266 962793 978473 1242506
823811 190432 1131359 1100987
122601 594905 138537 606089
314965 692943 1054968 748936
895623 319829 1815146 650235
299447 941318 861570 1423247
340688 942375 704004 992796
607927 923445 718062 1246676
211070 835494 852412 930952
115378 625454 959614 1303121
627506 413139 775757 845210
316058 298006 546508 1213520
797422 586401 1734523 612655
185447 851656 1017095 1329220
863851 294456 1648858 965407
71918 954822 738900 1908567
423845 751314 435837 1572885
140352 258203 181649 519786
171695 363203 1128082 1312997
567815 517445 1105950 1331262
483751 343891 1266444 441262
145541 134460 1034211 536041
529596 934650 1427406 1073608
279667 413636 350421 1393551
863098 788621 1854380 1661528
696979 627669 1069290 750469
234973 81870 1141041 680542
847484 655078 967423 908300
760837 432831 1271689 687217
843715 395281 938407 628354
484960 861296 741411 1212377
797811 568851 1540775 1062986
466459 160072 1399934 685355
775419 74424 789261 393345
820634 332061 1206747 1055749
823879 859515 1015584 1421311
855738 760009 1114563 1694110
768635 395216 1654772 1241682
619125 628389 777942 1235721
827971 646695 1033869 1457112
565794 503589 1104617 781211
15455 653652 81980 931383
988913 170575 1780193 950139
719981 679033 1070957 1371729
319909 52334 321673 798674
484771 103637 987067 222744
940042 422859 1421128 1293342
226839 51538 234357 427247
46857 203595 621604 1150854
775164 949760 972460 1285635
670898 452509 1309447 1015991
316965 927822 1130278 1309721
475330 250844 1364849 707869
361267 109582 1191942 375301
803683 599401 1305663 771597
697335 232218 1054786 304344
659912 692444 1090966 1513649
921764 874821 1547554 1424392
252103 70570 264735 326482
557017 236623 776305 1044596
985291 17057 1915637 184717
930234 216553 1283679 887779
55228 907639 310870 1399506
821431 214752 1377475 506791
165976 819335 762368 836235
481972 451848 539820 585628
111123 859879 557331 1022684
889132 957305 1342615 1172644
917797 525217 933395 687498
721608 512134 724875 980429
736839 684450 1383949 1241602
76458 205292 843288 734017
66448 328137 551809 337804
523642 904393 1421833 1443587
905478 879305 1203262 1307085
675234 967463 686347 1325588
543137 867546 1343549 1522711
783156 210038 1011032 508010
11740 742732 378596 1682714
777504 764853 1158286 1010587
935141 208977 1911639 770253
472125 225527 524639 295597
498063 445316 1248813 1416474
528442 805558 1412431 1430544

expected:
1259746 721622
134598 394394
575224 150651
-1 -1
958370 597264
-1 -1
1199149 1134230
257300 504933
943414 416864
442872 420269
9046 978693
-1 -1
758817 513496
303180 1725788
-1 -1
-1 -1
-1 -1
952160 823811
-1 -1
-1 -1
959487 597082
470659 1197788
668640 960325
-1 -1
379770 928708
312727 692268
-1 -1
447009 632116
-1 -1
864253 913720
883368 863851
113014 1215228
-1 -1
140838 514624
363203 515085
601355 977170
-1 -1
201690 291082
1048550 944136
310227 1118668
1577242 863098
-1 -1
245610 469946
-1 -1
1009939 652146
-1 -1
-1 -1
1327319 683838
533096 560252
-1 -1
996183 820634
-1 -1
860614 1511406
1537270 790432
698210 1114425
-1 -1
1007178 565794
27819 726280
1016627 331850
-1 -1
-1 -1
901922 111407
1268577 940042
231921 151226
62476 610785
-1 -1
905018 670898
486002 1210230
522863 456080
722534 219164
-1 -1
-1 -1
1019864 896104
1382646 1166428
-1 -1
709869 557017
-1 -1
1240312 649659
-1 -1
1201269 440544
327734 829880
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
1174550 858762
114687 410584
328137 332240
904393 1047284
-1 -1
-1 -1
698319 1349516
840152 391578
185683 751360
-1 -1
1080022 361887
-1 -1
664084 1335948
805558 1056884
got:
1082433 1259746
112684 942186
575224 150651
-1 -1
958370 597264
-1 -1
1134230 1199149
275418 707575
625296 943414
442872 420269
9046 978693
-1 -1
1540488 252939
303180 1725788
-1 -1
-1 -1
-1 -1
947136 993817
-1 -1
-1 -1
959487 597082
470659 1197788
668640 960325
-1 -1
379770 928708
173067 1250908
-1 -1
447009 632116
-1 -1
265924 1187836
883368 863851
74888 1833909
-1 -1
140838 514624
317630 392659
663447 1328575
-1 -1
978570 139986
1417050 1047924
310227 1118668
1294647 1577242
-1 -1
1132535 84930
-1 -1
1009939 652146
-1 -1
-1 -1
1327319 683838
1348949 166056
-1 -1
996183 820634
-1 -1
860614 1511406
1537270 592824
698210 1114425
-1 -1
1007178 565794
22110 913812
1016627 331850
-1 -1
-1 -1
779849 128846
1410063 563812
231921 151226
48475 983997
-1 -1
1006347 905018
484092 1215005
1254220 285198
931447 127506
-1 -1
-1 -1
977568 1402313
1166428 1382646
-1 -1
709869 557017
-1 -1
1240312 649659
-1 -1
1201269 293696
327734 829880
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
1338987 753300
96608 649893
328137 332240
904393 1047284
-1 -1
-1 -1
674758 1396638
840152 391578
17610 1485464
-1 -1
1620033 241258
-1 -1
664084 1335948
805558 1056884

exit status 1 can you fix the verifier? ```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader
var writer *bufio.Writer

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func solve() {
	var a, b, c, d int64
	fmt.Fscan(reader, &a, &b, &c, &d)

	// We need x in (a, c] and y in (b, d] such that a*b divides x*y
	// Let's try x = a * k for some k, and find appropriate y
	// x must be multiple of a/gcd(a, something)
	
	// Strategy: enumerate divisors of a*b
	// For each divisor g1 of a*b, let x = a / gcd(a, g1) * (some multiplier)
	// Actually, let's think differently:
	// Let g = gcd(a, b... no
	
	// For x = a*(some factor), y = b*(some factor) won't work directly
	// Let's try: pick x as smallest multiple of a that is > a, i.e., x = 2*a if 2*a <= c
	// Then need y such that a*b | x*y => b | y (if x = 2a, then 2a*y divisible by a*b => 2y divisible by b)
	// y must be multiple of b/gcd(2,b)
	
	// General approach: try all divisors of a (up to sqrt(a))
	// For each way to split a*b = A * B where A | x and B | y
	// x = A * ceil((a+1)/A), y = B * ceil((b+1)/B)
	// Check if x <= c and y <= d
	
	ab := a * b
	
	bestX, bestY := int64(-1), int64(-1)
	
	// Enumerate divisors of ab by iterating i from 1 to sqrt(ab)
	// For each divisor i of ab, consider using g1 = i as the part that x must be multiple of
	// Then g2 = ab / i, y must be multiple of g2
	
	var i int64
	for i = 1; i*i <= ab; i++ {
		if ab%i != 0 {
			continue
		}
		// Try g1 = i, g2 = ab/i
		for _, pair := range [][2]int64{{i, ab / i}, {ab / i, i}} {
			g1, g2 := pair[0], pair[1]
			// x must be multiple of g1, x > a
			// smallest multiple of g1 that is > a
			x := ((a / g1) + 1) * g1
			// y must be multiple of g2, y > b
			y := ((b / g2) + 1) * g2
			
			if x <= c && y <= d {
				// verify
				if (x*y)%ab == 0 {
					bestX, bestY = x, y
					break
				}
			}
		}
		if bestX != -1 {
			break
		}
	}
	
	if bestX == -1 {
		// Try harder: enumerate divisors of a, for each divisor da of a,
		// let x be smallest multiple of a/da > a, then need (da*b) | (x/a*a ... )
		// Actually let's just be more careful
		// x*y % (a*b) == 0
		// Let ga = gcd(x, a), so x = ga * x', gcd(x', a/ga) = 1
		// then need (a/ga * b) | (x' * y)
		// since gcd(x', a/ga)=1, need (a/ga * b) | y ... this is getting complex
		
		// The loop above should cover all cases since we try all divisors of ab
		fmt.Fprintln(writer, -1, -1)
		return
	}
	
	fmt.Fprintln(writer, bestX, bestY)
}

func main() {
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	
	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		solve()
	}
}
```