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.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6 | instruction | 0 | 32,594 | 22 | 65,188 |
Tags: dfs and similar, graphs, greedy, number theory, sortings
Correct Solution:
```
from collections import Counter
def rwh_primes(n):
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
primes = rwh_primes(2750132)
sprimes = set(primes)
def dl(x):
if x in sprimes:
return None
for p in primes:
if x % p == 0:
return x // p
elif p * p > x:
return None
n = int(input())
a = sorted(map(int, input().split()), reverse = True)
sa = set(a)
r = []
x = Counter()
p1 = []
p2 = []
for v in a:
if v in x and x[v] > 0:
x[v] -= 1
continue
d = dl(v)
if d and d in sa:
x[d] += 1
r.append(v)
elif v in sprimes:
p1.append(v)
else:
p2.append(v)
x = Counter()
y = 0
for v in reversed(p1):
if v in x and x[v] > 0:
x[v] -= 1
continue
r.append(v)
if v < len(primes)+1:
x[primes[v-1]] += 1
else:
y += 1
z = (len(p2) - y)//2
r.extend(p2[::-1][y:y+z])
print(*r)
``` | output | 1 | 32,594 | 22 | 65,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6 | instruction | 0 | 32,595 | 22 | 65,190 |
Tags: dfs and similar, graphs, greedy, number theory, sortings
Correct Solution:
```
import sys
from collections import Counter
from bisect import bisect_left
def Sieve(l): # Check if can be modified for primeNUmbers at prime places
#l=3 * 1000 * 1000 + 13
primes=[0]*2+[1]*l
for i in range(l):
if primes[i]:
for j in range(i*i,l,i):
primes[j]=0
primes=[k for k in range(l) if primes[k]]
return primes
#print(Sieve(10))
def index(a, x):
i = bisect_left(a, x)
if i != len(a) and a[i] == x:
return i
raise ValueError
n=int(input())
a=sorted(list(map(int,sys.stdin.readline().split())))
b=Counter(a)
actual=Counter()
l=-1
prime=Sieve(a[-1]+1)
while l!=-2*n:
#print(a)
mx=a[l]
#print(mx,l)
if b[mx]>0:
try:
second=index(prime,mx)+1
actual[second]=actual[second]+b[mx]
#print("prime:",mx,second,l)
except:
i=0
while mx%prime[i]!=0:
i=i+1
second=mx//prime[i]
actual[mx]=actual[mx]+b[mx]
#print("Mx will be added:",mx,second,l)
l=l-b[mx]
b[second]=b[second]-b[mx]
b[mx]=0
else:
l=l-1
#second=index(prime,a[-1])+1
#print(actual)
print(*actual.elements(), sep =' ')
``` | output | 1 | 32,595 | 22 | 65,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6 | instruction | 0 | 32,596 | 22 | 65,192 |
Tags: dfs and similar, graphs, greedy, number theory, sortings
Correct Solution:
```
from sys import stdin, stdout
import collections
import math
import heapq
def primes(n):
""" Returns a list of primes < n """
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
p = primes(2750132)
look_up = {}
i = 1
for num in p:
look_up[num] = i
i += 1
N = int(input())
#N,M = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
arr.sort()
h = []
freq = {}
for num in arr:
heapq.heappush(h, -num)
freq[num] = 0
#ans = []
while h:
num = -heapq.heappop(h)
if freq[num]>0:
freq[num] -= 1
continue
if num in look_up:
#ans.append(look_up[num])
print(look_up[num],end=' ')
freq[look_up[num]] += 1
else:
for i in range(2,num):
if num%i==0:
print(num,end=' ')
freq[num//i] += 1
break
``` | output | 1 | 32,596 | 22 | 65,193 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6
Submitted Solution:
```
lim = 2750131 + 10# 2 * 10**6 + 2
def erato():
arr = [None] * lim
arr[1] = 1
primes = [1]
for i in range(2, lim):
if not arr[i]:
primes.append(i)
arr[i] = 1
for j in range(i * 2, lim, i):
if not arr[j]:
arr[j] = j // i
s = set(primes)
for i in range(1, len(primes)):
if i in s:
arr[i] = primes[i]
return arr
if __name__ == '__main__':
n = int(input())
bb = set(map(int, input().split()))
e = erato()
res = []
for b in bb:
if e[b] in bb:
res.append(str(b))
# res = list(map(lambda x: str(e[x]), bb))
print(" ".join(res))
``` | instruction | 0 | 32,597 | 22 | 65,194 |
No | output | 1 | 32,597 | 22 | 65,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6
Submitted Solution:
```
def getPrimes():
limit = 10**7
nums = [True]*(limit)
for i in range(2,limit):
if nums[i]:
nums[i] = True
j = 2
while i*j < limit:
nums[i*j] = False
j += 1
primes = {}
count = 1
for i in range(2,limit):
if nums[i]:
primes[i] = count
count += 1
return primes
def factor(n):
facts = []
for i in range(2,int(n**0.5)+1):
if n%i == 0:
facts.append(i)
facts.append(n//i)
return max(facts)
def main():
n = int(input())
arr = list(map(int,input().split()))
arr.sort(reverse = True)
primes = getPrimes()
#print(prime_list,primes)
ans = []
for i in range(n):
if arr[i] in primes.keys():
num = primes[arr[i]]
ans.append(num)
else:
ans.append(arr[i])
for i in ans:
print(i,end = ' ')
main()
``` | instruction | 0 | 32,598 | 22 | 65,196 |
No | output | 1 | 32,598 | 22 | 65,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6
Submitted Solution:
```
from collections import Counter
lim = 2750131 + 10# 2 * 10**6 + 2
def erato():
arr = [None] * lim
arr[1] = 1
primes = [1]
for i in range(2, lim):
if not arr[i]:
primes.append(i)
arr[i] = 1
for j in range(i * 2, lim, i):
if not arr[j]:
arr[j] = j // i
s = set(primes)
for i in range(1, len(primes)):
if i in s:
arr[i] = primes[i]
return arr
if __name__ == '__main__':
n = int(input())
bb = list(map(int, input().split()))
cnt = Counter(bb)
e = erato()
res = []
for b in bb:
if cnt[e[b]] > 0 and cnt[b] > 0:
res.append(str(b))
cnt.subtract({b:1, e[b]:1})
# res = list(map(lambda x: str(e[x]), bb))
print(" ".join(res))
``` | instruction | 0 | 32,599 | 22 | 65,198 |
No | output | 1 | 32,599 | 22 | 65,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Authors guessed an array a consisting of n integers; each integer is not less than 2 and not greater than 2 β
10^5. You don't know the array a, but you know the array b which is formed from it with the following sequence of operations:
1. Firstly, let the array b be equal to the array a;
2. Secondly, for each i from 1 to n:
* if a_i is a prime number, then one integer p_{a_i} is appended to array b, where p is an infinite sequence of prime numbers (2, 3, 5, ...);
* otherwise (if a_i is not a prime number), the greatest divisor of a_i which is not equal to a_i is appended to b;
3. Then the obtained array of length 2n is shuffled and given to you in the input.
Here p_{a_i} means the a_i-th prime number. The first prime p_1 = 2, the second one is p_2 = 3, and so on.
Your task is to recover any suitable array a that forms the given array b. It is guaranteed that the answer exists (so the array b is obtained from some suitable array a). If there are multiple answers, you can print any.
Input
The first line of the input contains one integer n (1 β€ n β€ 2 β
10^5) β the number of elements in a.
The second line of the input contains 2n integers b_1, b_2, ..., b_{2n} (2 β€ b_i β€ 2750131), where b_i is the i-th element of b. 2750131 is the 199999-th prime number.
Output
In the only line of the output print n integers a_1, a_2, ..., a_n (2 β€ a_i β€ 2 β
10^5) in any order β the array a from which the array b can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.
Examples
Input
3
3 5 2 3 2 4
Output
3 4 2
Input
1
2750131 199999
Output
199999
Input
1
3 6
Output
6
Submitted Solution:
```
def Factor(n):
Ans = []
d = 2
c = n
while d * d <= n:
if n % d == 0:
Ans.append(d)
n //= d
else:
d += 1
if n > 1:
Ans.append(n)
return max(c // min(Ans), max(Ans))
def easy(n):
a = list(range(n+1))
a[1] = 0
lst = []
i = 2
while i <= n:
if a[i] != 0:
lst.append(a[i])
for j in range(i, n+1, i):
a[j] = 0
i += 1
return lst
n = int(input())
a = [int(i) for i in input().split()]
b = {}
c = []
m = easy(2750131)
for i in a:
b[i] = b.get(i, 0) + 1
for i in a:
l = Factor(i)
if l == i and i != 2750131:
h = m[i - 1]
if b[i] > 0 and b.get(h, 0) > 0:
c.append(i)
b[i] -= 1
b[h] = b.get(l, 0) - 1
elif l < i:
if ((b[i] > 0) and (b.get(l, 0) > 0)):
c.append(i)
b[i] -= 1
b[l] = b.get(l, 0) - 1
print(i, l)
print(b)
print('-' * 90)
print(' '.join([str(i) for i in c]))
``` | instruction | 0 | 32,600 | 22 | 65,200 |
No | output | 1 | 32,600 | 22 | 65,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,739 | 22 | 65,478 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# Fast IO Region
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")
# Get out of main function
def main():
pass
# decimal to binary
def binary(n):
return (bin(n).replace("0b", ""))
# binary to decimal
def decimal(s):
return (int(s, 2))
# power of a number base 2
def pow2(n):
p = 0
while n > 1:
n //= 2
p += 1
return (p)
# if number is prime in βn time
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
# list to string ,no spaces
def lts(l):
s = ''.join(map(str, l))
return s
# String to list
def stl(s):
# for each character in string to list with no spaces -->
l = list(s)
# for space in string -->
# l=list(s.split(" "))
return l
# Returns list of numbers with a particular sum
def sq(a, target, arr=[]):
s = sum(arr)
if (s == target):
return arr
if (s >= target):
return
for i in range(len(a)):
n = a[i]
remaining = a[i + 1:]
ans = sq(remaining, target, arr + [n])
if (ans):
return ans
# Sieve for prime numbers in a range
def SieveOfEratosthenes(n):
cnt = 0
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
for p in range(2, n + 1):
if prime[p]:
cnt += 1
# print(p)
return (cnt)
# for positive integerse only
def nCr(n, r):
f = math.factorial
return f(n) // f(r) // f(n - r)
# 1000000007
mod = int(1e9) + 7
def ssinp(): return input()
# s=input()
def iinp(): return int(input())
# n=int(input())
def nninp(): return map(int, input().split())
# a,b,c=map(int,input().split())
def llinp(): return list(map(int, input().split()))
# a=list(map(int,input().split()))
def p(xyz): print(xyz)
def p2(a, b): print(a, b)
import math
# import random
# sys.setrecursionlimit(300000)
# from fractions import Fraction
from collections import OrderedDict
# from collections import deque
######################## mat=[[0 for i in range(n)] for j in range(m)] ########################
######################## list.sort(key=lambda x:x[1]) for sorting a list according to second element in sublist ########################
######################## Speed: STRING < LIST < SET,DICTIONARY ########################
######################## from collections import deque ########################
######################## ASCII of A-Z= 65-90 ########################
######################## ASCII of a-z= 97-122 ########################
######################## d1.setdefault(key, []).append(value) ########################
for __ in range(iinp()):
n,m=nninp()
a=llinp()
rem=[0]*m
ans=0
for c in a:
rem[c%m]+=1
if(m%2==1):
if(rem[0]>0):
ans+=1
for i in range(1,math.ceil(m/2)):
a=rem[i]
b=rem[m-i]
if(a>0 and b>0):
if(a!=b):
ans+=max(a,b)-min(a,b)
else:
ans+=1
else:
ans=ans+max(a,b)
else:
if(rem[0]>0):
ans+=1
if(rem[m//2]>0):
ans+=1
for i in range(1,math.ceil(m/2)):
a=rem[i]
b=rem[m-i]
if(a>0 and b>0):
if(a!=b):
ans+=max(a,b)-min(a,b)
else:
ans+=1
else:
ans=ans+max(a,b)
p(ans)
``` | output | 1 | 32,739 | 22 | 65,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,740 | 22 | 65,480 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
for _ in range(int(input())):
n,m=map(int,input().split())
a=list(map(int,input().split()))
l=[0 for _ in range(m)]
for c in a:
l[c%m]+=1
ans=0
i=0
while i<=m//2:
if i==m-i or i==0:
if l[i]:
ans+=1
else:
if l[i]==0:
if l[m-i]==0:
ans+=0
else:
ans+=l[m-i]
else:
if l[m-i]==0:
ans+=l[i]
else:
if abs(l[i]-l[m-i])<=1:
ans+=1
else:
ans+=max(l[i],l[m-i])-min(l[i],l[m-i])
i+=1
print(ans)
``` | output | 1 | 32,740 | 22 | 65,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,741 | 22 | 65,482 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
for i in range(int(input())):
n,m=map(int,input().split())
a=list(map(int,input().split()))
g=[0]*(m+1)
for j in range(n):
g[a[j]%m]=g[a[j]%m]+1
sumo=0
for j in range(1,(m+1)//2):
if min(g[j],g[m-j])==max(g[j],g[m-j]) and min(g[j],g[m-j])>0:
sumo=sumo+1
else:
sumo=sumo+max(g[j],g[m-j])-min(g[j],g[m-j])
if m%2==0:
if g[m//2]>0:
sumo=sumo+1
if g[0]>0:
sumo=sumo+1
print(sumo)
``` | output | 1 | 32,741 | 22 | 65,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,742 | 22 | 65,484 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int,stdin.readline().split())
L = lambda : list(map(int,stdin.readline().split()))
mod = 1000000009
inf = 100000000000000000000
ss = "abcdefghijklmnopqrstuvwxyz"
############## All the best start coding #######################
def solve():
n,m=M()
a=L()
c=0
d=dt(lambda:0)
for i in a:
d[i%m]+=1
d[m-i%m]
for i in d:
if i==m-i and d[i]!=0:
c=c+1
elif (i==0 or i==m) and d[i]!=0:
c=c+1
elif d[i]==d[m-i]!=0:
c=c+1
else:
c=c+abs(d[i]-d[m-i])
d[i]=0
d[m-i]=0
print(c)
##################### Submit now ##############################
tt=1
tt=I()
for _ in range(tt):
solve()
``` | output | 1 | 32,742 | 22 | 65,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,743 | 22 | 65,486 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
def m_arrays(arr, k):
modulo = {}
seen = set()
for num in arr:
modulo[num % k] = modulo.get(num % k, 0) + 1
ans = 0
for c in modulo:
if k - c not in seen:
if k - c in modulo:
first = modulo[c]
second = modulo[k - c]
ans += max(abs(first - second) - 1, 0) + 1
elif c == 0:
ans += 1
else:
ans += modulo[c]
seen.add(c)
return ans
for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(m_arrays(arr, k))
``` | output | 1 | 32,743 | 22 | 65,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,744 | 22 | 65,488 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
from sys import stdin
from collections import defaultdict
input = stdin.readline
T = int(input())
for t in range(1,T + 1):
n,m = map(int,input().split())
count = defaultdict(lambda : 0)
_input = list(map(int,input().split()))
for i in _input:
count[i % m] += 1
res = 0
res += (count[0] > 0)
l = 1; r = m - 1
while l <= r:
if l == r:
if count[l] > 0:
res += 1
else:
if count[l] == count[r]:
res += (count[l] > 0)
else:
res += max(count[l],count[r]) - min(count[l],count[r])
l += 1
r -= 1
print(res)
``` | output | 1 | 32,744 | 22 | 65,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,745 | 22 | 65,490 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
from collections import Counter
def main():
for _ in range(int(input())):
n,m = map(int,input().split())
a = Counter(map(lambda xx:int(xx)%m,input().split()))
ans = 0
if a[0]:
ans += 1
for i in range(1,m):
if i > m-i:
break
if i == m-i:
if a[i]:
ans += 1
break
x,y = min(a[i],a[m-i]),max(a[i],a[m-i])
if x:
ans += 1
ans += max(0,y-x-1)
else:
ans += y-x
print(ans)
# Fast IO Region
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")
if __name__ == "__main__":
main()
``` | output | 1 | 32,745 | 22 | 65,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element. | instruction | 0 | 32,746 | 22 | 65,492 |
Tags: constructive algorithms, greedy, math
Correct Solution:
```
# Har har mahadev
# author : @ harsh kanani
from collections import Counter
for _ in range(int(input())):
n, m = map(int, input().split())
l = list(map(int, input().split()))
l1 = []
for i in range(n):
l1.append(l[i]%m)
c = Counter(l1)
#print(c)
ans = 0
for i in range(m//2+1):
if i==0:
if i in c:
ans += 1
else:
diff = abs(i-m)
temp = i
if diff in c and temp in c:
#print(diff, temp)
if c[diff] < c[temp]:
c_diff = c[diff]
c[temp] -= (c_diff+1)
c[diff] = 0
ans += 1
elif c[diff] > c[temp]:
c_temp = c[temp]
c[diff] -= (c_temp+1)
c[temp] = 0
ans += 1
else:
c[diff] = 0
c[temp] = 0
ans += 1
#print("debug", c)
if c[diff] > 0:
ans += c[diff]
c[diff] = 0
if c[temp] > 0:
ans += c[temp]
c[temp] = 0
else:
if diff in c:
ans += c[diff]
c[diff] = 0
elif temp in c:
ans += c[temp]
c[temp] = 0
# print("ans:", ans)
# print(c)
print(ans)
``` | output | 1 | 32,746 | 22 | 65,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
for u in range(int(input())):
n, k = map(int, input().split())
x = [int(w) for w in input().split()]
cnt = [0]*(k)
for i in x:
cnt[i%k] += 1
ans = 0
for i in range(k//2 + 1):
opp = (k - i)%k
if(i == opp):
if(cnt[i] > 0):
ans += 1
else:
if(cnt[i] == 0 or cnt[opp] == 0):
ans += cnt[i] + cnt[opp]
else:
a = max(cnt[i], cnt[opp])
b = min(cnt[i], cnt[opp])
if(a - b <= 1):
ans += 1
else:
ans += a-b
print(ans)
``` | instruction | 0 | 32,747 | 22 | 65,494 |
Yes | output | 1 | 32,747 | 22 | 65,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
from collections import Counter
t=int(input())
for j in range(0,t):
n,m=map(int,input().split())
a=[int(x)%m for x in input().split()]
d=Counter(a)
ans=0
for i in set(a):
if d[i]<0:
continue
x=(m-i)%m
v=min(d[x],d[i])+(d[x]!=d[i])
ans+=max(d[x],d[i])-v+1
d[x]=-1
print(ans)
``` | instruction | 0 | 32,748 | 22 | 65,496 |
Yes | output | 1 | 32,748 | 22 | 65,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
num_cases = int(input())
nums = []
for _ in range(num_cases):
n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
num_arrs = 0
mods = [0] * m
for i in a:
mods[i % m] += 1
num_arrs = num_arrs+1 if mods[0] > 0 else num_arrs
mods[0] = 0
for i in range(m//2):
a_start = mods[i+1]
a_end = mods[m-i-1]
if a_start != 0 and a_end != 0:
if mods[i+1] > a_end:
mods[i+1] -= (mods[m-i-1]+1)
num_arrs += 1
mods[m-i-1] = 0
elif mods[m-i-1] > mods[i+1]:
mods[m-i-1] -= (mods[i+1] + 1)
num_arrs += 1
mods[i+1] = 0
else:
mods[m-i-1] = 0
mods[i+1] = 0
num_arrs += 1
num_arrs += sum(mods)
nums.append(num_arrs)
for i in nums:
print(i)
``` | instruction | 0 | 32,749 | 22 | 65,498 |
Yes | output | 1 | 32,749 | 22 | 65,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
import sys
t = int(sys.stdin.readline())
for i in range(t):
n, m = map(int, sys.stdin.readline().split())
data = list(map(int, sys.stdin.readline().split()))
num = [0] * m
for item in data:
num[item % m] += 1
ans = 0
if num[0] != 0:
ans += 1
num[0] = 0
for start in range(1, m // 2 + 1):
end = m - start
temp = min(num[start], num[end])
if temp != 0:
ans += 1
if start == end:
num[start] = 0
continue
if num[start] == num[end]:
num[end] -= temp
num[start] -= temp
continue
if num[start] == temp:
num[end] -= temp + 1
num[start] -= temp
else:
num[start] -= temp + 1
num[end] -= temp
ans += sum(num)
print(ans)
``` | instruction | 0 | 32,750 | 22 | 65,500 |
Yes | output | 1 | 32,750 | 22 | 65,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
from collections import defaultdict
for _ in range(int(input())):
n,m=map(int,input().split())
l=list(map(int,input().split()))
d=defaultdict(list)
for i in range(n):
d[l[i]%m]+=[l[i]]
ans=0
if len(d[0]) > 0:
ans += 1
if m>2:
for i in range(1, m//2+ 1):
if m - i not in d.keys():
ans += len(d[m - i])
if m - i == i:
ans += 1
else:
if abs(len(d[m - i]) - len(d[i])) > 1:
ans += abs(len(d[m - i]) - len(d[i]))
else:
ans += 1
print(ans)
``` | instruction | 0 | 32,751 | 22 | 65,502 |
No | output | 1 | 32,751 | 22 | 65,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
import sys
from collections import Counter
def solve(arr,k):
ans=1 if arr[0]>0 else 0
a,b=1,k-1
while a<=b:
if arr[a]==arr[b] and arr[a]>0:
ans+=1
else:
ans+=abs(arr[a]-arr[b])
a+=1
b-=1
return ans
for _ in range(int(input())):
n,k=map(int,sys.stdin.readline().split())
arr=Counter([int(x)%k for x in sys.stdin.readline().split()])
sys.stdout.write(str(solve(arr,k)))
``` | instruction | 0 | 32,752 | 22 | 65,504 |
No | output | 1 | 32,752 | 22 | 65,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
t=int(input())
for _ in range(t):
n,m=map(int,input().split())
a=list(map(int,input().split()))
f=[0]*m
for i in a:
f[i%m]+=1
t=0
for i in range(m):
if(i==0 and f[i]>0):
t+=1
elif(i!=m-i and f[i]==0):
t+=f[m-i]
elif(i==m-i and f[i]>0):
t+=1
elif(m-i>i):
a=f[i]
b=f[m-i]
if(abs(a-b)<2):
t+=1
elif(a>b):
a-=b+1
t+=a+1
else:
b-=a+1
t+=a+1
print(t)
``` | instruction | 0 | 32,753 | 22 | 65,506 |
No | output | 1 | 32,753 | 22 | 65,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a_1, a_2, β¦, a_n consisting of n positive integers and a positive integer m.
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
Let's call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i and i+1 are called adjacent for each i) their sum is divisible by m. An array of one element is m-divisible.
Find the smallest number of m-divisible arrays that a_1, a_2, β¦, a_n is possible to divide into.
Input
The first line contains a single integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains two integers n, m (1 β€ n β€ 10^5, 1 β€ m β€ 10^5).
The second line of each test case contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 10^9).
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10^5.
Output
For each test case print the answer to the problem.
Example
Input
4
6 4
2 2 8 6 9 4
10 8
1 1 1 5 2 4 4 8 6 7
1 1
666
2 2
2 4
Output
3
6
1
1
Note
In the first test case we can divide the elements as follows:
* [4, 8]. It is a 4-divisible array because 4+8 is divisible by 4.
* [2, 6, 2]. It is a 4-divisible array because 2+6 and 6+2 are divisible by 4.
* [9]. It is a 4-divisible array because it consists of one element.
Submitted Solution:
```
test=int(input())
for _ in range(test):
l,m=map(int,input().split())
ls=list(map(int,input().split()))
d=dict()
for i in range(len(ls)-1):
for j in range(i+1,len(ls)):
if((ls[i]+ls[j])%m==0 and d.get(j,False)==False and d.get(i,False)==False):
d[j]=True
d[i]=True
#print(d)
ct=0
for i in range(len(ls)):
if(d.get(i,False)==False and ls[i]%m!=0):
ct+=1
if(len(d.keys())>0):
ct+=1
if(len(d.keys())==0):
print(l)
else:
print(ct)
``` | instruction | 0 | 32,754 | 22 | 65,508 |
No | output | 1 | 32,754 | 22 | 65,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,846 | 22 | 65,692 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
def gcd(a,b):
if a<b:
c=b
b=a
a=c
while b!=0:
t=b
b=a%b
a=t
return int(a)
def extendedEuclides(a,b):
xx=y=0
yy=x=1
while b!=0:
q=int(a/b)
t=b
b=a%b
a=t
t=xx
xx=x-q*xx
x=t
t=yy
yy=y-q*yy
y=t
return [a,x,y]
def chineseRemainder(x,y,a,b):
[d,s,t]=extendedEuclides(x,y)
if(a%d!=b%d):
return [0,-1]
return [int(((s*b*x+t*a*y)%(x*y))/d),x*y/d]
[n,m,k]=input().split(' ')
n=eval(n)
m=eval(m)
k=eval(k)
arr=list(map(int,input().split(' ')))
I=1
for el in arr:
I=I*(el/gcd(I,el))
if I>n:
break
if I==1:
print("YES")
elif I>n:
print("NO")
else:
can=1
auxI=I
fat=[]
occur=[]
for i in range(2,1010000):
if auxI%i==0:
v=1
while auxI%i==0:
v=v*i
fat.append(v)
occur.append(-1)
auxI=int(auxI/i)
if auxI>1:
fat.append(auxI)
occur.append(-1)
for i,x in enumerate(fat):
for j in range(0,min(k,x)):
if(gcd(arr[j],x)==x):
occur[i]=j
if occur[i]==-1:
can=0
for i,x in enumerate(fat):
for j in range(0,k):
if ((gcd(arr[j],x)!=x and j%x==occur[i])or(gcd(arr[j],x)==x and j%x!=occur[i])):
can=0
I=1
J=1
lrem=0
for i,x in enumerate(fat):
rem=(x-occur[i])%x
g=gcd(I,x)
auxI=I*int(x/g)
xxx=chineseRemainder(I,x,lrem%I,rem)
lrem=xxx[0]
I=auxI
#print(lrem,rem,x,I)
if lrem==0:
lrem=I
if int(lrem)>m-k+1:
can=0
if can==0:
print('NO')
else:
print('YES')
# 1491583330722
``` | output | 1 | 32,846 | 22 | 65,693 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,847 | 22 | 65,694 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
import math
def lcm(a,b):
return a*b// math.gcd(a,b)
def egcd(a,b):
if b==0: return (a, 1, 0)
g,x,y = egcd(b,a%b)
return (g, y, x - (a//b) * y)
def crt(a,m1,b,m2):
g,x,y = egcd(m1,m2)
if (b-a)%g!=0: return (0,-1)
m = m1 * m2 // g
r = (b-a) // g * x % (m2//g)
r = (a + m1 * r) % m
return (r, m)
def nel():
print("NO")
exit(0)
x,y,n = map(int,input().split())
v = list(map(int,input().split()))
mn = 1
for i in v:
mn = lcm(mn,i)
if mn > x: nel()
aux = (0, 1)
for i in range(0,n):
aux = crt(aux[0],aux[1],(-i % v[i] + v[i])%v[i], v[i])
if aux[1]==-1: nel()
if aux[0]==0: aux = (aux[1],aux[1])
if aux[0]+n-1>y: nel()
for i,j in enumerate(v,0):
res = math.gcd(aux[0]+i,aux[1])
if res!=j: nel()
print("YES")
``` | output | 1 | 32,847 | 22 | 65,695 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,848 | 22 | 65,696 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
def gcd(a,b):
if b == 0:
return a
return gcd(b, a%b)
def extend_euclid(a,b):
if b == 0:
return 1,0
else:
y,x = extend_euclid(b, a%b)
y = y - (a//b)*x
return x,y
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
lcm = 1
for i in a:
lcm = (lcm*i)//gcd(lcm, i)
if lcm>n:
print('NO')
exit()
j = 0
m1 = 1
s = True
for i in range(k):
x,y = extend_euclid(m1, a[i])
res = m1*x + a[i]*y
if (-i-j)%res != 0:
s = False
break
res = (-i-j)//res
x,y = x*res , y*res
j += m1*x
t = m1*a[i]
if j>t:
j -= (j//t)*t
if j<0:
j += ((-j+t-1)//t)*t
if j == 0:
j = t
m1 = (m1*a[i])//gcd(m1, a[i])
if j+k-1 >m or s == False:
print('NO')
exit()
b = [gcd(lcm, j+i) for i in range(k)]
for i in range(k):
if (a[i] != b[i]):
print('NO')
exit()
print('YES')
``` | output | 1 | 32,848 | 22 | 65,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,849 | 22 | 65,698 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
#https://codeforces.com/contest/338/problem/D
def gcd(a,b):
if b == 0:
return a
return gcd(b, a%b)
def extend_euclid(a,b):
if b == 0:
return 1,0
else:
y,x = extend_euclid(b, a%b)
y = y - (a//b)*x
return x,y
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
lcm = 1
for i in a:
lcm = (lcm*i)//gcd(lcm, i)
if lcm>n:
print('NO')
exit()
j = 0
m1 = 1
s = True
for i in range(k):
x,y = extend_euclid(m1, a[i])
res = m1*x + a[i]*y
if (-i-j)%res != 0:
s = False
break
res = (-i-j)//res
x,y = x*res , y*res
j += m1*x
t = m1*a[i]
if j>t:
j -= (j//t)*t
if j<0:
j += ((-j+t-1)//t)*t
if j == 0:
j = t
m1 = (m1*a[i])//gcd(m1, a[i])
if j+k-1 >m or s == False:
print('NO')
exit()
b = [gcd(lcm, j+i) for i in range(k)]
for i in range(k):
if (a[i] != b[i]):
print('NO')
exit()
print('YES')
``` | output | 1 | 32,849 | 22 | 65,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,850 | 22 | 65,700 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
def gcd(a,b):
if b == 0:
return a
return gcd(b, a%b)
def ext(a,b):
if b == 0:
return 1,0
else:
y,x = ext(b, a%b)
y = y - (a//b)*x
return x,y
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
lcm = 1
for i in a:
lcm = (lcm*i)//gcd(lcm, i)
if lcm>n:
print('NO')
exit()
j = 0
m1 = 1
s = True
for i in range(k):
x,y = ext(m1, a[i])
res = m1*x + a[i]*y
if (-i-j)%res != 0:
s = False
break
res = (-i-j)//res
x,y = x*res , y*res
j += m1*x
t = m1*a[i]
if j>t:
j -= (j//t)*t
if j<0:
j += ((-j+t-1)//t)*t
if j == 0:
j = t
m1 = (m1*a[i])//gcd(m1, a[i])
if j+k-1 >m or s == False:
print('NO')
exit()
b = [gcd(lcm, j+i) for i in range(k)]
for i in range(k):
if (a[i] != b[i]):
print('NO')
exit()
print('YES')
``` | output | 1 | 32,850 | 22 | 65,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,851 | 22 | 65,702 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
from sys import stdin
from math import gcd
def lcm(a,b):
return a*b//gcd(a,b)
def exgcd(a,b)->(int,int,int):
if b == 0:
return (a,1,0)
d,x,y = exgcd(b,a%b)
t = x
x = y
y = t - (a//b)*y
return (d,x,y)
def cal(v:list)->int:
now = v[0]
for i in range(1,len(v)):
a = now[0]
b = -v[i][0]
c = v[i][1] - now[1]
g,x,y = exgcd(a,b)
x*=c//g
y*=c//g
lc = lcm(a,b)
now = (lc,(a*x+now[1])%lc)
return now[1]
def no():
print("NO")
exit(0)
def yes():
print("YES")
exit(0)
n,m,k = list(map(int,stdin.readline().split()))
a = list(map(int,stdin.readline().split()))
ll = a[0]
for x in a:
ll = lcm(ll,x)
if ll > n:
no()
v = [(x,x-i%x) for i,x in enumerate(a)]
ans = cal(v)
ans = ans%ll
if ans<=0:ans+=ll
if ans+k-1 > m:
no()
for i,x in enumerate(a):
if gcd(ll,ans+i)!=x:
no()
yes()
``` | output | 1 | 32,851 | 22 | 65,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,852 | 22 | 65,704 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
from math import gcd
def lcm(a, b):
if min(a, b) == 0: return max(a, b)
return a // gcd(a, b) * b
class equation():
def __init__(self, r, mod):
self.r = r
self.mod = mod
def goodBye():
print("NO")
exit(0)
def exgcd(a,b):
if b == 0:
return (1,0)
xp,yp = exgcd(b,a % b)
x = yp
y = xp-a // b * yp
return (x,y)
def merge(a, b):
newmode = lcm(a.mod,b.mod)
if (a.r-b.r)%gcd(a.mod,b.mod)!=0:
goodBye()
newr = exgcd(a.mod,b.mod)[0]*(b.r-a.r)//gcd(a.mod,b.mod)*a.mod+a.r
newr%=newmode
return equation(newr,newmode)
x, y = 0, 0
n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in a:
x = lcm(x, i)
if x>n:
goodBye()
cur = equation(0, 1)
for i in range(0, len(a)):
cur = merge(cur, equation((-i) % a[i], a[i]))
y = cur.r
if y == 0: y += x
for i in range(0, len(a)):
if gcd(x, y + i) != a[i]:
goodBye()
if x > n or y + k - 1 > m: goodBye()
print("YES")
``` | output | 1 | 32,852 | 22 | 65,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there. | instruction | 0 | 32,853 | 22 | 65,706 |
Tags: chinese remainder theorem, math, number theory
Correct Solution:
```
'''
Created on Aug 28, 2016
@author: Md. Rezwanul Haque
'''
def gcd(a,b):
if b == 0:
return a
return gcd(b, a%b)
def extend_euclid(a,b):
if b == 0:
return 1,0
else:
y,x = extend_euclid(b, a%b)
y = y - (a//b)*x
return x,y
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
lcm = 1
for i in a:
lcm = (lcm*i)//gcd(lcm, i)
if lcm>n:
print('NO')
exit()
j = 0
m1 = 1
s = True
for i in range(k):
x,y = extend_euclid(m1, a[i])
res = m1*x + a[i]*y
if (-i-j)%res != 0:
s = False
break
res = (-i-j)//res
x,y = x*res , y*res
j += m1*x
t = m1*a[i]
if j>t:
j -= (j//t)*t
if j<0:
j += ((-j+t-1)//t)*t
if j == 0:
j = t
m1 = (m1*a[i])//gcd(m1, a[i])
if j+k-1 >m or s == False:
print('NO')
exit()
b = [gcd(lcm, j+i) for i in range(k)]
for i in range(k):
if (a[i] != b[i]):
print('NO')
exit()
print('YES')
``` | output | 1 | 32,853 | 22 | 65,707 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
from math import gcd
def LCM(a, b):
if min(a, b) == 0: return max(a, b)
return a // gcd(a, b) * b
class Eqn():
def __init__(self, r, mod):
self.r = r
self.mod = mod
def bye():
print("NO")
exit(0)
def exgcd(a, b):
if b == 0:
return (1, 0)
xp, yp = exgcd(b, a % b)
x = yp
y = xp - a // b * yp
return (x, y)
def merge(a, b):
newmode = LCM(a.mod, b.mod)
if (a.r - b.r) % gcd(a.mod, b.mod) != 0:
bye()
newr = exgcd(a.mod, b.mod)[0] * (b.r - a.r) // gcd(a.mod, b.mod) * a.mod + a.r
newr %= newmode
return Eqn(newr, newmode)
x, y = 0, 0
n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in a:
x = LCM(x, i)
if x > n:
bye()
cur = Eqn(0, 1)
for i in range(0, len(a)):
cur = merge(cur, Eqn((-i) % a[i], a[i]))
y = cur.r
if y == 0: y += x
for i in range(0, len(a)):
if gcd(x, y + i) != a[i]:
bye()
if x > n or y + k - 1 > m: bye()
print("YES")
``` | instruction | 0 | 32,854 | 22 | 65,708 |
Yes | output | 1 | 32,854 | 22 | 65,709 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
def gcd(a,b):
if a<b:
c=b
b=a
a=c
while b!=0:
t=b
b=a%b
a=t
return int(a)
def extendedEuclides(a,b):
xx=y=0
yy=x=1
while b!=0:
q=int(a/b)
t=b
b=a%b
a=t
t=xx
xx=x-q*xx
x=t
t=yy
yy=y-q*yy
y=t
return [a,x,y]
def chineseRemainder(x,y,a,b):
[d,s,t]=extendedEuclides(x,y)
if(a%d!=b%d):
return [0,-1]
return [int(((s*b*x+t*a*y)%(x*y))/d),x*y/d]
[n,m,k]=input().split(' ')
n=eval(n)
m=eval(m)
k=eval(k)
arr=list(map(int,input().split(' ')))
I=1
for el in arr:
I=I*(el/gcd(I,el))
if I>n:
break
if I==1:
print("YES")
elif I>n:
print("NO")
else:
can=1
auxI=I
fat=[]
occur=[]
for i in range(2,1010000):
if auxI%i==0:
v=1
while auxI%i==0:
v=v*i
fat.append(v)
occur.append(-1)
auxI=int(auxI/i)
if auxI>1:
fat.append(auxI)
occur.append(-1)
for i,x in enumerate(fat):
for j in range(0,min(k,x)):
if(gcd(arr[j],x)==x):
occur[i]=j
if occur[i]==-1:
can=0
for i,x in enumerate(fat):
for j in range(0,k):
if ((gcd(arr[j],x)!=x and j%x==occur[i])or(gcd(arr[j],x)==x and j%x!=occur[i])):
can=0
I=1
J=1
lrem=0
for i,x in enumerate(fat):
rem=(x-occur[i])%x
g=gcd(I,x)
auxI=I*int(x/g)
xxx=chineseRemainder(I,x,lrem%I,rem)
lrem=xxx[0]
I=auxI
#print(lrem,rem,x,I)
if lrem==0:
lrem=I
if int(lrem)>m-k+1:
can=0
if can==0:
print('NO')
else:
print('YES')
# 1491583140056
``` | instruction | 0 | 32,855 | 22 | 65,710 |
Yes | output | 1 | 32,855 | 22 | 65,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
from math import gcd
def lcm(a, b):
if min(a, b) == 0: return max(a, b)
return a // gcd(a, b) * b
class equation():
def __init__(self, r, mod):
self.r = r
self.mod = mod
def goodBye():
print("NO")
exit(0)
def exgcd(a,b):
if b == 0:
return (1,0)
xp,yp = exgcd(b,a % b)
x = yp
y = xp-a // b * yp
return (x,y)
def merge(a, b):
newmode = lcm(a.mod,b.mod)
if (a.r-b.r)%gcd(a.mod,b.mod)!=0:
goodBye()
newr = exgcd(a.mod,b.mod)[0]*(b.r-a.r)//gcd(a.mod,b.mod)*a.mod+a.r
newr%=newmode
return equation(newr,newmode)
x, y = 0, 0
n, m, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in a:
x = lcm(x, i)
if x>n:
goodBye()
cur = equation(0, 1)
for i in range(0, len(a)):
cur = merge(cur, equation((-i) % a[i], a[i]))
y = cur.r
if y == 0: y += x
for i in range(0, len(a)):
# print("gcd and a[i] ", gcd(x, y + i), a[i])
if gcd(x, y + i) != a[i]:
goodBye()
if x > n or y + k - 1 > m: goodBye()
print("YES")
# 344579508000 6351696000
# 344579508000 154028628000
# 154028628000/6351696000
``` | instruction | 0 | 32,856 | 22 | 65,712 |
Yes | output | 1 | 32,856 | 22 | 65,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
def gcd(a,b):
if a<b:
c=b
b=a
a=c
while b!=0:
t=b
b=a%b
a=t
return int(a)
def extendedEuclides(a,b):
xx=y=0
yy=x=1
while b!=0:
q=int(a/b)
t=b
b=a%b
a=t
t=xx
xx=x-q*xx
x=t
t=yy
yy=y-q*yy
y=t
return [a,x,y]
def chineseRemainder(x,y,a,b):
[d,s,t]=extendedEuclides(x,y)
if(a%d!=b%d):
return [0,-1]
return [((s*b*x+t*a*y)%(x*y))/d,x*y/d]
[n,m,k]=input().split(' ')
n=eval(n)
m=eval(m)
k=eval(k)
arr=list(map(int,input().split(' ')))
I=1
for el in arr:
I=I*(el/gcd(I,el))
if I>n:
break
if I==1:
print("YES")
elif I>n:
print("NO")
else:
can=1
auxI=I
fat=[]
occur=[]
for i in range(2,1010000):
if auxI%i==0:
v=1
while auxI%i==0:
v*=i
fat.append(v)
occur.append(-1)
auxI=auxI/i
if auxI>1:
fat.append(auxI)
occur.append(-1)
for i,x in enumerate(fat):
for j in range(0,min(k,x)):
if(gcd(arr[j],x)==x):
occur[i]=j
if occur[i]==-1:
can=0
for i,x in enumerate(fat):
for j in range(0,k):
if ((gcd(arr[j],x)!=x and j%x==occur[i])or(gcd(arr[j],x)==x and j%x!=occur[i])):
can=0
I=1
J=1
lrem=0
for i,x in enumerate(fat):
rem=(x-occur[i])%x
g=gcd(I,x)
auxI=I*x/g
lrem=chineseRemainder(I,x,lrem%I,rem)[0]
I=auxI
if lrem==0:
lrem=I
if int(lrem)>m-k+1:
can=0
if can==0:
print('NO')
else:
print('YES')
``` | instruction | 0 | 32,857 | 22 | 65,714 |
No | output | 1 | 32,857 | 22 | 65,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
import math
def lcm(a,b):
return a*b// math.gcd(a,b)
def egcd(a,b):
if b==0: return (a, 1, 0)
g,x,y = egcd(b,a%b)
return (g, y, x - (a//b) * y)
def crt(a,m1,b,m2):
g,x,y = egcd(m1,m2)
if (b-a)%g!=0: return (0,-1)
m = m1 * m2 // g
r = (b-a) // g * x % (m2//g)
r = (a + m1 * r) % m
return (r, m)
def nel():
print("NO")
exit(0)
x,y,n = map(int,input().split())
v = list(map(int,input().split()))
mn = 1
for i in v:
mn = lcm(mn,i)
if mn > x: nel()
aux = (0, 1)
for i in range(0,n):
aux = crt(aux[0],aux[1],(-i % v[i] + v[i])%v[i], v[i])
if aux[1]==-1: nel()
if aux[0]==0: aux = (aux[1],aux[1])
if aux[0]+n>=y: nel()
for i,j in enumerate(v,0):
res = math.gcd(aux[0]+i,aux[1])
if res!=j: nel()
print("YES")
``` | instruction | 0 | 32,858 | 22 | 65,716 |
No | output | 1 | 32,858 | 22 | 65,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
from math import gcd
def lcm(a,b):
if min(a,b)==0:return max(a,b)
return a//gcd(a,b)*b
class equation():
def __init__(self,rr,mmod):
self.r = rr
self.mod = mmod
def goodBye():
print("NO")
exit(0)
def fastExp(base,power,mod):
ans = 1
while(power>0):
if(power%2==0):
power//=2
base = base*base%mod
else:
power-=1
ans = ans*base%mod
return ans
def modInverse(num,mod):
return fastExp(num,mod-2,mod)
def merge(a,b):
if(a.mod>b.mod):a,b = b,a
g = gcd(a.mod,b.mod)
a.mod//=g
a.r%=a.mod
if a.mod==1:return b
newr = b.mod*modInverse(b.mod,a.mod)*a.r + a.mod*modInverse(a.mod,b.mod)*b.r
newmod = a.mod*b.mod
newr%=newmod
return equation(newr,newmod)
x,y = 0,0
n,m,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in a:
x = lcm(x,i)
cur = equation(0,1)
for i in range(0,len(a)):
cur = merge(cur,equation((-i)%a[i],a[i]))
y = cur.r
if y==0:goodBye()
for i in range(0,len(a)):
if gcd(x,y+i)!=a[i]:
goodBye()
if x>n or y+k-1>m:goodBye()
print("YES")
``` | instruction | 0 | 32,859 | 22 | 65,718 |
No | output | 1 | 32,859 | 22 | 65,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider a table G of size n Γ m such that G(i, j) = GCD(i, j) for all 1 β€ i β€ n, 1 β€ j β€ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a1, a2, ..., ak. We say that this sequence occurs in table G if it coincides with consecutive elements in some row, starting from some position. More formally, such numbers 1 β€ i β€ n and 1 β€ j β€ m - k + 1 should exist that G(i, j + l - 1) = al for all 1 β€ l β€ k.
Determine if the sequence a occurs in table G.
Input
The first line contains three space-separated integers n, m and k (1 β€ n, m β€ 1012; 1 β€ k β€ 10000). The second line contains k space-separated integers a1, a2, ..., ak (1 β€ ai β€ 1012).
Output
Print a single word "YES", if the given sequence occurs in table G, otherwise print "NO".
Examples
Input
100 100 5
5 2 1 2 1
Output
YES
Input
100 8 5
5 2 1 2 1
Output
NO
Input
100 100 7
1 2 3 4 5 6 7
Output
NO
Note
Sample 1. The tenth row of table G starts from sequence {1, 2, 1, 2, 5, 2, 1, 2, 1, 10}. As you can see, elements from fifth to ninth coincide with sequence a.
Sample 2. This time the width of table G equals 8. Sequence a doesn't occur there.
Submitted Solution:
```
def gcd(a,b):
if a<b:
c=b
b=a
a=c
while b!=0:
t=b
b=a%b
a=t
return a
def extendedEuclides(a,b):
xx=y=0
yy=x=1
while b!=0:
q=int(a/b)
t=b
b=a%b
a=t
t=xx
xx=x-q*xx
x=t
t=yy
yy=y-q*yy
y=t
return [a,x,y]
def chineseRemainder(x,y,a,b):
[d,s,t]=extendedEuclides(x,y)
if(a%d!=b%d):
return [0,-1]
return [((s*b*x+t*a*y)%(x*y))/d,x*y/d]
[n,m,k]=input().split(' ')
n=eval(n)
m=eval(m)
k=eval(k)
arr=list(map(int,input().split(' ')))
I=1
for el in arr:
I=I*el/gcd(I,el)
if I>n:
break
if I==1:
print("YES")
elif I>n:
if k>5000:
print(I)
print("NO")
else:
can=1
auxI=I
fat=[]
occur=[]
for i in range(2,1010000):
if auxI%i==0:
v=1
while auxI%i==0:
v*=i
fat.append(v)
occur.append(-1)
auxI=auxI/i
if auxI>1:
fat.append(auxI)
occur.append(-1)
for i,x in enumerate(fat):
for j in range(0,min(k,x)):
if(gcd(arr[j],x)==x):
occur[i]=j
if occur[i]==-1:
can=0
for i,x in enumerate(fat):
for j in range(0,k):
if ((gcd(arr[j],x)!=x and j%x==occur[i])or(gcd(arr[j],x)==x and j%x!=occur[i])):
can=0
I=1
J=1
lrem=0
for i,x in enumerate(fat):
rem=(x-occur[i])%x
g=gcd(I,x)
auxI=I*x/g
lrem=chineseRemainder(I,x,lrem%I,rem)[0]%auxI
I=auxI
if lrem==0:
lrem=I
if lrem>m-k+1:
can=0
if can==0:
print('NO')
else:
print('YES')
``` | instruction | 0 | 32,860 | 22 | 65,720 |
No | output | 1 | 32,860 | 22 | 65,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,956 | 22 | 65,912 |
Tags: geometry, math
Correct Solution:
```
a, b = map(int, input().split())
if b > a:
print(-1)
else:
x1 = a + b
x = b
print(x1 / (2 * (x1 // (2 * x))))
``` | output | 1 | 32,956 | 22 | 65,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,957 | 22 | 65,914 |
Tags: geometry, math
Correct Solution:
```
from decimal import *
import math
getcontext().prec=50
a,b=map(Decimal, input().split())
if b>a:
print (-1)
else:
cur=-1
if (a+b)%2==0:
cur=(a+b)//2
else:
cur=(a+b)/Decimal(2)
print(cur/math.floor(cur/b))
``` | output | 1 | 32,957 | 22 | 65,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,958 | 22 | 65,916 |
Tags: geometry, math
Correct Solution:
```
import sys
a,b = map(int,input().split())
if a<b:
print(-1)
sys.exit(0)
k = int(((a/b)+1)/2)
z = 2*k*b/(a+b)
print(a/(2*k-z))
``` | output | 1 | 32,958 | 22 | 65,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,959 | 22 | 65,918 |
Tags: geometry, math
Correct Solution:
```
from fractions import Fraction
def solve(a, b):
x = Fraction(b)
n = a // (x*2)
a_ = a % (x*2)
if b > a:
return -1
if a_ == x:
return float(x)
if a_ < x:
return float((a+b)/(2*n))
if a_ > x:
return float((a+b)/(2*n+2))
a, b = map(Fraction, input().split())
print(solve(a, b))
``` | output | 1 | 32,959 | 22 | 65,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,960 | 22 | 65,920 |
Tags: geometry, math
Correct Solution:
```
a,b = list(map(int,input().split()))
if b > a:
print(-1)
else:
try:
x= 100000000000
k = int((a+b)/2/b)
if k != 0:
x = (a+b)/2/k
k = int((a-b)/2/b)
if k != 0:
x = min(x,(a-b)/2/k)
print("%.9f"%x)
except:
print(-1)
``` | output | 1 | 32,960 | 22 | 65,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,961 | 22 | 65,922 |
Tags: geometry, math
Correct Solution:
```
#!/usr/bin/env python3
import collections, itertools, fractions, functools, heapq, math, queue
def solve():
a, b = map(int, input().split())
if a < b:
return -1
return (a+b)/(2*((a+b)//(2*b)))
if __name__ == '__main__':
print(solve())
``` | output | 1 | 32,961 | 22 | 65,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,962 | 22 | 65,924 |
Tags: geometry, math
Correct Solution:
```
# problem statement: https://codeforces.com/problemset/problem/578/A
coord = input()
a, b = list(map(int, coord.split()))
if b > a:
print(-1)
else:
sol1 = (a + b)/(2 * int((a+b)/(2*b)))
print(sol1)
``` | output | 1 | 32,962 | 22 | 65,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image> | instruction | 0 | 32,963 | 22 | 65,926 |
Tags: geometry, math
Correct Solution:
```
import sys
a, b = list(map(int, sys.stdin.readline().split()))
if b > a :
print(-1)
elif b == a:
print(a)
else:
t = (a+b)/(2*int((a+b)/b/2))
print(t)
``` | output | 1 | 32,963 | 22 | 65,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There is a polyline going through points (0, 0) β (x, x) β (2x, 0) β (3x, x) β (4x, 0) β ... - (2kx, 0) β (2kx + x, x) β ....
We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or determine that there is no such x.
Input
Only one line containing two positive integers a and b (1 β€ a, b β€ 109).
Output
Output the only line containing the answer. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9. If there is no such x then output - 1 as the answer.
Examples
Input
3 1
Output
1.000000000000
Input
1 3
Output
-1
Input
4 1
Output
1.250000000000
Note
You can see following graphs for sample 1 and sample 3.
<image> <image>
Submitted Solution:
```
from math import ceil, log, floor, sqrt
import math
def mod_expo(n, p, m):
"""find (n^p)%m"""
result = 1
while p != 0:
if p%2 == 1:
result = (result * n)%m
p //= 2
n = (n * n)%m
return result
def is_prime(n):
m = 2
while m*m <= n:
if n%m == 0:
return False
m += 1
return True
def get_x(x, y):
x0 = -1
num = (x-y)
k = 1
while True:
cur = num/(2*k)
if cur < y:
l = x0
break
x0 = cur
# print(x0)
k += 1
x0 = -1
num = (x+y)
k = 1
while True:
cur = num/(2*k + 2)
if cur < y:
r = x0
break
x0 = cur
# print(x0)
k += 1
if l == -1:
return r
if r == -1:
return l
return min(l, r)
def discover():
for i in range(24, 60):
if is_prime(i):
if not is_prime(pow(2, i)-1):
print(i)
return False
return True
t = 1
#t = int(input())
while t:
t = t - 1
points = []
#n = int(input())
a, b = map(int, input().split())
#print(discover())
# = map(int, input().split())
#arr = list(map(int, input().strip().split()))[:n]
#w = list(map(int, input().strip().split()))[:k]
#for i in range(3):
# x, y = map(int, input().split())
# points.append((x, y))
#s = input()
#if happy_guests(a, b, n, m):
# print("Yes")
# else:
# print("No")
#print(get_res(s))
#print(get_x(a, b))
print("{:.10f}".format(get_x(a, b)))
``` | instruction | 0 | 32,968 | 22 | 65,936 |
No | output | 1 | 32,968 | 22 | 65,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya studies divisibility rules at school. Here are some of them:
* Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even.
* Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible by 3.
* Divisibility by 4. A number is divisible by 4 if and only if its last two digits form a number that is divisible by 4.
* Divisibility by 5. A number is divisible by 5 if and only if its last digit equals 5 or 0.
* Divisibility by 6. A number is divisible by 6 if and only if it is divisible by 2 and 3 simultaneously (that is, if the last digit is even and the sum of all digits is divisible by 3).
* Divisibility by 7. Vasya doesn't know such divisibility rule.
* Divisibility by 8. A number is divisible by 8 if and only if its last three digits form a number that is divisible by 8.
* Divisibility by 9. A number is divisible by 9 if and only if the sum of its digits is divisible by 9.
* Divisibility by 10. A number is divisible by 10 if and only if its last digit is a zero.
* Divisibility by 11. A number is divisible by 11 if and only if the sum of digits on its odd positions either equals to the sum of digits on the even positions, or they differ in a number that is divisible by 11.
Vasya got interested by the fact that some divisibility rules resemble each other. In fact, to check a number's divisibility by 2, 4, 5, 8 and 10 it is enough to check fulfiling some condition for one or several last digits. Vasya calls such rules the 2-type rules.
If checking divisibility means finding a sum of digits and checking whether the sum is divisible by the given number, then Vasya calls this rule the 3-type rule (because it works for numbers 3 and 9).
If we need to find the difference between the sum of digits on odd and even positions and check whether the difference is divisible by the given divisor, this rule is called the 11-type rule (it works for number 11).
In some cases we should divide the divisor into several factors and check whether rules of different types (2-type, 3-type or 11-type) work there. For example, for number 6 we check 2-type and 3-type rules, for number 66 we check all three types. Such mixed divisibility rules are called 6-type rules.
And finally, there are some numbers for which no rule works: neither 2-type, nor 3-type, nor 11-type, nor 6-type. The least such number is number 7, so we'll say that in such cases the mysterious 7-type rule works, the one that Vasya hasn't discovered yet.
Vasya's dream is finding divisibility rules for all possible numbers. He isn't going to stop on the decimal numbers only. As there are quite many numbers, ha can't do it all by himself. Vasya asked you to write a program that determines the divisibility rule type in the b-based notation for the given divisor d.
Input
The first input line contains two integers b and d (2 β€ b, d β€ 100) β the notation system base and the divisor. Both numbers are given in the decimal notation.
Output
On the first output line print the type of the rule in the b-based notation system, where the divisor is d: "2-type", "3-type", "11-type", "6-type" or "7-type". If there are several such types, print the one that goes earlier in the given sequence. If a number belongs to the 2-type, print on the second line the least number of the last b-based digits that we will need to use to check the divisibility.
Examples
Input
10 10
Output
2-type
1
Input
2 3
Output
11-type
Note
The divisibility rule for number 3 in binary notation looks as follows: "A number is divisible by 3 if and only if the sum of its digits that occupy the even places differs from the sum of digits that occupy the odd places, in a number that is divisible by 3". That's an 11-type rule. For example, 2110 = 101012. For it the sum of digits on odd positions equals 1 + 1 + 1 = 3, an on even positions β 0 + 0 = 0. The rule works and the number is divisible by 3.
In some notations a number can fit into the 3-type rule and the 11-type rule. In this case the correct answer is "3-type". | instruction | 0 | 33,629 | 22 | 67,258 |
Tags: math, number theory
Correct Solution:
```
b, d = map(int, input().split())
for i in range(1, 10):
if (b**i) % d == 0:
print("2-type")
print(i)
exit()
if (b-1) % d == 0:
print("3-type")
exit()
if (b+1) % d == 0:
print("11-type")
exit()
for i in range(2, d+1):
if d % i == 0:
x = 1
while d % i == 0:
d /= i
x *= i
if (b**10) % x != 0 and (b+1) % x != 0 and (b-1) % x != 0:
print("7-type")
break
else:
print("6-type")
``` | output | 1 | 33,629 | 22 | 67,259 |
Provide a correct Python 3 solution for this coding contest problem.
You survived several months of exam wars and were able to enter ICPC University on a sunny day. On the day of admission, there was an enthusiastic recruitment of circles on the campus of the university, and you received a large number of pamphlets and returned. When you return to your room, you find one of the pamphlets you received that interests you. The pamphlet was given by the university's public relations department.
The following problems were described in the pamphlet.
> How many combinations of two or more consecutive positive integers have a sum of N? For example, 9 has two combinations, 2 + 3 + 4 and 4 + 5.
If you were curious about the answer to this question, you decided to write a program to find out the answer. Therefore, your job is to write a program that outputs the answer to the problem for the positive integer N given as the input.
Input
The input is a sequence of datasets. Each dataset is a line of one integer N. Where 1 β€ N β€ 1000.
The end of the input is indicated by a single line of zeros.
Output
The output is the order of the input datasets, which is the answer to the question for the positive integers represented by each dataset of the inputs. No other characters should be in the output.
Example
Input
9
500
0
Output
2
3 | instruction | 0 | 34,207 | 22 | 68,414 |
"Correct Solution:
```
import math
def get_one_int()->int:
one_int = int(input())
return one_int
def make_divisors(num:int)->set:
divisors = set()
for i in range(1, math.floor(num ** 0.5) + 1):
if num % i == 0:
divisors.add(i)
divisors.add(num // i)
return divisors
def count_odd_num(num_set)->int:
odd_num = 0
for i in num_set:
if i % 2 != 0:
odd_num += 1
return odd_num
if __name__ == "__main__":
while True:
given_num = get_one_int()
if given_num == 0:
break
divisors = make_divisors(given_num)
odd_num = count_odd_num(divisors)
odd_num -= 1 # remove 1
print(odd_num)
``` | output | 1 | 34,207 | 22 | 68,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two positive integers a and b. In one move you can increase a by 1 (replace a with a+1). Your task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible, that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains two integers a and b (1 β€ a, b β€ 10^9).
Output
For each test case print the answer β the minimum number of moves you need to do in order to make a divisible by b.
Example
Input
5
10 4
13 9
100 13
123 456
92 46
Output
2
5
4
333
0 | instruction | 0 | 34,422 | 22 | 68,844 |
Tags: math
Correct Solution:
```
def main():
n = int(input())
while n > 0:
a,b = [int(x) for x in input().split()]
c = (b - a%b) % b
print(c)
n = n - 1
if __name__ == '__main__':
main()
``` | output | 1 | 34,422 | 22 | 68,845 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.