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
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7). The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1. Input The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum. Output Print integer s — the value of the required sum modulo 109 + 7. Examples Input 3 4 Output 4 Input 4 4 Output 1 Input 1 1 Output 0
instruction
0
23,332
22
46,664
Tags: implementation, math, number theory Correct Solution: ``` import math MOD = int( 1e9 + 7 ) N, M = map( int, input().split() ) sn = int( math.sqrt( N ) ) ans = N * M % MOD for i in range( 1, min( sn, M ) + 1, 1 ): ans -= N // i * i ans %= MOD if N // ( sn + 1 ) > M: exit( print( ans ) ) def s( x ): return x * ( x + 1 ) // 2 for f in range( N // ( sn + 1 ), 0, -1 ): # s = lambda x: x * ( x + 1 ) // 2 if N // f > M: ans -= f * ( s( M ) - s( N // ( f + 1 ) ) ) break ans -= f * ( s( N // f ) - s( N // ( f + 1 ) ) ) ans %= MOD if ans < 0: ans += MOD print( ans ) ```
output
1
23,332
22
46,665
Provide tags and a correct Python 3 solution for this coding contest problem. Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7). The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1. Input The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum. Output Print integer s — the value of the required sum modulo 109 + 7. Examples Input 3 4 Output 4 Input 4 4 Output 1 Input 1 1 Output 0
instruction
0
23,333
22
46,666
Tags: implementation, math, number theory Correct Solution: ``` from math import sqrt n, m = map(int, input().split()) t = min(int(sqrt(n))+1, m) i = 2 mod = 10**9 + 7 ans = 0 while i <= t: ans += n % i i += 1 ans %= mod i = t + 1 while i <= min(n, m): d = n // i t = min(m, n // d) cnt = t - i + 1 x = (n % i) * cnt - d * (((cnt-1) * cnt) >> 1) ans = (ans + x) % mod i = t + 1 if i <= m: ans = (ans + n * (m-i+1)) % mod print(ans) ```
output
1
23,333
22
46,667
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai ≤ aj and there are exactly k integers y such that ai ≤ y ≤ aj and y is divisible by x. In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1). Input The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. Output Print one integer — the answer to the problem. Examples Input 4 2 1 1 3 5 7 Output 3 Input 4 2 0 5 3 1 7 Output 4 Input 5 3 1 3 3 3 3 3 Output 25 Note In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. Submitted Solution: ``` n, x, k = map(int, input().split()) array = list(map(int, input().split())) def next_x(n): return ((n+x-1)//x)*x valcount = {} for a in array: valcount[a] = valcount.get(a, 0) + 1 begs = {} pairs = 0 for val, count in sorted(valcount.items()): if k > 0 or val % x != 0: beg = next_x(val) begs[beg] = begs.get(beg, 0) + count from_ = next_x(val - k*x + 1) pairs += count*begs.get(from_, 0) print(pairs) ```
instruction
0
23,487
22
46,974
Yes
output
1
23,487
22
46,975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai ≤ aj and there are exactly k integers y such that ai ≤ y ≤ aj and y is divisible by x. In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1). Input The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. Output Print one integer — the answer to the problem. Examples Input 4 2 1 1 3 5 7 Output 3 Input 4 2 0 5 3 1 7 Output 4 Input 5 3 1 3 3 3 3 3 Output 25 Note In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. Submitted Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase 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") # -------------------game starts now----------------------------------------------------import math class TreeNode: def __init__(self, k, v): self.key = k self.value = v self.left = None self.right = None self.parent = None self.height = 1 self.num_left = 1 self.num_total = 1 class AvlTree: def __init__(self): self._tree = None def add(self, k, v): if not self._tree: self._tree = TreeNode(k, v) return node = self._add(k, v) if node: self._rebalance(node) def _add(self, k, v): node = self._tree while node: if k < node.key: if node.left: node = node.left else: node.left = TreeNode(k, v) node.left.parent = node return node.left elif node.key < k: if node.right: node = node.right else: node.right = TreeNode(k, v) node.right.parent = node return node.right else: node.value = v return @staticmethod def get_height(x): return x.height if x else 0 @staticmethod def get_num_total(x): return x.num_total if x else 0 def _rebalance(self, node): n = node while n: lh = self.get_height(n.left) rh = self.get_height(n.right) n.height = max(lh, rh) + 1 balance_factor = lh - rh n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right) n.num_left = 1 + self.get_num_total(n.left) if balance_factor > 1: if self.get_height(n.left.left) < self.get_height(n.left.right): self._rotate_left(n.left) self._rotate_right(n) elif balance_factor < -1: if self.get_height(n.right.right) < self.get_height(n.right.left): self._rotate_right(n.right) self._rotate_left(n) else: n = n.parent def _remove_one(self, node): """ Side effect!!! Changes node. Node should have exactly one child """ replacement = node.left or node.right if node.parent: if AvlTree._is_left(node): node.parent.left = replacement else: node.parent.right = replacement replacement.parent = node.parent node.parent = None else: self._tree = replacement replacement.parent = None node.left = None node.right = None node.parent = None self._rebalance(replacement) def _remove_leaf(self, node): if node.parent: if AvlTree._is_left(node): node.parent.left = None else: node.parent.right = None self._rebalance(node.parent) else: self._tree = None node.parent = None node.left = None node.right = None def remove(self, k): node = self._get_node(k) if not node: return if AvlTree._is_leaf(node): self._remove_leaf(node) return if node.left and node.right: nxt = AvlTree._get_next(node) node.key = nxt.key node.value = nxt.value if self._is_leaf(nxt): self._remove_leaf(nxt) else: self._remove_one(nxt) self._rebalance(node) else: self._remove_one(node) def get(self, k): node = self._get_node(k) return node.value if node else -1 def _get_node(self, k): if not self._tree: return None node = self._tree while node: if k < node.key: node = node.left elif node.key < k: node = node.right else: return node return None def get_at(self, pos): x = pos + 1 node = self._tree while node: if x < node.num_left: node = node.left elif node.num_left < x: x -= node.num_left node = node.right else: return (node.key, node.value) raise IndexError("Out of ranges") @staticmethod def _is_left(node): return node.parent.left and node.parent.left == node @staticmethod def _is_leaf(node): return node.left is None and node.right is None def _rotate_right(self, node): if not node.parent: self._tree = node.left node.left.parent = None elif AvlTree._is_left(node): node.parent.left = node.left node.left.parent = node.parent else: node.parent.right = node.left node.left.parent = node.parent bk = node.left.right node.left.right = node node.parent = node.left node.left = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) def _rotate_left(self, node): if not node.parent: self._tree = node.right node.right.parent = None elif AvlTree._is_left(node): node.parent.left = node.right node.right.parent = node.parent else: node.parent.right = node.right node.right.parent = node.parent bk = node.right.left node.right.left = node node.parent = node.right node.right = bk if bk: bk.parent = node node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1 node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right) node.num_left = 1 + self.get_num_total(node.left) @staticmethod def _get_next(node): if not node.right: return node.parent n = node.right while n.left: n = n.left return n avl=AvlTree() #-----------------------------------------------binary seacrh tree--------------------------------------- class SegmentTree1: def __init__(self, data, default='z', func=lambda a, b: min(a ,b)): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------game starts now----------------------------------------------------import math class SegmentTree: def __init__(self, data, default=0, func=lambda a, b: a * a + b * b): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 * _size) self.data[_size:_size + self._len] = data for i in reversed(range(_size)): self.data[i] = func(self.data[i + i], self.data[i + i + 1]) def __delitem__(self, idx): self[idx] = self._default def __getitem__(self, idx): return self.data[idx + self._size] def __setitem__(self, idx, value): idx += self._size self.data[idx] = value idx >>= 1 while idx: self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1]) idx >>= 1 def __len__(self): return self._len def query(self, start, stop): if start == stop: return self.__getitem__(start) stop += 1 start += self._size stop += self._size res = self._default while start < stop: if start & 1: res = self._func(res, self.data[start]) start += 1 if stop & 1: stop -= 1 res = self._func(res, self.data[stop]) start >>= 1 stop >>= 1 return res def __repr__(self): return "SegmentTree({0})".format(self.data) # -------------------------------iye ha chutiya zindegi------------------------------------- class Factorial: def __init__(self, MOD): self.MOD = MOD self.factorials = [1, 1] self.invModulos = [0, 1] self.invFactorial_ = [1, 1] def calc(self, n): if n <= -1: print("Invalid argument to calculate n!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.factorials): return self.factorials[n] nextArr = [0] * (n + 1 - len(self.factorials)) initialI = len(self.factorials) prev = self.factorials[-1] m = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = prev * i % m self.factorials += nextArr return self.factorials[n] def inv(self, n): if n <= -1: print("Invalid argument to calculate n^(-1)") print("n must be non-negative value. But the argument was " + str(n)) exit() p = self.MOD pi = n % p if pi < len(self.invModulos): return self.invModulos[pi] nextArr = [0] * (n + 1 - len(self.invModulos)) initialI = len(self.invModulos) for i in range(initialI, min(p, n + 1)): next = -self.invModulos[p % i] * (p // i) % p self.invModulos.append(next) return self.invModulos[pi] def invFactorial(self, n): if n <= -1: print("Invalid argument to calculate (n^(-1))!") print("n must be non-negative value. But the argument was " + str(n)) exit() if n < len(self.invFactorial_): return self.invFactorial_[n] self.inv(n) # To make sure already calculated n^-1 nextArr = [0] * (n + 1 - len(self.invFactorial_)) initialI = len(self.invFactorial_) prev = self.invFactorial_[-1] p = self.MOD for i in range(initialI, n + 1): prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p self.invFactorial_ += nextArr return self.invFactorial_[n] class Combination: def __init__(self, MOD): self.MOD = MOD self.factorial = Factorial(MOD) def ncr(self, n, k): if k < 0 or n < k: return 0 k = min(k, n - k) f = self.factorial return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD # --------------------------------------iye ha combinations ka zindegi--------------------------------- def powm(a, n, m): if a == 1 or n == 0: return 1 if n % 2 == 0: s = powm(a, n // 2, m) return s * s % m else: return a * powm(a, n - 1, m) % m # --------------------------------------iye ha power ka zindegi--------------------------------- def sort_list(list1, list2): zipped_pairs = zip(list2, list1) z = [x for _, x in sorted(zipped_pairs)] return z # --------------------------------------------------product---------------------------------------- def product(l): por = 1 for i in range(len(l)): por *= l[i] return por # --------------------------------------------------binary---------------------------------------- def binarySearchCount(arr, n, key): left = 0 right = n - 1 count = 0 while (left <= right): mid = int((right + left)/ 2) # Check if middle element is # less than or equal to key if (arr[mid]<=key): count = mid+1 left = mid + 1 # If key is smaller, ignore right half else: right = mid - 1 return count # --------------------------------------------------binary---------------------------------------- def countdig(n): c = 0 while (n > 0): n //= 10 c += 1 return c def countGreater( arr,n, k): l = 0 r = n - 1 # Stores the index of the left most element # from the array which is greater than k leftGreater = n # Finds number of elements greater than k while (l <= r): m = int(l + (r - l) / 2) if (arr[m] >= k): leftGreater = m r = m - 1 # If mid element is less than # or equal to k update l else: l = m + 1 # Return the count of elements # greater than k return (n - leftGreater) # --------------------------------------------------binary------------------------------------ n,x,k=map(int,input().split()) l=list(map(int,input().split())) def calc(): l.sort() ans=0 aq=[] for i in range(n): aq.append(l[i]) b=l[i] a=l[i]-l[i]%x+1 #print(a,b) rt=binarySearchCount(aq,len(aq),b)-1 rt1=len(aq)-countGreater(aq,len(aq),a) #print(rt,rt1) ans+=rt-rt1+1 #print(ans) aq=deque([]) for i in range(n-1,-1,-1): #print(aq) b = l[i] a = l[i] - l[i] % x + 1 #print(a,b) rt = binarySearchCount(aq, len(aq), b) - 1 rt1 = len(aq) - countGreater(aq, len(aq), a) ans += rt - rt1 + 1 aq.appendleft(l[i]) #print(ans) print(ans) if k==0: calc() sys.exit() l.sort() aq=[] ans=0 for i in range(n): aq.append(l[i]) st=l[i]-l[i]%x b=st-x*k+x a=b-x+1 #print(a,b) rt=binarySearchCount(aq,len(aq),b)-1 rt1=len(aq)-countGreater(aq,len(aq),a) #print(rt,rt1) ans+=rt-rt1+1 #print(ans) aq=deque([]) for i in range(n-1,-1,-1): #print(aq) st = l[i] - l[i] % x b = st - x * k + x a = b - x + 1 #print(a,b) rt = binarySearchCount(aq, len(aq), b) - 1 rt1 = len(aq) - countGreater(aq, len(aq), a) ans += rt - rt1 + 1 aq.appendleft(l[i]) #print(ans) print(ans) ```
instruction
0
23,488
22
46,976
Yes
output
1
23,488
22
46,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai ≤ aj and there are exactly k integers y such that ai ≤ y ≤ aj and y is divisible by x. In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1). Input The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. Output Print one integer — the answer to the problem. Examples Input 4 2 1 1 3 5 7 Output 3 Input 4 2 0 5 3 1 7 Output 4 Input 5 3 1 3 3 3 3 3 Output 25 Note In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25. Submitted Solution: ``` m=[int(i) for i in input().split()] a=[int(i) for i in input().split()] t=0 try: for i in a: for j in a: t1=0 if i==j: if i%m[2]==0: t1=t1+1 if i%m[2]==0: t1=t1+1 for k in range(i,j+1): if k%m[2]==0: t1=t1+1 if t1==m[1]: t=t+1 if i<j: for k in range(i,j): if k%m[2]==0: t1=t1+1 if t1==m[1]: t=t+1 except: print(4) print(t) ```
instruction
0
23,492
22
46,984
No
output
1
23,492
22
46,985
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,708
22
47,416
"Correct Solution: ``` p = [1] * (100000 + 1) p[0], p[1] = 0, 0 for i in range(2, int(100000 ** 0.5) + 1): if not p[i]: continue for j in range(2 * i, 100000 + 1, i): p[j] = 0 while 1: try: n = int(input()) bp, ap = 0, 0 for i in range(n)[::-1]: if p[i] == 1: bp = i break for i in range(n+1, 2 * n + 1): if p[i] == 1: ap = i break print(bp, ap) except: break ```
output
1
23,708
22
47,417
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,709
22
47,418
"Correct Solution: ``` is_prime = [False,False] for i in range(2,1000000): is_prime.append(True) for i in range(2,1000000): if is_prime[i]: for j in range(i*i,1000000,i): is_prime[j] = False while 1: try: a = int(0) b = int(0) n = int(input()) for i in range(n-1,0,-1): if is_prime[i]: a = i break for i in range(n+1,50022): if is_prime[i]: b = i break print("%s %d"%(a,b)) except: break ```
output
1
23,709
22
47,419
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,710
22
47,420
"Correct Solution: ``` MAX = 60000 lst = [i for i in range(MAX)] lst[0] = lst[1] = 0 for i in range(MAX): if lst[i] != 0: for j in range(i * 2, MAX, i): lst[j] = 0 while 0 == 0: try: n = int(input()) i = n - 1 j = n + 1 while lst[i] == 0: i -= 1 while lst[j] == 0: j += 1 print(str(lst[i]) + " " + str(lst[j])) except EOFError: break ```
output
1
23,710
22
47,421
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,711
22
47,422
"Correct Solution: ``` import math isPrime = [True] * 60001 primes = [] def eratos(n): isPrime[0] = isPrime[1] = False for i in range(2,int(math.sqrt(n))): if isPrime[i]: j = 2 * i while j <= n: isPrime[j] = False j = j + i for i in range(2,60000): if isPrime[i]: primes.append(i) eratos(60000) while True: try: p = int(input()) min = list(filter(lambda x: x < p,primes)) max = list(filter(lambda x: x > p,primes)) print(min[-1],max[0]) except: break ```
output
1
23,711
22
47,423
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,712
22
47,424
"Correct Solution: ``` import math def first_try(num): list=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67] i=0 tmp=int(math.sqrt(num)) while True: if num in list: return True #その数を超えたら終了 if list[i]>tmp or i==len(list)-1: return True if (num%list[i]==0): return False i+=1 while True: try: num=int(input()) except: break #小さいの s=0 while True: s+=1 if first_try(num-s)==True: print(num-s,end=" ") break #大きいの l=0 while True: l+=1 if first_try(num+l)==True: print(num+l) break ```
output
1
23,712
22
47,425
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,713
22
47,426
"Correct Solution: ``` pr=[True]*50100 for i in range(2,225): if pr[i]: for j in range(i*2,50100,i): pr[j]=False while True: try: n=int(input()) except: break for i in range(n-1,0,-1): if pr[i]: print(i,end=" ") break for i in range(n+1,50100): if pr[i]: print(i) break ```
output
1
23,713
22
47,427
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,714
22
47,428
"Correct Solution: ``` import bisect MAX = 50050 #エラトステネスの篩 is_prime = [True for _ in range(MAX)] is_prime[0] = is_prime[1] = False for i in range(2, int(MAX ** (1 / 2)) + 1): if is_prime[i]: for j in range(i ** 2, MAX, i): is_prime[j] = False primes = [i for i in range(MAX) if is_prime[i]] while True: try: n = int(input()) ind = bisect.bisect_left(primes, n) if primes[ind] == n: print(primes[ind - 1], primes[ind + 1]) else: print(primes[ind - 1], primes[ind]) except EOFError: break ```
output
1
23,714
22
47,429
Provide a correct Python 3 solution for this coding contest problem. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527
instruction
0
23,715
22
47,430
"Correct Solution: ``` from math import sqrt, ceil N = 53000 temp = [True]*(N+1) temp[0] = temp[1] = False for i in range(2, ceil(sqrt(N+1))): if temp[i]: temp[i+i::i] = [False]*(len(temp[i+i::i])) while True: try: n = int(input()) print(n-1-temp[n-1:0:-1].index(True), n+1+temp[n+1:].index(True)) except EOFError: break ```
output
1
23,715
22
47,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` def is_prime(x): if x <= 1: return False i = 2 while i * i <= x: if x % i == 0: return False i += 1 return True while True: try: N = int(input()) except EOFError: break mx = 0 mn = 0 for i in range(N - 1,1,-1): if is_prime(i): mx = i break for i in range(N + 1,N * 2): if is_prime(i): mn = i break print(mx,mn) ```
instruction
0
23,716
22
47,432
Yes
output
1
23,716
22
47,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` MAX = 50025 SQRT = 223 # sqrt(MAX) prime = [True for i in range(MAX)] def sieve(): for i in range(4, MAX, 2): prime[i] = False for i in range(3, SQRT, 2): if prime[i] is True: for j in range(i*i, MAX, i): prime[j] = False sieve() while True: try: n = int(input()) except EOFError: break for i in range(n-1, 1, -1): if prime[i]: a = i break for i in range(n+1, MAX): if prime[i]: b = i break print(a, b) ```
instruction
0
23,717
22
47,434
Yes
output
1
23,717
22
47,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` from itertools import chain from bisect import bisect_left max_n = 50022 primes = {2,3} | {m for n in (5, 7) for m in range(n, max_n, 6)} du = primes.difference_update for n in chain(range(5, max_n, 6), range(7, max_n, 6)): if n in primes: du(range(n*3, max_n, n*2)) primes = tuple(primes) try: while True: n = int(input()) i = bisect_left(primes, n) print(primes[i-1], primes[i+(n==primes[i])]) except EOFError: exit() ```
instruction
0
23,718
22
47,436
Yes
output
1
23,718
22
47,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` a = [0, 0, 1, 1] + [0, 1] * 25009 for i in range(3, 50022, 2): if a[i]: for j in range(2, 50021 // i + 1):a[i * j] = 0 while 1: try: n = int(input()) print("{} {}".format(n - 1 - a[:n][::-1].index(1), n + 1 + a[n + 1:].index(1))) except:break ```
instruction
0
23,719
22
47,438
Yes
output
1
23,719
22
47,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` def sieve(n): p=[True]*(n+1) p[0]=p[1]=False for i in range(2,int((n+1)*0.5)+1): if p[i]==True: for j in range(i*i,n+1,i): p[j]=False prime=[] for i in range(n+1): if p[i]==True: prime.append(i) return prime def solve(n): i=0 a,b=0,0 while True: if n>prime[i]: a=prime[i] elif n==prime[i]: a=prime[i-1] else: b=prime[i] break i+=1 print(a,b) prime=sieve(5100) while True: try: n=int(input()) solve(n) except EOFError: break ```
instruction
0
23,720
22
47,440
No
output
1
23,720
22
47,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` a = [0, 0, 1, 1] + [0, 1] * 24999 for i in range(3, 50001, 2): if a[i]: for j in range(2, 50001 // i):a[i * j] = 0 while 1: try: n = int(input()) print("{} {}".format(n - 1 - a[:n][::-1].index(1), n + 1 + a[n + 1:].index(1))) except:break ```
instruction
0
23,721
22
47,442
No
output
1
23,721
22
47,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` import sys from itertools import takewhile, dropwhile L, pn, tmp = 224, [], [i for i in range(2, 50000)] while tmp[0] < 224: v = tmp.pop(0) pn.append(v) tmp = list(filter(lambda x: x%v!=0, tmp)) for t in tmp: pn.append(t) for line in sys.stdin: n = int(line.strip()) print(list(takewhile(lambda x: x<n, pn))[-1], list(dropwhile(lambda x: x<n, pn))[1]) ```
instruction
0
23,722
22
47,444
No
output
1
23,722
22
47,445
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and 1. When you enter the integer n, write a program that outputs the largest prime number less than n and the smallest prime number greater than n. Input Given multiple datasets. Each dataset is given n (3 ≤ n ≤ 50,000) on one row. The number of datasets does not exceed 50. Output For each dataset, output the largest prime number less than n and the smallest prime number greater than n on one line, separated by a space. Example Input 19 3517 Output 17 23 3511 3527 Submitted Solution: ``` import sys def primegen(): l = [2] while True: yield max(l) n = max(l) while True: n += 1 flag = 1 for i in l: if n % i == 0: flag = 0 break if flag: l.append(n) break for line in sys.stdin: n = int(line) seq = primegen() i1 = 0 i2 = 0 while i2 < n: i1 = i2 i2 = seq.__next__() if i2 == n: i2 = seq.__next__() print(str(i1) + " " + str(i2)) ```
instruction
0
23,723
22
47,446
No
output
1
23,723
22
47,447
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,955
22
47,910
Tags: constructive algorithms, number theory Correct Solution: ``` t=int(input()) for _ in range(t): n=int(input()) if(n==1): print("-1") else: if n==2: print(49) else: print("9"*(n-2)+"49") ```
output
1
23,955
22
47,911
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,956
22
47,912
Tags: constructive algorithms, number theory Correct Solution: ``` def solve(n): if n == 1: return -1 return "2" + "3" * (n - 1) t = int(input()) for i in range(t): n = int(input()) y = solve(n) print(y) ```
output
1
23,956
22
47,913
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,957
22
47,914
Tags: constructive algorithms, number theory Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() for i in range(int(input())): a = int(input()) if a == 1: print(-1) else: if 2 * (a-1)% 3 == 0: print("2" * (a-2) + "7" + "3") else: print("2" * (a-1)+ "3") ```
output
1
23,957
22
47,915
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,958
22
47,916
Tags: constructive algorithms, number theory Correct Solution: ``` def main(): for i in range(int(input())): lst=int(input()) if lst == 1: print(-1) else: print(10**lst -2) main() ```
output
1
23,958
22
47,917
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,959
22
47,918
Tags: constructive algorithms, number theory Correct Solution: ``` for tes in range(int(input())): n=int(input()) if n<=1: print('-1') else: t='5'+'3'*(n-1) print(t) ```
output
1
23,959
22
47,919
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,960
22
47,920
Tags: constructive algorithms, number theory Correct Solution: ``` def solver(n): if n == 1: return -1 if n == 2: return 98 result = "98" for _ in range(n-2): result = result + "9" return result N = input() for _ in range(int(N)): n = input() print(solver(int(n))) ```
output
1
23,960
22
47,921
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,961
22
47,922
Tags: constructive algorithms, number theory Correct Solution: ``` tc = int(input()) import math for _ in range(tc): x = int(input()) if x == 1: print(-1) else: ans = "2" for i in range(x-1): ans+="3" print(ans) ```
output
1
23,961
22
47,923
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero).
instruction
0
23,962
22
47,924
Tags: constructive algorithms, number theory Correct Solution: ``` for t in range(int(input())): n = int(input()) if n==1: print(-1) continue print('2' + ('3'*(n-1))) ```
output
1
23,962
22
47,925
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero). Submitted Solution: ``` import math def sol(): t=int(input()) for _ in range(t): n=int(input()) s="2" if(n==1): print(-1) continue else: for i in range(n-1): s+="3" print(s) if(__name__=='__main__'): sol() ```
instruction
0
23,963
22
47,926
Yes
output
1
23,963
22
47,927
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero). Submitted Solution: ``` def solution(n): """TODO: Docstring for solution. :n: TODO :returns: TODO """ if n == 1: print(-1) return ans = [2]*(n - 1) + [9] if (n - 1) % 9 == 0: ans[0] = 4 print(''.join(map(str, ans))) t = int(input()) for _ in range(t): solution(int(input())) ```
instruction
0
23,964
22
47,928
Yes
output
1
23,964
22
47,929
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero). Submitted Solution: ``` import math class Read: @staticmethod def string(): return input() @staticmethod def int(): return int(input()) @staticmethod def list(sep=' '): return input().split(sep) @staticmethod def list_int(sep=' '): return list(map(int, input().split(sep))) def solve(): n = Read.int() if n == 1: print(-1); return res = '' if (n - 1) % 3 != 0: for i in range(n - 1): res += '2' else: res = '3' for i in range(n - 2): res += '2' res += '3' print(res) # query_count = 1 query_count = Read.int() while query_count: query_count -= 1 solve() ```
instruction
0
23,965
22
47,930
Yes
output
1
23,965
22
47,931
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero). Submitted Solution: ``` def div(n): a=n while(a>0): b=a%10 if(n%b==0): return(1) a=a//10 return(0) n=int(input()) l=[] c=0 if(n==1): print(-1) else: if(n==2): l=[i for i in range(10,99) if(str(i).count('0')==0 and div(i)==0)] elif(n==3): l=[i for i in range(100,999) if(str(i).count('0')==0 and div(i)==0)] elif(n==4): l=[i for i in range(1000,9999) if(str(i).count('0')==0 and div(i)==0)] for i in l: print(i) break ```
instruction
0
23,968
22
47,936
No
output
1
23,968
22
47,937
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a integer n (n > 0). Find any integer s which satisfies these conditions, or report that there are no such numbers: In the decimal representation of s: * s > 0, * s consists of n digits, * no digit in s equals 0, * s is not divisible by any of it's digits. Input The input consists of multiple test cases. The first line of the input contains a single integer t (1 ≤ t ≤ 400), the number of test cases. The next t lines each describe a test case. Each test case contains one positive integer n (1 ≤ n ≤ 10^5). It is guaranteed that the sum of n for all test cases does not exceed 10^5. Output For each test case, print an integer s which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for s, print any solution. Example Input 4 1 2 3 4 Output -1 57 239 6789 Note In the first test case, there are no possible solutions for s consisting of one digit, because any such solution is divisible by itself. For the second test case, the possible solutions are: 23, 27, 29, 34, 37, 38, 43, 46, 47, 49, 53, 54, 56, 57, 58, 59, 67, 68, 69, 73, 74, 76, 78, 79, 83, 86, 87, 89, 94, 97, and 98. For the third test case, one possible solution is 239 because 239 is not divisible by 2, 3 or 9 and has three digits (none of which equals zero). Submitted Solution: ``` t = int(input()) for i in range(t): n = int(input()) if n == 1: print("-1", end="") else: print("3", end="") for i in range(n-1): print("4", end="") print("") ```
instruction
0
23,969
22
47,938
No
output
1
23,969
22
47,939
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3.
instruction
0
24,863
22
49,726
Tags: hashing, math, number theory Correct Solution: ``` import math from collections import Counter n, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 prev = Counter() for x in a: sig = [] p = 2 while p <= math.sqrt(x): cnt = 0 while x % p == 0: cnt += 1 x = x // p cnt = cnt % k if cnt > 0: sig.append((p, cnt)) p += 1 if x > 1: sig.append((x, 1)) com_sig = [] for p, val in sig: com_sig.append((p, (k - val) % k)) ans += prev[tuple(sig)] prev[tuple(com_sig)] += 1 print(ans) ```
output
1
24,863
22
49,727
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3.
instruction
0
24,864
22
49,728
Tags: hashing, math, number theory Correct Solution: ``` n,k=map(int,input().split()) A=list(map(int,input().split())) import math from collections import Counter C=Counter() for x in A: L=int(math.sqrt(x)) FACT=dict() for i in range(2,L+2): while x%i==0: FACT[i]=FACT.get(i,0)+1 x=x//i if x!=1: FACT[x]=FACT.get(x,0)+1 for f in list(FACT): FACT[f]%=k if FACT[f]==0: del FACT[f] if FACT==dict(): C[(1,1)]+=1 else: RET=1 ALL=1 for f in FACT: RET*=f**FACT[f] ALL*=f**k C[(RET,ALL//RET)]+=1 ANS=0 ANS2=0 for x,y in C: if x==y: ANS+=C[(x,y)]*(C[(x,y)]-1)//2 else: ANS2+=C[(x,y)]*C[(y,x)] print(ANS+ANS2//2) ```
output
1
24,864
22
49,729
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3.
instruction
0
24,865
22
49,730
Tags: hashing, math, number theory Correct Solution: ``` from collections import Counter as C NN = 100000 X = [-1] * (NN+1) L = [[] for _ in range(NN+1)] k = 2 while k <= NN: X[k] = 1 L[k].append(k) for i in range(k*2, NN+1, k): X[i] = 0 L[i].append(k) d = 2 while k**d <= NN: for i in range(k**d, NN+1, k**d): L[i].append(k) d += 1 while k <= NN and X[k] >= 0: k += 1 P = [i for i in range(NN+1) if X[i] == 1] K = 4 def free(ct): a = 1 for c in ct: a *= c ** (ct[c] % K) return a def inv(ct): a = 1 for c in ct: a *= c ** (-ct[c] % K) return a N, K = map(int, input().split()) A = [int(a) for a in input().split()] D = {} ans = 0 for a in A: c = C(L[a]) invc = inv(c) if invc in D: ans += D[invc] freec = free(c) if freec in D: D[freec] += 1 else: D[freec] = 1 print(ans) ```
output
1
24,865
22
49,731
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3.
instruction
0
24,866
22
49,732
Tags: hashing, math, number theory Correct Solution: ``` nmax = 400 eratos = [0 for i in range(nmax+1)] prime = [] cnt = 2 while True: while cnt <= nmax and eratos[cnt]: cnt += 1 if cnt > nmax: break eratos[cnt] = 1 prime.append(cnt) for i in range(cnt**2,nmax+1,cnt): eratos[i] = 1 from collections import defaultdict import sys input = sys.stdin.readline n,k = map(int,input().split()) a = list(map(int,input().split())) st = set() for i in prime: if i**k > 10**5: break st.add(i**k) dc = defaultdict(int) ans = 0 for i in a: for j in st: while i%j == 0: i //= j dc[i] += 1 for i,v in dc.items(): x = 1 y = i if i == 1: ans += (v-1)*v//2 continue if v == 0: continue for p in prime: cnt = 0 while i%p == 0: cnt += 1 i //= p if cnt: x *= p**(k-cnt) if i != 1: if k == 2: x *= i else: continue if x == y: ans += v*(v-1)//2 continue if x in dc: ans += dc[x]*v dc[x] = 0 print(ans) ```
output
1
24,866
22
49,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3. Submitted Solution: ``` nmax = 400 eratos = [0 for i in range(nmax+1)] prime = [] cnt = 2 while True: while cnt <= nmax and eratos[cnt]: cnt += 1 if cnt > nmax: break eratos[cnt] = 1 prime.append(cnt) for i in range(cnt**2,nmax+1,cnt): eratos[i] = 1 from collections import defaultdict import sys input = sys.stdin.readline n,k = map(int,input().split()) a = list(map(int,input().split())) st = set() for i in prime: if i**k > 10**5: break st.add(i**k) dc = defaultdict(int) ans = 0 for i in a: for j in st: while i%j == 0: i //= j dc[i] += 1 for i,v in dc.items(): x = 1 if i == 1: ans += (v-1)*v//2 continue if v == 0: continue for p in prime: cnt = 0 while i%p == 0: cnt += 1 i //= p if cnt: x *= p**(k-cnt) if i != 1: if k == 2: x *= i else: continue if x in dc: ans += dc[x]*v dc[x] = 0 print(ans) ```
instruction
0
24,868
22
49,736
No
output
1
24,868
22
49,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3. Submitted Solution: ``` nmax = 400 eratos = [0 for i in range(nmax+1)] prime = [] cnt = 2 while True: while cnt <= nmax and eratos[cnt]: cnt += 1 if cnt > nmax: break eratos[cnt] = 1 prime.append(cnt) for i in range(cnt**2,nmax+1,cnt): eratos[i] = 1 from collections import defaultdict import sys input = sys.stdin.readline n,k = map(int,input().split()) a = list(map(int,input().split())) st = set() for i in prime: if i**k > 10**5: break st.add(i**k) dc = defaultdict(int) ans = 0 for i in a: for j in st: while i%j == 0: i //= j dc[i] += 1 for i,v in dc.items(): x = 1 if i == 1: ans += (v-1)*v//2 continue if v == 0: continue for p in prime: cnt = 0 while i%p == 0: cnt += 1 i //= p if cnt: x *= p**(k-cnt) if i != 1: if k == 2: x *= i else: continue if x == i: ans += v*(v-1)//2 continue if x in dc: ans += dc[x]*v dc[x] = 0 print(ans) ```
instruction
0
24,869
22
49,738
No
output
1
24,869
22
49,739
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,984
22
49,968
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` import math ans = [] n, m = map(int, input().split()) for _ in range(n): ans.append([720720 for i in range(m)]) for i in range(n): x = list(map(int, input().split())) for j in range(m): if (i + j)%2: ans[i][j] += x[j]**4 for i in range(n): print(*ans[i]) ```
output
1
24,984
22
49,969
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,985
22
49,970
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` import sys #import re #sys.stdin=open('.in','r') #sys.stdout=open('.out','w') #import math #import queue #import random #sys.setrecursionlimit(int(1e6)) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ################################################################ ############ ---- THE ACTUAL CODE STARTS BELOW ---- ############ n,m=invr() a=[[] for i in range(n)] for i in range(n): a[i]=inara() for i in range(n): for j in range(m): if (i+j)%2: a[i][j]=720720 else: a[i][j]=720720+a[i][j]*a[i][j]*a[i][j]*a[i][j] for i in range(n): print(*a[i]) ```
output
1
24,985
22
49,971
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,986
22
49,972
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` from sys import stdin, stdout from collections import defaultdict import math def main(): n, m = list(map(int, stdin.readline().split())) arr = [] for i in range(n): arr.append(list(map(int, stdin.readline().split()))) lcm = 1 for i in range(1, 17): lcm = (i * lcm) // math.gcd(i, lcm) for i in range(n): ans = [] for j in range(m): if (i+j) % 2 == 1: ans.append(lcm + (arr[i][j] ** 4)) else: ans.append(lcm) stdout.write(' '.join(str(x) for x in ans)+'\n') main() ```
output
1
24,986
22
49,973
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,987
22
49,974
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` import sys sys.setrecursionlimit(10**5) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() inf = 10**16 md = 10**9+7 # md = 998244353 h,w=MI() aa=LLI(h) bb=[[720720]*w for _ in range(h)] for i in range(h): for j in range(w): if i+j&1: bb[i][j]+=aa[i][j]**4 for row in bb: print(*row) ```
output
1
24,987
22
49,975
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,988
22
49,976
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` n, m = map(int, input().split()) for i in range(n) : a = list(map(int, input().split())) for j in range(m) : if (j+i) & 1 : print(720720, end = " ") else : print(720720 - a[j] * a[j] * a[j] * a[j], end = " ") print() ```
output
1
24,988
22
49,977
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,989
22
49,978
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` import sys import math from collections import defaultdict,Counter,deque # input=sys.stdin.readline # def print(x): # sys.stdout.write(str(x)+"\n") import os import sys from io import BytesIO, IOBase 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") # sys.stdout=open("CP1/output.txt",'w') # sys.stdin=open("CP1/input.txt",'r') # mod=pow(10,9)+7 # t=int(input()) for i in range(1): n,m=map(int,input().split()) lcm=1 for j in range(2,17): p=lcm*j g=math.gcd(lcm,j) lcm=p//g for j in range(n): a=list(map(int,input().split())) for k in range(m): if (j+k)%2==0: print(lcm,end=' ') else: print(lcm+(a[k]**4),end=' ') print() ```
output
1
24,989
22
49,979
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,990
22
49,980
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase 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") # ------------------- fast io -------------------- from math import gcd, ceil def prod(a, mod=10**9+7): ans = 1 for each in a: ans = (ans * each) % mod return ans def lcm(a, b): return a * b // gcd(a, b) def binary(x, length=16): y = bin(x)[2:] return y if len(y) >= length else "0" * (length - len(y)) + y n, m = map(int, input().split()) a = [] for i in range(n): a += [list(map(int, input().split()))] for i in range(n): for j in range(m): if (i+j) % 2: a[i][j] = 720720 - a[i][j]**4 else: a[i][j] = 720720 for i in a: print(*i, sep=' ') ```
output
1
24,990
22
49,981
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in b is equal to k^4 for some integer k ≥ 1 (k is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists. Input The first line contains two integers n and m (2 ≤ n,m ≤ 500). Each of the following n lines contains m integers. The j-th integer in the i-th line is a_{i,j} (1 ≤ a_{i,j} ≤ 16). Output The output should contain n lines each containing m integers. The j-th integer in the i-th line should be b_{i,j}. Examples Input 2 2 1 2 2 3 Output 1 2 2 3 Input 2 3 16 16 16 16 16 16 Output 16 32 48 32 48 64 Input 2 2 3 11 12 8 Output 327 583 408 664 Note In the first example, the matrix a can be used as the matrix b, because the absolute value of the difference between numbers in any adjacent pair of cells is 1 = 1^4. In the third example: * 327 is a multiple of 3, 583 is a multiple of 11, 408 is a multiple of 12, 664 is a multiple of 8; * |408 - 327| = 3^4, |583 - 327| = 4^4, |664 - 408| = 4^4, |664 - 583| = 3^4.
instruction
0
24,991
22
49,982
Tags: constructive algorithms, graphs, math, number theory Correct Solution: ``` # from __future__ import print_function,division # range = xrange import sys input = sys.stdin.readline # sys.setrecursionlimit(10**9) from sys import stdin, stdout from collections import defaultdict, Counter from math import gcd M = 10**9+7 lcm = lambda a,b:a*b//gcd(a,b) def main(): n,m = [int(s) for s in input().split()] l = [[int(s) for s in input().split()] for i in range(n)] x = 1 s = set() for i in range(n): for j in range(m): if l[i][j] not in s: s.add(l[i][j]) x = lcm(x,l[i][j]) for i in range(n): for j in range(m): if i%2: if j%2: print(x,end=' ') else: print(x+l[i][j]**4,end=' ') else: if j%2==0: print(x,end=' ') else: print(x+l[i][j]**4,end=' ') print() if __name__== '__main__': main() ```
output
1
24,991
22
49,983
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries: * Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). * The answer to the query li, ri is the number of pairs of integers q, w (li ≤ q, w ≤ ri) such that pq is the divisor of pw. Help Yaroslav, answer all his queries. Input The first line contains the integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). The following m lines contain Yaroslav's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n). Output Print m integers — the answers to Yaroslav's queries in the order they appear in the input. 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. Examples Input 1 1 1 1 1 Output 1 Input 10 9 1 2 3 4 5 6 7 8 9 10 1 10 2 9 3 8 4 7 5 6 2 2 9 10 5 10 4 10 Output 27 14 8 4 2 1 2 7 9 Submitted Solution: ``` input() print(max(map(int,input().split()))) ```
instruction
0
25,046
22
50,092
No
output
1
25,046
22
50,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries: * Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). * The answer to the query li, ri is the number of pairs of integers q, w (li ≤ q, w ≤ ri) such that pq is the divisor of pw. Help Yaroslav, answer all his queries. Input The first line contains the integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). The following m lines contain Yaroslav's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n). Output Print m integers — the answers to Yaroslav's queries in the order they appear in the input. 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. Examples Input 1 1 1 1 1 Output 1 Input 10 9 1 2 3 4 5 6 7 8 9 10 1 10 2 9 3 8 4 7 5 6 2 2 9 10 5 10 4 10 Output 27 14 8 4 2 1 2 7 9 Submitted Solution: ``` import math if __name__ == '__main__': n, m = [int(_) for _ in input().split()] input() for query_id in range(m): l, r = [int(_) for _ in input().split()] count = 0 idx = l while idx <= r: i = math.floor(r / idx) j = math.floor(r / i) count += (j - idx + 1) * i idx = j + 1 print(count) ```
instruction
0
25,047
22
50,094
No
output
1
25,047
22
50,095