/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 14ms 2.957 MiB
#2 Wrong Answer 549ms 3.246 MiB

Code

t = int(input())

for i in range(t):
	n,m = map(int, input().split())
	if n <= m:
		mi = n
	else:
		mi = m
	
	lcd = -1
	
	if n == 1 or m == 1:
		lcd = -1
	elif m == n:
		lcd = m
	elif n<=1 or m<=1:
		lcd = -1
		
	elif n % 2 != 0 and m % 2 != 0:
		
		k = 3
		
		while mi/2 >= k:
			if m % k == 0 and n % k == 0:
				lcd = k
				break
			
			k = k+2
		
	elif n % 2 != 0 and m % 2 != 0:
		
		k = 3
		
		while mi/2 >= k:
			if m % k == 0 and n % k == 0:
				lcd = k
				break
			
			k = k+2
			
	else:
		k = 2
		
	
		for _ in range(mi):
			if m % k == 0 and n % k == 0:
				lcd = k
				break
			
			k = k+1
			
			

	print(lcd)
		
	

Information

Submit By
Type
Submission
Problem
P1011 LCD
Contest
Brain booster - 1
Language
Python 3 (Python 3.12.3)
Submit At
2023-12-31 17:05:56
Judged At
2024-11-11 03:44:50
Judged By
Score
0
Total Time
549ms
Peak Memory
3.246 MiB