message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
def printDivisors(n) :
i = 1
d = []
while i <= n :
if (n % i==0) :
d.append(i)
i = i + 1
return d
n = int(input())
div = list(map(int,input().split()))
x = max(div)
div_x = printDivisors(x)
for i in div_x:
if i in div:
div.remove(i)
y = max(div)
print(x,y)
``` | instruction | 0 | 70,785 | 22 | 141,570 |
Yes | output | 1 | 70,785 | 22 | 141,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
n = int(input())
l = list(map(int, input().split()))
x = max(l)
c = 1
while c <= x:
if x % c == 0:
l.remove(c)
c += 1
y = max(l)
print(x, y)
``` | instruction | 0 | 70,786 | 22 | 141,572 |
Yes | output | 1 | 70,786 | 22 | 141,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
n = int(input())
x = [ int(k) for k in input().split(' ')]
ans = 1
a = max(x)
x1= x.copy()
b = 1
d = []
for i in x:
if i not in d:
if a%i==0:
d.append(i)
x1.remove(i)
b = max(x1)
print(a,b)
``` | instruction | 0 | 70,787 | 22 | 141,574 |
Yes | output | 1 | 70,787 | 22 | 141,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
from math import sqrt
n = int(input())
inp = [int(x) for x in input().split()]
x = y = 0
freq = [0] * 10001
for i in inp :
freq[i] += 1
x = max(x, i)
fact = x
for i in range (1, int(sqrt(fact)) + 1) :
if fact % i == 0 :
div = fact // i
if i == div :
freq[i] -= 1
else :
freq[i] -= 1
freq[div] -= 1
for i in range (1, 10001) :
if freq[i] != 0 :
y = max(y, i)
print(F"{x} {y}")
``` | instruction | 0 | 70,788 | 22 | 141,576 |
Yes | output | 1 | 70,788 | 22 | 141,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
import sys
n = int(input())
dn = list(map(int, sys.stdin.readline().split()))
x = max(dn)
y = 0
d = {}
for a in dn:
if a not in d:
d[a] = 1
else:
d[a] += 1
for a in dn:
if x % a == 0:
d[a] -= 1
y = 0
for k, v in d.items():
if v > 0 and k > y:
y = k
print(x, y)
``` | instruction | 0 | 70,789 | 22 | 141,578 |
No | output | 1 | 70,789 | 22 | 141,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 18 11:15:07 2019
@author: avina
"""
n = int(input())
L = list(map(int, input().strip().split()))
L.sort(reverse=True)
k = []
for i in range(n):
if L.count(L[i]) == 2:
k.append(L[i])
k = list(set(k))
k.sort(reverse=True)
e = 0
for i in k:
for j in range(n//2):
for je in range(j+1,n//2):
if L[j]%i == 0 and L[je]%i == 0:
#print(i)
a = L[j]
b = L[je]
e+=1
break
if e == 1:
break
if e == 1:
break
print(a,b)
``` | instruction | 0 | 70,790 | 22 | 141,580 |
No | output | 1 | 70,790 | 22 | 141,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
n1 = a[-1]
n2 = 0
if n1 == a[-2]:
n1 = n2
else:
l = Counter(a)
for i in range(n-1,-1,-1):
if n1%a[i] == 0:
if a[i]*a[i] != n1 and l[a[i]] > 1:
n2 = a[i]
break
else:
if l[a[i]]>2:
n2 = a[i]
break
else:
n2 = a[i]
break
print(n2,n1)
``` | instruction | 0 | 70,791 | 22 | 141,582 |
No | output | 1 | 70,791 | 22 | 141,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list.
For example, if x=4 and y=6 then the given list can be any permutation of the list [1, 2, 4, 1, 2, 3, 6]. Some of the possible lists are: [1, 1, 2, 4, 6, 3, 2], [4, 6, 1, 1, 2, 3, 2] or [1, 6, 3, 2, 4, 1, 2].
Your problem is to restore suitable positive integer numbers x and y that would yield the same list of divisors (possibly in different order).
It is guaranteed that the answer exists, i.e. the given list of divisors corresponds to some positive integers x and y.
Input
The first line contains one integer n (2 β€ n β€ 128) β the number of divisors of x and y.
The second line of the input contains n integers d_1, d_2, ..., d_n (1 β€ d_i β€ 10^4), where d_i is either divisor of x or divisor of y. If a number is divisor of both numbers x and y then there are two copies of this number in the list.
Output
Print two positive integer numbers x and y β such numbers that merged list of their divisors is the permutation of the given list of integers. It is guaranteed that the answer exists.
Example
Input
10
10 2 8 1 2 4 1 20 4 5
Output
20 8
Submitted Solution:
```
def mi():
return map(int, input().split(' '))
n = int(input())
li = list(mi())
li.sort()
a = li[-1]
b = -1
s = list(set(li))
for i in s:
if a%i != 0:
b = max(b,i)
if a == li[-2]:
print(a,a)
else:
print(a,b)
``` | instruction | 0 | 70,792 | 22 | 141,584 |
No | output | 1 | 70,792 | 22 | 141,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,664 | 22 | 143,328 |
Tags: greedy, implementation, math
Correct Solution:
```
def divisible(n):
if n[0]*2 <= n[1]:
return [n[0], n[0]*2]
tc = int(input())
for i in range(tc):
n = list(map(int, input().split()))
print(*divisible(n))
``` | output | 1 | 71,664 | 22 | 143,329 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,665 | 22 | 143,330 |
Tags: greedy, implementation, math
Correct Solution:
```
t = int(input())
for i in range(0,t):
l, r = [int(x) for x in input().split()]
print(l,2*l)
``` | output | 1 | 71,665 | 22 | 143,331 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,666 | 22 | 143,332 |
Tags: greedy, implementation, math
Correct Solution:
```
for _ in range(int(input())):
l, _ = map(int, input().split())
print(l, 2*l)
``` | output | 1 | 71,666 | 22 | 143,333 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,667 | 22 | 143,334 |
Tags: greedy, implementation, math
Correct Solution:
```
from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353
def inp(): return stdin.readline().strip()
def out(var, end="\n"): stdout.write(str(var)+"\n")
def outa(*var, end="\n"): stdout.write(' '.join(map(str, var)) + end)
def lmp(): return list(mp())
def mp(): return map(int, inp().split())
def smp(): return map(str, inp().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
def remadd(x, y): return 1 if x%y else 0
def ceil(a,b): return (a+b-1)//b
def isprime(x):
if x<=1: return False
if x in (2, 3): return True
if x%2 == 0: return False
for i in range(3, int(sqrt(x))+1, 2):
if x%i == 0: return False
return True
for _ in range(int(inp())):
l, r = mp()
print(l, 2*l)
``` | output | 1 | 71,667 | 22 | 143,335 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,668 | 22 | 143,336 |
Tags: greedy, implementation, math
Correct Solution:
```
n=int(input())
for i in range(n):
q,w=map(int, input().split())
print(q, q*2)
``` | output | 1 | 71,668 | 22 | 143,337 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,669 | 22 | 143,338 |
Tags: greedy, implementation, math
Correct Solution:
```
x = eval(input())
z=0
i =0
while (z<x):
l = list(map(int,input().split()))
print(l[0],(2*l[0]))
z+=1
``` | output | 1 | 71,669 | 22 | 143,339 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,670 | 22 | 143,340 |
Tags: greedy, implementation, math
Correct Solution:
```
t = int(input())
for i in range(t):
x, y = map(int, input().split())
print(x, x * 2)
``` | output | 1 | 71,670 | 22 | 143,341 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a range of positive integers from l to r.
Find such a pair of integers (x, y) that l β€ x, y β€ r, x β y and x divides y.
If there are multiple answers, print any of them.
You are also asked to answer T independent queries.
Input
The first line contains a single integer T (1 β€ T β€ 1000) β the number of queries.
Each of the next T lines contains two integers l and r (1 β€ l β€ r β€ 998244353) β inclusive borders of the range.
It is guaranteed that testset only includes queries, which have at least one suitable pair.
Output
Print T lines, each line should contain the answer β two integers x and y such that l β€ x, y β€ r, x β y and x divides y. The answer in the i-th line should correspond to the i-th query from the input.
If there are multiple answers, print any of them.
Example
Input
3
1 10
3 14
1 10
Output
1 7
3 9
5 10 | instruction | 0 | 71,671 | 22 | 143,342 |
Tags: greedy, implementation, math
Correct Solution:
```
for _ in range(int(input() ) ):
l, r = map(int, input().split() )
print(l, l*2)
``` | output | 1 | 71,671 | 22 | 143,343 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l β€ a β€ b β€ r). Your task is to find the maximum value among all considered ones.
Expression <image> means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal β as "xor".
Input
The single line contains space-separated integers l and r (1 β€ l β€ r β€ 1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
In a single line print a single integer β the maximum value of <image> for all pairs of integers a, b (l β€ a β€ b β€ r).
Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0 | instruction | 0 | 71,951 | 22 | 143,902 |
Tags: bitmasks, dp, greedy, implementation, math
Correct Solution:
```
a,b=map(int,input().split())
b1=bin(b)[2:]
a1=bin(a)[2:]
if len(a1)==len(b1) :
d=(b^a)
v=d.bit_length()
print(int("0"+"1"*(v),2))
else :
print(int("1"*len(b1),2))
#fdsfsdf
``` | output | 1 | 71,951 | 22 | 143,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l β€ a β€ b β€ r). Your task is to find the maximum value among all considered ones.
Expression <image> means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal β as "xor".
Input
The single line contains space-separated integers l and r (1 β€ l β€ r β€ 1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
In a single line print a single integer β the maximum value of <image> for all pairs of integers a, b (l β€ a β€ b β€ r).
Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0 | instruction | 0 | 71,953 | 22 | 143,906 |
Tags: bitmasks, dp, greedy, implementation, math
Correct Solution:
```
l, r = map(int, input().split())
print(0 if l == r else 2 ** len(bin(l ^ r)[2:]) - 1)
``` | output | 1 | 71,953 | 22 | 143,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l β€ a β€ b β€ r). Your task is to find the maximum value among all considered ones.
Expression <image> means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal β as "xor".
Input
The single line contains space-separated integers l and r (1 β€ l β€ r β€ 1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
In a single line print a single integer β the maximum value of <image> for all pairs of integers a, b (l β€ a β€ b β€ r).
Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0 | instruction | 0 | 71,955 | 22 | 143,910 |
Tags: bitmasks, dp, greedy, implementation, math
Correct Solution:
```
import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque
# from types import GeneratorType
# def bootstrap(func, stack=[]):
# def wrapped_function(*args, **kwargs):
# if stack:
# return func(*args, **kwargs)
# else:
# call = func(*args, **kwargs)
# while True:
# if type(call) is GeneratorType:
# stack.append(call)
# call = next(call)
# else:
# stack.pop()
# if not stack:
# break
# call = stack[-1].send(call)
# return call
# return wrapped_function
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8
N = 5*10**6
def solve(n):
arr = []
while n> 0:
arr.append(n%2)
n=n//2
return arr
l,r = Ri()
arrl = solve(l)
arrr = solve(r)
if len(arrr) > len(arrl):
ans = (1<<len(arrr))-1
print(ans)
else:
ind = -1
for i in range(len(arrr)-1,-1,-1):
if arrr[i] != arrl[i]:
ind = i
break
if ind == -1:
print(0)
else:
ans = (1 << (ind+1)) -1
print(ans)
``` | output | 1 | 71,955 | 22 | 143,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l β€ a β€ b β€ r). Your task is to find the maximum value among all considered ones.
Expression <image> means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal β as "xor".
Input
The single line contains space-separated integers l and r (1 β€ l β€ r β€ 1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
In a single line print a single integer β the maximum value of <image> for all pairs of integers a, b (l β€ a β€ b β€ r).
Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0 | instruction | 0 | 71,956 | 22 | 143,912 |
Tags: bitmasks, dp, greedy, implementation, math
Correct Solution:
```
l,r=map(int,input().split())
for i in range(61)[::-1]:
if (l>>i)&1!=(r>>i)&1:
print((1<<(i+1))-1)
exit()
print(0)
``` | output | 1 | 71,956 | 22 | 143,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l β€ a β€ b β€ r). Your task is to find the maximum value among all considered ones.
Expression <image> means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal β as "xor".
Input
The single line contains space-separated integers l and r (1 β€ l β€ r β€ 1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Output
In a single line print a single integer β the maximum value of <image> for all pairs of integers a, b (l β€ a β€ b β€ r).
Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0 | instruction | 0 | 71,958 | 22 | 143,916 |
Tags: bitmasks, dp, greedy, implementation, math
Correct Solution:
```
l,r=map(int,(input().split()))
for i in range(64,-2,-1):
if(i<0 or ((1<<i)&l)!=((1<<i)&r)): break
print((1<<(i+1))-1)
``` | output | 1 | 71,958 | 22 | 143,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,689 | 22 | 145,378 |
Tags: math
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
a=n
if n==1:
print(0)
else:
pow2=0
pow3=0
while(n%2==0 or n%3==0):
if n%3==0:
n/=3
pow3+=1
if n%2==0:
n/=2
pow2+=1
if n!=1:
print(-1)
else:
if pow3<pow2:
print(-1)
elif pow3==pow2:
print(pow3)
else:
#a*=2**(pow3-pow2)
print(2*pow3-pow2)
``` | output | 1 | 72,689 | 22 | 145,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,690 | 22 | 145,380 |
Tags: math
Correct Solution:
```
from math import *
t=int(input())
for _ in range(t):
n=int(input())
k=0
flag=0
while(True):
if(n==1):
break
if(gcd(n,3)!=3):
flag=1
break
if(n%6==0):
n=n//6
k+=1
else:
n=n*2
k+=1
if(flag):
print(-1)
else:
print(k)
``` | output | 1 | 72,690 | 22 | 145,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,691 | 22 | 145,382 |
Tags: math
Correct Solution:
```
def func(n):
for i in range(n):
x = int(input())
counter = 0
for i in range(1,50):
if x == 1:
break
if x % 6 == 0:
x //= 6
counter += 1
else:
x *= 2
counter += 1
if i == counter:
print(-1)
else:
print(counter)
n = int(input())
func(n)
``` | output | 1 | 72,691 | 22 | 145,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,692 | 22 | 145,384 |
Tags: math
Correct Solution:
```
def r(x):
i=0
j=0
while x%3==0:
x=x/3
i=i+1
while x%2==0:
x=x/2
j=j+1
if x==1:
return [j,i]
else:
return 0
for i in range(int(input())):
n=int(input())
if r(n)==0:
print(-1)
else:
l=r(n)
if l[0]>l[1]:
print(-1)
else:
print(2*l[1]-l[0])
#print(r(3))
``` | output | 1 | 72,692 | 22 | 145,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,693 | 22 | 145,386 |
Tags: math
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
c2 = 0
c3 = 0
while n%2 == 0:
c2 += 1
n //= 2
while n%3 == 0:
c3 += 1
n //= 3
#print(n, c2, c3)
if n != 1:
print(-1)
else:
if c2 > c3:
print(-1)
else:
ans= c3+(c3-c2)
print(ans)
``` | output | 1 | 72,693 | 22 | 145,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,694 | 22 | 145,388 |
Tags: math
Correct Solution:
```
z=int(input())
for h in range(z):
n=int(input())
cnt=0
while True:
if n<=6:
if n==3:
cnt+=2
n=1
if n==6:
cnt+=1
n=1
break
else:
if n%6==0:
n=n//6
cnt+=1
elif (n*2)%6==0:
n=(n*2)//6
cnt+=2
else:
break
if n==1:
print(cnt)
else:
print(-1)
``` | output | 1 | 72,694 | 22 | 145,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,695 | 22 | 145,390 |
Tags: math
Correct Solution:
```
def f(val):
powers_of_two, powers_of_three = 0, 0
while val % 2 == 0:
val = val // 2
powers_of_two += 1
while val % 3 == 0:
val = val // 3
powers_of_three += 1
if val > 1 or powers_of_two > powers_of_three:
return -1
return powers_of_three + (powers_of_three - powers_of_two)
n = int(input())
for _ in range(n):
val = int(input())
print(f(val))
``` | output | 1 | 72,695 | 22 | 145,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | instruction | 0 | 72,696 | 22 | 145,392 |
Tags: math
Correct Solution:
```
t = int(input())
for i in range(t):
x = int(input())
c = 0
while x!=1:
if x%6 !=0:
if x%3 !=0:
print(-1)
break
else:
c+=1
x*=2
else:
c+=1
x/=6
else:
print(c)
``` | output | 1 | 72,696 | 22 | 145,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
for i in range(int(input())):
x=int(input())
cnt2=0
cnt3=0
while(x%2==0):
cnt2+=1
x/=2
while(x%3==0):
cnt3+=1
x/=3
if x>1 or cnt2>cnt3:
print(-1)
else:
print(cnt3+cnt3-cnt2)
``` | instruction | 0 | 72,697 | 22 | 145,394 |
Yes | output | 1 | 72,697 | 22 | 145,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
def one_get_not_get(arr):
for i in range(len(arr)):
j = 0
count = 0
count1 = 0
value = arr[i]
while(j < value*6):
if arr[i] % 6 == 0:
arr[i] = int(arr[i]/6)
count += 1
count1 -= 1
elif (arr[i] - 6) == 2:
print(-1)
break
elif count1 > 6:
print(-1)
break
elif arr[i] == 1:
print(count)
break
else:
arr[i] = arr[i]*2
count += 1
count1 += 1
j += 1
if __name__ == '__main__':
t = int(input())
arr = []
for i in range(t):
n = int(input())
arr.append(n)
one_get_not_get(arr)
``` | instruction | 0 | 72,698 | 22 | 145,396 |
Yes | output | 1 | 72,698 | 22 | 145,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
T = int(input())
dic = {}
def is_2power(K):
if K == 2:
return True
temp = 2
while(True):
temp *= 2
if temp == K:
return True
if temp > K:
return False
def Fun(num, moves, Mult):
if num in dic:
return dic[num]
temp = num
while(True):
# print(None)
if Mult > 10:
dic[num] = -1
return -1
if temp == 1:
dic[num] = moves
return moves
if temp == 0 or is_2power(temp):
dic[num] = -1
return -1
# print(num)
if (temp % 6) == 0:
temp /= 6
Mult = 0
moves += 1
else:
temp *= 2
Mult += 1
moves += 1
for i in range(T):
n = int(input())
print(Fun(n, 0, 0))
# print(dic)
``` | instruction | 0 | 72,700 | 22 | 145,400 |
Yes | output | 1 | 72,700 | 22 | 145,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
count=0
flag=0
if n==1:
print(0)
if n==2 or n==4 or n==5:
print(-1)
if n==6:
print(1)
if n==3:
print(2)
if n>6:
j=0
k=0
while n%3==0:
n=n/3
j+=1
while n%2==0:
n=n/2
k+=1
if j==0:
print(-1)
if j>=k:
print(2*j-k)
elif j<k:
print(-1)
``` | instruction | 0 | 72,701 | 22 | 145,402 |
No | output | 1 | 72,701 | 22 | 145,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
#rOkY
#FuCk
################################## kOpAl #######################################
def ans(a):
count=0
k=0
while(a!=1):
if(a%6==0):
a=a//6
count+=1
else:
a=a*2
count+=1
if(a%6!=0 or a==1):
break
if(a==1):
k=1
break
if(k==1):
print(count)
else:
print(-1)
t=int(input())
while(t>0):
a=int(input())
if(a%10==5 or a%10==7 or a%10==8 or a%10==4 or a%10==2):
print(-1)
elif(a==1):
print(0)
elif(a==2):
print(-1)
else:
ans(a)
t-=1
``` | instruction | 0 | 72,702 | 22 | 145,404 |
No | output | 1 | 72,702 | 22 | 145,405 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
if n==1:
print(1)
elif n%3!=0:
print(-1)
else:
b=0
while n%3==0:
n=n/3
b+=1
if n==1:
print(2*b)
else:
if n%2!=0:
print(-1)
else:
a=0
while n%2==0:
n=n/2
a+=1
if a<b:
print(2*b-a)
else:
print(-1)
``` | instruction | 0 | 72,703 | 22 | 145,406 |
No | output | 1 | 72,703 | 22 | 145,407 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1.
Submitted Solution:
```
n = int(input())
while n:
targ = int(input())
if targ%3:
print(-1)
else:
i=0
while targ%3==0:
targ/=6
i+=1
if targ!=1:
print(-1)
else:
print(i)
n-=1
``` | instruction | 0 | 72,704 | 22 | 145,408 |
No | output | 1 | 72,704 | 22 | 145,409 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = β_{k | n} k.
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
For a given number c, find the minimum n such that d(n) = c.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer c (1 β€ c β€ 10^7).
Output
For each test case, output:
* "-1" if there is no such n that d(n) = c;
* n, otherwise.
Example
Input
12
1
2
3
4
5
6
7
8
9
10
39
691
Output
1
-1
2
3
-1
5
4
7
-1
-1
18
-1
Submitted Solution:
```
import math
import sys
input=sys.stdin.readline
N = 10**7
M = int(math.sqrt(N))
sieve = [0 for i in range(N+1)]
table_d = [-1 for i in range(N+1)]
map_c_to_n={}
table_d[1]= 1
map_c_to_n[1]=1
## sieve[i] is the smallest prime dividing i>=2
## table_d[i] is the sum of divisors of i
for p in range(2, M+1):
if sieve[p]==0: ## p is prime
sieve[p]=p
table_d[p]=p+1
map_c_to_n[p+1]=p
for i in range(p*p, (N+1),p):
sieve[i]=p
for i in range(2, M+1):
if sieve[i]!=i: ## i is not prime
p=sieve[i]
copy_i=i
d_p=1 ## sum of divisors of : p to its multiplicity in i
while copy_i%p==0:
copy_i //= p
d_p = 1 + p*d_p
d_i = d_p * table_d[copy_i]
table_d[i]= d_i
if d_i not in map_c_to_n:
map_c_to_n[d_i]=i
t = int(input())
for _ in range(t):
c = int(input())
ans =''
if c in map_c_to_n:
ans = str(map_c_to_n[c])
else:
ans = '-1'
sys.stdout.write(ans+'\n')
``` | instruction | 0 | 72,773 | 22 | 145,546 |
No | output | 1 | 72,773 | 22 | 145,547 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = β_{k | n} k.
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
For a given number c, find the minimum n such that d(n) = c.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer c (1 β€ c β€ 10^7).
Output
For each test case, output:
* "-1" if there is no such n that d(n) = c;
* n, otherwise.
Example
Input
12
1
2
3
4
5
6
7
8
9
10
39
691
Output
1
-1
2
3
-1
5
4
7
-1
-1
18
-1
Submitted Solution:
```
mydict = {}
for i in range(10**4, 0, -1):
result = 0
j = 1
while True:
if i % j == 0:
result += j
if j * j != i:
result += i // j
j += 1
if j * j > i :
break
mydict[result] = i
t = int(input())
for test_case in range(t):
c = int(input())
res = -1
if c in mydict:
res = mydict[c]
print()
print(res)
print()
``` | instruction | 0 | 72,774 | 22 | 145,548 |
No | output | 1 | 72,774 | 22 | 145,549 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = β_{k | n} k.
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
For a given number c, find the minimum n such that d(n) = c.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer c (1 β€ c β€ 10^7).
Output
For each test case, output:
* "-1" if there is no such n that d(n) = c;
* n, otherwise.
Example
Input
12
1
2
3
4
5
6
7
8
9
10
39
691
Output
1
-1
2
3
-1
5
4
7
-1
-1
18
-1
Submitted Solution:
```
import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
self.BUFSIZE = 8192
def read(self):
while True:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
self.os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def get_int():
return int(input())
def get_ints():
return list(map(int, input().split(' ')))
def get_int_grid(n):
return [get_ints() for _ in range(n)]
def get_str():
return input().strip()
def get_strs():
return get_str().split(' ')
def flat_list(arr):
return [item for subarr in arr for item in subarr]
def yes_no(b):
if b:
return "YES"
else:
return "NO"
def binary_search(good, left, right, delta=1, right_true=False):
"""
Performs binary search
----------
Parameters
----------
:param good: Function used to perform the binary search
:param left: Starting value of left limit
:param right: Starting value of the right limit
:param delta: Margin of error, defaults value of 1 for integer binary search
:param right_true: Boolean, for whether the right limit is the true invariant
:return: Returns the most extremal value interval [left, right] which is good function evaluates to True,
alternatively returns False if no such value found
"""
limits = [left, right]
while limits[1] - limits[0] > delta:
if delta == 1:
mid = sum(limits) // 2
else:
mid = sum(limits) / 2
if good(mid):
limits[int(right_true)] = mid
else:
limits[int(~right_true)] = mid
if good(limits[int(right_true)]):
return limits[int(right_true)]
else:
return False
def prefix_sums(a):
p = [0]
for x in a:
p.append(p[-1] + x)
return p
def solve_a():
n = get_int()
x = get_ints()
x_enum = [(v, i) for i, v in enumerate(x)]
x_enum.sort()
if x_enum[0][0] != x_enum[1][0]:
return x_enum[0][1] + 1
else:
return x_enum[-1][1] + 1
def solve_b():
n = get_int()
grid = [list(get_str()) for row in range(n)]
points = []
for i in range(n):
for j in range(n):
if grid[i][j] == '*':
points.append((i, j))
a, b = points
if a[0] != b[0] and a[1] != b[1]:
grid[a[0]][b[1]] = '*'
grid[b[0]][a[1]] = '*'
elif a[0] == b[0]:
new = (a[0] + 1) % n
grid[new][a[1]] = '*'
grid[new][b[1]] = '*'
elif a[1] == b[1]:
new = (a[1] + 1) % n
grid[a[0]][new] = '*'
grid[b[0]][new] = '*'
for row in grid:
print(''.join(row))
return
def solve_c():
a, b = get_ints()
s = list(get_str())
a -= s.count('0')
b -= s.count('1')
n = len(s)
for i in range(n):
if s[i] == '1' and s[n - i - 1] == '?':
s[n - i - 1] = '1'
b -= 1
if s[i] == '0' and s[n - i - 1] == '?':
s[n - i - 1] = '0'
a -= 1
for i in range(n):
if i != n - i - 1 and s[i] == s[n - i - 1] == '?':
if a > 1:
s[n - i - 1] = '0'
s[i] = '0'
a -= 2
elif b > 1:
s[n - i - 1] = '1'
s[i] = '1'
b -= 2
else:
return -1
if s[n // 2] == '?':
if a > 0:
s[n // 2] = '0'
a -= 1
elif b > 0:
s[n // 2] = '1'
b -= 1
else:
return -1
for i in range(n):
if s[i] != s[n - i - 1]:
return -1
if (a != 0) or (b != 0):
return -1
else:
return ''.join(s)
def solve_d():
n = get_int()
b = get_ints()
b_set = {}
b.sort()
S = sum(b)
# Random number is biggest
if S - b[-1] - b[-2] == b[-2]:
return b[:-2]
# Random number is second biggest
if S - b[-1] - b[-2] == b[-1]:
return b[:-2]
else:
for i in range(n):
# Random number is ith smallest i={1,...,n}
if S - b[i] - b[-1] == b[-1]:
return b[:i] + b[i+1:n+1]
return [-1]
def solve_e():
n, l, r, s = get_ints()
def linear_sieve(n):
'''
Calculates all the primes in {1,...,n} and the least prime factor for all integers {1,...,n}.
Time complexity: O(n)
Memory complexity: O(n)
:param n: highest integer to consider
:return: tuple:
first element = array of primes;
second element = array of least prime factors.
'''
# Initiate arrays for primes and least prime divisors
primes = []
least_prime_divs = [0] * (n + 1)
# Iterate over all numbers in thr range, starting at 2
for i in range(2, n + 1):
# Any number which has not already been assigned a least prime divisor is a prime
if not least_prime_divs[i]:
least_prime_divs[i] = i
primes.append(i)
# Iterate over current (ordered) prime array
for p in primes:
# End iteration if we out of the range or the prime exceeds the LPD of current number
if i * p > n or p > least_prime_divs[i]:
break
# Each number can only be assigned once, giving linear time complexity
least_prime_divs[i * p] = p
# Return prime array and array of least prime divisors
return primes, least_prime_divs
def preprocess_g(n_max):
cnt = [0] * (n_max + 1)
ans = [-1] * (n_max + 1)
for i in range(1, n_max + 1):
j = i
while j < n_max + 1:
cnt[j] += i
j += i
if cnt[i] < n_max and ans[cnt[i]] == -1:
ans[cnt[i]] = i
return ans
def solve_g():
n = get_int()
return d[n]
t = get_int()
d = preprocess_g(10 ** 7)
ans = []
for _ in range(t):
ans.append(solve_g())
print(*ans)
``` | instruction | 0 | 72,775 | 22 | 145,550 |
No | output | 1 | 72,775 | 22 | 145,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us denote by d(n) the sum of all divisors of the number n, i.e. d(n) = β_{k | n} k.
For example, d(1) = 1, d(4) = 1+2+4=7, d(6) = 1+2+3+6=12.
For a given number c, find the minimum n such that d(n) = c.
Input
The first line contains one integer t (1 β€ t β€ 10^4). Then t test cases follow.
Each test case is characterized by one integer c (1 β€ c β€ 10^7).
Output
For each test case, output:
* "-1" if there is no such n that d(n) = c;
* n, otherwise.
Example
Input
12
1
2
3
4
5
6
7
8
9
10
39
691
Output
1
-1
2
3
-1
5
4
7
-1
-1
18
-1
Submitted Solution:
```
def sum_div(number):
divisors = [1]
for i in range(2, number):
if (number % i)==0:
divisors.append(i)
return sum(divisors)
t=int(input("enter"))
for i in range(t):
n=int(input())
print(sum_div(n))
``` | instruction | 0 | 72,776 | 22 | 145,552 |
No | output | 1 | 72,776 | 22 | 145,553 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,787 | 22 | 145,574 |
Tags: number theory
Correct Solution:
```
def gcd(a, b):
while a:
b %= a
a, b = b, a
return b
def lcm(a, b):
return a // gcd(a, b) * b
n = int(input())
ans = 0
for i in range(n, max(0, n - 100), -1):
for j in range(i, max(0, i - 100), -1):
cur = lcm(i, j)
for k in range(j, max(0, j - 100), -1):
ans = max(ans, lcm(cur, k))
print(ans)
``` | output | 1 | 72,787 | 22 | 145,575 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,788 | 22 | 145,576 |
Tags: number theory
Correct Solution:
```
from math import factorial, gcd
import itertools
n = int(input())
if n <= 3:
print(factorial(n))
exit()
ans = 0
for a, b, c in itertools.product(range(max(n - 50, 1), n + 1), range(max(n - 50, 1), n + 1), range(max(n - 50, 1), n + 1)):
x = a * b // gcd(a, b)
x = x * c // gcd(x, c)
ans = max(x, ans)
print(ans)
``` | output | 1 | 72,788 | 22 | 145,577 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,789 | 22 | 145,578 |
Tags: number theory
Correct Solution:
```
import math
n = int(input())
if(n<=2):
print(n)
exit()
if(n%2!=0):
print(n*(n-1)*(n-2))
else:
l = max((n-1)*(n-2)*(n-3),(n*(n-2)*(n-1))//math.gcd(n,(n-2)))
print(max(l,(n*(n-3)*(n-1))//math.gcd(n,n-3)))
``` | output | 1 | 72,789 | 22 | 145,579 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,790 | 22 | 145,580 |
Tags: number theory
Correct Solution:
```
'''''
arr= [1,3,4,3]
i=0
for k in range(8):
if i!=arr[i]-1:
if arr[i]!=arr[arr[i]-1]:
print(arr[i],arr[arr[i]-1],arr,i)
arr[i],arr[arr[i]-1]=arr[arr[i]-1],arr[i]
else:
i+=1
else:
i+=1
print(arr)
'''''
'''
def AllParenthesis(n):
def backtrack(ans,curr,openp,closep,maxp):
if len(curr)==2*maxp:
ans.append(curr)
return
if openp<maxp:
backtrack(ans,curr+"(",openp+1,closep,maxp)
if closep<openp:
backtrack(ans,curr+")",openp,closep+1,maxp)
ans = []
openp, closep = 0, 0
curr = ''
backtrack(ans, curr, openp, closep, n)
return ans
print(AllParenthesis(3))
'''
#mat = [[1,2,3],[4,5,6],[7,8,9]]
'''temp=[[0 for x in range(len(mat[0]))]for x in range(len(mat))]
for i in range(len(mat)):
temp[i][0]=mat[i][0]
for j in range(1,len(mat[0])):
temp[i][j]=temp[i][j-1]+mat[i][j]
for i in range(1,len(mat)):
for j in range(len(mat[0])):
temp[i][j]=temp[i-1][j]+temp[i][j]
k=3
lr=0
lc=0
rr=0
rc=0
ans=[[0 for x in range(len(mat[0]))]for x in range(len(mat))]
for i in range(len(mat)):
for j in range(len(mat[0])):
area1 = 0
area2 = 0
area3 = 0
lr=i
lc=j
if i-k>=0:
lr=i-k
else:
lr=0
if j-k>=0:
lc=j-k
else:
lc=0
rr=i
rc=j
if i+k<len(mat):
rr=i+k
else:
rr=len(mat)-1
if j+k<len(mat[0]):
rc=j+k
else:
rc=len(mat[0])-1
if lc-1>=0:
area1=temp[rr][lc-1]
if lr-1>=0:
area2=temp[lr-1][rc]
if lr-1>=0 and lc-1>=0:
area3=temp[lr-1][lc-1]
ans[i][j]=temp[rr][rc]-area1-area2+area3'''
'''print(ans)'''
'''
nums = [-1,0,1,2,-1,-4] #-1,0,1,2,-1,-4,-2,-3,3,0,4
nums.sort()
print(nums)
seen = set()
length=len(nums)
ans=[]
i=0
while i<length-2:
l=i+1
r=length-1
target=nums[i]
while l<r:
if nums[l]+nums[r]==-target:
seen.add((target,nums[l],nums[r]))
while l < r and nums[l + 1] == nums[l]:
l += 1
while l < r and nums[r - 1] == nums[r]:
r -= 1
l+=1
r-=1
elif nums[l]+nums[r]>-target:
r-=1
else:
l+=1
i+=1
print(seen)
'''
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
import math
def check(n):
''' check = [1] * (n + 1)
check[0] = 0
check[1] = 0
for i in range(2, int(math.sqrt(n)) + 1):
if check[i] == 1:
for j in range(i * i, n + 1, i):
if check[j] == 1:
check[j] = 0
def lcm(num1, num2):
gcd1 = math.gcd(num1, num2)
lcmf = (num1 * num2) // gcd1
return lcmf'''
if n==1:
return 1
if n==2:
return 2
if n==3:
return 6
# ans = 0
if n&1:
return ((n-1)*(n-2)*(n))
if math.gcd(n,n-3)==1:
return (n*(n-1)*(n-3))
else:
return ((n-1)*(n-2)*(n-3))
''' k = j - 1
for k in range(n-2, n-10, -1):
lcm2 = lcm((n*(n-1)), k)
if check[k]:
return(lcm1*k)
'''
n =int(input())
print(check(n))
``` | output | 1 | 72,790 | 22 | 145,581 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,791 | 22 | 145,582 |
Tags: number theory
Correct Solution:
```
n = int(input())
if n < 3:
print(n)
elif n%2 == 1: # odd
print(n*(n-1)*(n-2))
elif n%3 == 0: # even and multiple of 3
print((n-1)*(n-2)*(n-3))
else:
print(n*(n-1)*(n-3))
``` | output | 1 | 72,791 | 22 | 145,583 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,792 | 22 | 145,584 |
Tags: number theory
Correct Solution:
```
a=int(input())
while True:
if a==1:
print(1)
break
elif a==2:
print(2)
break
elif a==3:
print(6)
break
elif a==4:
print(12)
break
elif a%2!=0:
print(a*(a-1)*(a-2))
break
elif a%3!=0:
print(a*(a-1)*(a-3))
break
a-=1
``` | output | 1 | 72,792 | 22 | 145,585 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,793 | 22 | 145,586 |
Tags: number theory
Correct Solution:
```
import math
def LCM(a,b):
res=int((a*b)/math.gcd(a,b))
return res
a=int(input())
ans=0
if(a==1):
ans=1
elif(a==2):
ans=2
elif(a%2==0):
b1=(a-1)*(a-2)*(a-3)
b2=a*(a-1)*(a-3)
if(math.gcd(a,a-3)>math.gcd(a,a-2)):
ans=b1
else:
ans=b2
elif(a%2==1):
ans=a*(a-1)*(a-2)
print(ans)
``` | output | 1 | 72,793 | 22 | 145,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get. | instruction | 0 | 72,794 | 22 | 145,588 |
Tags: number theory
Correct Solution:
```
# Target - Expert on CF
# Be Humblefool
import sys
# inf = float("inf")
# sys.setrecursionlimit(10000000)
# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod, MOD = 1000000007, 998244353
# words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'}
# vow=['a','e','i','o','u']
# dx,dy=[0,1,0,-1],[1,0,-1,0]
# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
# from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
def gcd(a,b):
if a==0:
return b
else:
return gcd(b%a,a)
def lcm(a,b):
return (a*b)//gcd(a,b)
n = int(input())
if n==1 or n==2:
print(n)
exit()
if n&1:
print(lcm(lcm(n,n-1),(n-2)))
else:
print(max( lcm(lcm(n-1,n-2),(n-3)), lcm((n-3),lcm(n,n-1))))
``` | output | 1 | 72,794 | 22 | 145,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get.
Submitted Solution:
```
n=int(input())
a={1:1,2:2,3:6,4:12,5:60,6:60}
if n in a:
print(a[n])
else:
if n%2!=0:
print(n*(n-1)*(n-2))
else:
if n%3!=0:
print(n * (n - 1) * (n - 3))
else:
print((n-3) * (n - 1) * (n - 2))
``` | instruction | 0 | 72,795 | 22 | 145,590 |
Yes | output | 1 | 72,795 | 22 | 145,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?
Input
The first line contains an integer n (1 β€ n β€ 106) β the n mentioned in the statement.
Output
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.
Examples
Input
9
Output
504
Input
7
Output
210
Note
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7Β·6Β·5 = 210. It is the maximum value we can get.
Submitted Solution:
```
import math
def lcm(x,y):
return x*(y//math.gcd(x,y))
n = int(input())
if n < 3: print(n)
elif n == 3: print(6)
else:
if n % 2 == 1: print(n*(n - 1)*(n - 2))
else:
ans = 0
for i in range(max(n - 50,1),n - 1):
for j in range(i + 1,n):
for k in range(j + 1,n + 1):
ans = max(ans, lcm(i,lcm(j,k)))
print(ans)
``` | instruction | 0 | 72,796 | 22 | 145,592 |
Yes | output | 1 | 72,796 | 22 | 145,593 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.