message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this:
1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1
Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime.
Input
Input contains several test cases. Each test case consists of an integer N in one line.
Output
For each line of input, output P .
Example
Input
1
4
7
51
Output
0
2
2
6
Submitted Solution:
```
primes = [0, 0] + [1] * 9999
for i in range(2, 101):
if primes[i]:
for j in range(i*i, 10001, i):
primes[j] = 0
while True:
try:
N = int(input())
except:
break
print(sum(primes[i] & primes[-i] for i in range(1, N+1)))
``` | instruction | 0 | 68,071 | 22 | 136,142 |
No | output | 1 | 68,071 | 22 | 136,143 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing order and decreasing order like this:
1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1
Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both numbers in the pairs are prime.
Input
Input contains several test cases. Each test case consists of an integer N in one line.
Output
For each line of input, output P .
Example
Input
1
4
7
51
Output
0
2
2
6
Submitted Solution:
```
import math
def ifprime(num):
if num == 1:
return False
for i in range(2,math.floor(num ** 0.5) + 1):
if num % i:
continue
else:
return False
return True
while(True):
try:
num = int(input())
except:
break
if num % 2 == 0:
print(0)
continue
count = 0
for i in range(1,num+1):
if ifprime(i) and ifprime(num+1-i):
count += 1
print(count)
``` | instruction | 0 | 68,072 | 22 | 136,144 |
No | output | 1 | 68,072 | 22 | 136,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,143 | 22 | 136,286 |
Tags: implementation, math
Correct Solution:
```
import sys
input = sys.stdin.readline
from collections import Counter
n,k=map(int,input().split())
A=list(map(int,input().split()))
D=[Counter() for i in range(11)]
for a in A:
for j in range(1,11):
D[j][a*(10**j)%k]+=1
ANS=0
for a in A:
L=len(str(a))
x=-a%k
if a*(10**L)%k==x:
ANS-=1
ANS+=D[L][x]
print(ANS)
``` | output | 1 | 68,143 | 22 | 136,287 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,144 | 22 | 136,288 |
Tags: implementation, math
Correct Solution:
```
try:
while True:
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
dic = {}
for idx in range(n):
l = len(str(arr[idx]))
r = arr[idx] % k
dic[(l, r)] = dic.get((l, r), 0) + 1
res = 0
for i in range(n):
for j in range(1,11):
cur = arr[i] * int(pow(10, j))
cr = cur % k
l = len(str(arr[i]))
r = arr[i] % k
res += dic.get((j, (k-cr) % k), 0) - ( (l, r) == (j, (k-cr) % k))
print(res)
except Exception as e:
pass
``` | output | 1 | 68,144 | 22 | 136,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,145 | 22 | 136,290 |
Tags: implementation, math
Correct Solution:
```
n, k = map(int, input().split())
v = list(map(int, input().split()))
d = {}
ans = 0
for x in v:
num_d, mod_k = len(str(x)), x % k
d.setdefault(num_d, {}).setdefault(mod_k, []).append(x)
for x in v:
num_d, mod_k = len(str(x)), x % k
for add, mods in d.items():
val_mod = (mod_k * 10 ** add) % k
need_mod = (k - val_mod) % k
ans += len(mods.get(need_mod, []))
if need_mod == mod_k and add == num_d:
ans -= 1
print(ans)
``` | output | 1 | 68,145 | 22 | 136,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,146 | 22 | 136,292 |
Tags: implementation, 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():
n,k = map(int,input().split())
a = input().split()
a1 = list(map(int,a))
dct = [Counter() for _ in range(11)]
for i in range(n):
dct[len(a[i])][a1[i]%k] += 1
ans = 0
for i in range(n):
x = a1[i]
for j in range(1,11):
x = (x*10)%k
if x:
ans += dct[j][k-x]
else:
ans += dct[j][0]
if not (a1[i]*(pow(10,len(a[i]),k)+1))%k:
ans -= 1
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 | 68,146 | 22 | 136,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,147 | 22 | 136,294 |
Tags: implementation, math
Correct Solution:
```
import sys
from collections import Counter as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,k=I()
l=I()
ar=[i%k for i in l]
ans=[]
dv=cc(ar)
for i in range(1,12):
x=[(j*(10**i))%k for j in l]
ans.append(cc(x))
dv=cc(ar)
an=0
if k==2:
an=dv[0]*(dv[1])+dv[0]*(dv[0]-1)
else:
for i in range(n):
d1=(k-ar[i])%k
mu=len(str(l[i]))
an+=ans[mu-1][d1]
#print(l[i],ans[mu-1][d1],d1,l[i]*mu)
if d1==(l[i]*(10**mu)%k):
an-=1
print(an)
``` | output | 1 | 68,147 | 22 | 136,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,148 | 22 | 136,296 |
Tags: implementation, math
Correct Solution:
```
def main():
n, k = map(int, input().split())
aa, cnt, res = [], {}, 0
scale = [10 ** i + 1 for i in range(11)]
for w in input().split():
a, s = int(w), len(w)
aa.append(a)
if not a * scale[s] % k:
res -= 1
t = (s, a % k)
cnt[t] = cnt.get(t, 0) + 1
scale = [1 - i for i in scale]
for a in aa:
for s in range(1, 11):
x = a * scale[s] % k
res += cnt.get((s, x), 0)
print(res)
if __name__ == '__main__':
main()
``` | output | 1 | 68,148 | 22 | 136,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,149 | 22 | 136,298 |
Tags: implementation, math
Correct Solution:
```
from collections import Counter
c=[Counter() for i in range(11)]
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [[] for i in range(11)]
for j in range(n):
b[len(str(a[j]))].append(a[j])
for i in range(1, 11):
r=(a[j] * (10 ** i))%k
c[i][r]+=1
s = 0
for i in range(11):
y = b[i]
for j in range(len(y)):
p = y[j] % k
if p == 0:
p = k
p = k - p
r = y[j] * (10 ** i) + y[j]
if r % k == 0:
s += c[i][p] - 1
else:
s += c[i][p]
print(s)
``` | output | 1 | 68,149 | 22 | 136,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient. | instruction | 0 | 68,150 | 22 | 136,300 |
Tags: implementation, math
Correct Solution:
```
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
for i in range(n):
l = len(str(a[i]))
y = a[i] % k
d[(l, y)] = d.get((l, y), 0) + 1
res = 0
for i in range(n):
for j in range(1, 11):
cur = a[i] * int(pow(10, j))
cur_l = len(str(a[i]))
cur_y = a[i] % k
y = cur % k
if (j, (k - y) % k) in d:
#print(a[i], cur, j, d[(j, (k-y)%k)])
res += d[(j, (k-y)%k)]
if (cur_l, cur_y) == (j, (k-y)%k):
res -= 1
print(res)
``` | output | 1 | 68,150 | 22 | 136,301 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
from math import log
from collections import deque
n,k=map(int,input().split())
s=list(map(int,input().split()))
ans=0
s.sort()
s1=deque(s)
for j in range(11):
d=dict()
z=10**j
for i in s:
y=i*z
u=y%k
if u in d:
d[u]+=1
else:
d.update({u:1})
aux=0
for i in s1:
y=i
lg=int(log(i,10))+1
lg=10**lg
if lg==z:
aux1=(y*z)%k
aux2=y%k
d[aux1]-=1
x=(k-aux2)
if aux2==0:
x=0
if x in d:
ans+=d[x]
d[aux1]+=1
aux+=1
else:
break
for i in range(aux):
s1.popleft()
print(ans)
``` | instruction | 0 | 68,152 | 22 | 136,304 |
Yes | output | 1 | 68,152 | 22 | 136,305 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
n, k = map(int, input().split())
nums = list(map(int, input().split()))
counts = [{} for _ in range(11)]
for n in nums:
a = n
for i in range(11):
r = a % k
try:
counts[i][r] += 1
except KeyError:
counts[i][r] = 1
a *= 10
res = 0
for i in nums:
wo = str(i)
le = len(wo)
mimo = (k-(i % k)) % k
if mimo in counts[le]:
res += counts[le][mimo]
if int(wo+wo) % k == 0:
res -= 1
print(res)
``` | instruction | 0 | 68,153 | 22 | 136,306 |
Yes | output | 1 | 68,153 | 22 | 136,307 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
n, k = map(int, input().split())
A = list(map(int, input().split()))
table = [0]*15
table[0]= 1
for i in range(1, 15):
table[i] = 10*table[i-1]
table[i] %= k
from collections import defaultdict
D = [defaultdict(lambda:0) for _ in range(11)]
for a in A:
j = len(str(a))
D[j][a%k] += 1
ans = 0
for a in A:
for j in range(11):
t = -a*table[j]
t %= k
ans += D[j][t]
j = len(str(a))
if (a*table[j]+a)%k == 0:
ans -= 1
print(ans)
``` | instruction | 0 | 68,154 | 22 | 136,308 |
Yes | output | 1 | 68,154 | 22 | 136,309 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
import sys
input=sys.stdin.readline
l=input().split()
n=int(l[0])
k=int(l[1])
tot=[dict() for i in range(11)]
l=input().split()
li=[(int(i),len(i)) for i in l]
for i in li:
z=i[0]
if(z%k in tot[0]):
tot[0][z%k]+=1
else:
tot[0][z%k]=1
for j in range(1,11):
z=z*10
if(z%k in tot[j]):
tot[j][z%k]+=1
else:
tot[j][z%k]=1
ans=0
for i in li:
z=i[0]
y=i[1]
a=z%k
a=k-a
if(a==k):
a-=k
if(a in tot[y]):
ans+=tot[y][a]
for i in li:
z=i[0]
y=i[1]
if((z*pow(10,y)+z)%k==0):
ans-=1
print(ans)
``` | instruction | 0 | 68,155 | 22 | 136,310 |
Yes | output | 1 | 68,155 | 22 | 136,311 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
n, k = map(int, input().split())
nums = list(map(int, input().split()))
counts = [{} for _ in range(11)]
for n in nums:
a = n
for i in range(10):
r = a % k
try:
counts[i][r] += 1
except KeyError:
counts[i][r] = 1
a *= 10
res = 0
for i in nums:
wo = str(i)
le = len(wo)
mimo = (k-(i % k)) % k
if mimo in counts[le]:
res += counts[le][mimo]
if int(wo+wo) % k == 0:
res -= 1
print(res)
``` | instruction | 0 | 68,156 | 22 | 136,312 |
No | output | 1 | 68,156 | 22 | 136,313 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
for j in range(11):
b.append([[], []])
for j in range(n):
b[len(str(a[j]))][1].append(a[j])
for i in range(1,10):
b[i][0].append(a[j] * (10 ** i))
s = 0
for i in range(1,10):
d = dict()
x = b[i][0]
y = b[i][1]
for j in range(len(x)):
if x[j] % k in d.keys():
d[x[j] % k] += 1
else:
d[x[j] % k] = 1
for j in range(len(y)):
p = y[j] % k
if p == 0:
p = k
p = k - p
if p in d.keys():
r = y[j]*(10**i) + y[j]
if r % k == 0:
s += d[p]-1
else:
s+=d[p]
print(s)
``` | instruction | 0 | 68,157 | 22 | 136,314 |
No | output | 1 | 68,157 | 22 | 136,315 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
from math import log
from collections import deque
n,k=map(int,input().split())
s=list(map(int,input().split()))
ans=0
s.sort()
s1=deque(s)
for j in range(10):
d=dict()
z=10**j
for i in s:
y=i*z
u=y%k
if u in d:
d[u]+=1
else:
d.update({u:1})
aux=0
for i in s1:
y=i
lg=int(log(i,10))+1
lg=10**lg
if lg==z:
aux1=(y*z)%k
aux2=y%k
d[aux1]-=1
x=(k-aux2)
if aux2==0:
x=0
if x in d:
ans+=d[x]
d[aux1]+=1
aux+=1
else:
break
for i in range(aux):
s1.popleft()
print(ans)
``` | instruction | 0 | 68,158 | 22 | 136,316 |
No | output | 1 | 68,158 | 22 | 136,317 |
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, consisting of n positive integers.
Let's call a concatenation of numbers x and y the number that is obtained by writing down numbers x and y one right after another without changing the order. For example, a concatenation of numbers 12 and 3456 is a number 123456.
Count the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 2 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).
Output
Print a single integer — the number of ordered pairs of positions (i, j) (i ≠ j) in array a such that the concatenation of a_i and a_j is divisible by k.
Examples
Input
6 11
45 1 10 12 11 7
Output
7
Input
4 2
2 78 4 10
Output
12
Input
5 2
3 7 19 3 3
Output
0
Note
In the first example pairs (1, 2), (1, 3), (2, 3), (3, 1), (3, 4), (4, 2), (4, 3) suffice. They produce numbers 451, 4510, 110, 1045, 1012, 121, 1210, respectively, each of them is divisible by 11.
In the second example all n(n - 1) pairs suffice.
In the third example no pair is sufficient.
Submitted Solution:
```
n, k = map(int, input().split())
A = list(map(int, input().split()))
import math
g = math.gcd(10, k)
if g != 1:
ans = 0
for a in A:
if a%k == 0:
ans += n-1
print(ans)
exit()
def xgcd(a, b):
x0, y0, x1, y1 = 1, 0, 0, 1
while b != 0:
q, a, b = a // b, b, a % b
x0, x1 = x1, x0 - q * x1
y0, y1 = y1, y0 - q * y1
return a, x0, y0
def modinv(a, m):
g, x, y = xgcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
table = [0]*15
table[0]= 1
for i in range(1, 15):
table[i] = 10*table[i-1]
table[i] %= k
tableinv = [0]*15
for i in range(15):
tableinv[i] = modinv(table[i], k)
tableinv[i] %= k
#print(table)
#print(tableinv)
from collections import defaultdict
d1 = defaultdict(lambda: 0)
d2 = defaultdict(lambda: 0)
ans = 0
for a in A:
l = len(str(a))
t = -a*tableinv[l]
t %= k
s = a%k
ans += d1[t]
ans += d2[s]
d1[s] += 1
d2[t] += 1
print(ans)
``` | instruction | 0 | 68,159 | 22 | 136,318 |
No | output | 1 | 68,159 | 22 | 136,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,278 | 22 | 136,556 |
Tags: math
Correct Solution:
```
N = int(input())
for i in range(N):
n, k = map(int, input().split())
if k&1 != n&1 or k**2 > n:
print('NO')
else:
print('YES')
``` | output | 1 | 68,278 | 22 | 136,557 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,279 | 22 | 136,558 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
n,k = map(int,input().split())
if k*k > n or n%2 != k%2:
print("NO")
else:
print("YES")
``` | output | 1 | 68,279 | 22 | 136,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,280 | 22 | 136,560 |
Tags: math
Correct Solution:
```
for x in range(int(input())):
n,k = map(int, input().split())
print('YES'if k*k <= n and n%2 == k%2 else 'NO')
``` | output | 1 | 68,280 | 22 | 136,561 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,281 | 22 | 136,562 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(t):
n,k=map(int, input().split())
if n%2==0:
if k!=1 and k%2==0 and n>=k**2:
print('YES')
else :
print('NO')
else:
if k%2>0 and n>=k**2:
print('YES')
else:
print('NO')
``` | output | 1 | 68,281 | 22 | 136,563 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,282 | 22 | 136,564 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(t):
n,k=map(int,input().split())
result="YES"
if (n%2==0 and k%2==0) or (n%2!=0 and k%2!=0):
if k**2>n:
result="NO"
else:
result="NO"
print(result)
``` | output | 1 | 68,282 | 22 | 136,565 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,283 | 22 | 136,566 |
Tags: math
Correct Solution:
```
for i in range(int(input())):
n,k=map(int,input().split())
value=n - (k-1)**2
p=2*k-1
if(value>=p and value%2==1):
print("YES")
else:
print("NO")
``` | output | 1 | 68,283 | 22 | 136,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,284 | 22 | 136,568 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(0,t):
n,k=map(int,input().split())
s=k*k
if n%2==0 and k%2==0 and s<=n: #even case
print('Yes')
elif n%2!=0 and k%2!=0 and n>=s: #odd case
print('Yes')
else:
print('No')
``` | output | 1 | 68,284 | 22 | 136,569 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers. | instruction | 0 | 68,285 | 22 | 136,570 |
Tags: math
Correct Solution:
```
t = int(input())
c = 0
for i in range(t):
a,b = input().split()
a = int(a)
b = int(b)
#c = a+b
if ((a%2)==(b%2))and(b**2<=a):
print("YES")
else:
print("NO")
``` | output | 1 | 68,285 | 22 | 136,571 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
def swap(lt,a,b):
temp = lt[a]
lt[a] = lt[b]
lt[b] = temp
import math
q= int(input())
for x in range(q):
a,b = map(int,input().split(" "))
if(a%2 == b%2 and b<=int(math.floor(a**(0.5)))):
print("YES")
else:
print("NO")
``` | instruction | 0 | 68,286 | 22 | 136,572 |
Yes | output | 1 | 68,286 | 22 | 136,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
o = ((2 * k ) * k) / 2
if (n%2) == 0 and (k%2) == 1:
print("NO")
elif (n%2) == 1 and (k%2) == 0:
print("NO")
elif o <= n:
print("YES")
else:
print("NO")
``` | instruction | 0 | 68,287 | 22 | 136,574 |
Yes | output | 1 | 68,287 | 22 | 136,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
for _ in range(int(input())):
n, k = (int(x) for x in input().split())
nn = k
s = (nn*(2+(nn-1)*2)) >> 1
if s <= n and k % 2 == 0 and n % 2 == 0:
ans = "YES"
elif s <= n and k % 2 == 1 and n % 2 == 1:
ans = "YES"
else:
ans = "NO"
print(ans)
``` | instruction | 0 | 68,288 | 22 | 136,576 |
Yes | output | 1 | 68,288 | 22 | 136,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input
def main(t = 1):
for i in range(t):
n,k = map(int,input().split())
if k**2>n or k%2!=n%2:
print('NO')
else:
print('YES')
main(int(input()))
``` | instruction | 0 | 68,289 | 22 | 136,578 |
Yes | output | 1 | 68,289 | 22 | 136,579 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
try:
from sys import stdin,stdout
import math
import numbers
for _ in range(int(stdin.readline())):
n,k = map(int,stdin.readline().split())
if n&1:
if k&1:
stdout.write("YES"+"\n")
else:
stdout.write("NO"+"\n")
else:
if k&1:
stdout.write("NO"+"\n")
else:
stdout.write("YES"+"\n")
except:
pass
``` | instruction | 0 | 68,290 | 22 | 136,580 |
No | output | 1 | 68,290 | 22 | 136,581 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
for _ in range(int(input())):
n,k=map(int,input().split())
ans='YES'
if k>n:
ans='NO'
elif (n+k)%2!=0:
ans="NO"
print(ans)
``` | instruction | 0 | 68,291 | 22 | 136,582 |
No | output | 1 | 68,291 | 22 | 136,583 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
def check(a, b):
if a < b:
return "NO"
Sum = (a-(b-1)*(2*b-2)//2)%2
if (Sum > 0 and Sum%2!=0) or a==b**2:
return "YES"
return "NO"
t = int(input())
for i in range(t):
a = list(map (int, input().strip().split()))
print(check(a[0], a[1]))
``` | instruction | 0 | 68,292 | 22 | 136,584 |
No | output | 1 | 68,292 | 22 | 136,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given two integers n and k. Your task is to find if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers or not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases.
The next t lines describe test cases. The only line of the test case contains two integers n and k (1 ≤ n, k ≤ 10^7).
Output
For each test case, print the answer — "YES" (without quotes) if n can be represented as a sum of k distinct positive odd (not divisible by 2) integers and "NO" otherwise.
Example
Input
6
3 1
4 2
10 3
10 2
16 4
16 5
Output
YES
YES
NO
YES
YES
NO
Note
In the first test case, you can represent 3 as 3.
In the second test case, the only way to represent 4 is 1+3.
In the third test case, you cannot represent 10 as the sum of three distinct positive odd integers.
In the fourth test case, you can represent 10 as 3+7, for example.
In the fifth test case, you can represent 16 as 1+3+5+7.
In the sixth test case, you cannot represent 16 as the sum of five distinct positive odd integers.
Submitted Solution:
```
def judge(n,k):
if n < k:
return 'NO'
elif n % 2 == 0 and k % 2 == 0 or n % 2 != 0 and k % 2 != 0:
return 'YES'
else:
return 'NO'
num = int(input())
for i in range(num):
numbers = input().split()
n,k = int(numbers[0]),int(numbers[1])
print(judge(n,k))
``` | instruction | 0 | 68,293 | 22 | 136,586 |
No | output | 1 | 68,293 | 22 | 136,587 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,575 | 22 | 137,150 |
Tags: math, number theory
Correct Solution:
```
# from dust i have come, dust i will be
mod=int(1e9)+7
A,B,n,x=map(int,input().split())
'''
if we expand the given formula for some test cases
e.g-> for n=2,3,4.. we get
A^n*x + B(A^0+A^1+...+A^{n-1})
for the geometric progression, 1+r+r^2+...+r^{n-1}
the ans=(r^n-1)/(r-1) when r>1, if r==1, ans=nr
'''
if n==0:
print(x)
exit(0)
if A==1:
temp=n*A
else:
'''
(A/B)%m=(A%m*(B^-1)%m)%m
'''
x1=pow(A,n,mod)-1
x2=pow(A-1,mod-2,mod)
temp=(x1*x2)% mod
p1=pow(A,n,mod)*pow(x,1,mod)
p1=p1%mod
p2=(B%mod)*temp
p2=p2%mod
print((p1+p2)%mod)
``` | output | 1 | 68,575 | 22 | 137,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,576 | 22 | 137,152 |
Tags: math, number theory
Correct Solution:
```
MOD=10**9+7
a,b,n,x=map(int,input().split())
t=pow(a,n,MOD*max(1,a-1))
print((t*x+b*(t-1)//(a-1))%MOD if a-1else(x+n*b)%MOD)
``` | output | 1 | 68,576 | 22 | 137,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,577 | 22 | 137,154 |
Tags: math, number theory
Correct Solution:
```
def mod_exp(x, y, p):
res = 1
x %= p
while y:
if y&1:
res = (res * x) % p
y >>= 1
x = (x * x) % p
return res
def power(a, b, m):
x, y = 1, a
while b:
if b&1:
x = (x * y) % m
y = (y * y) % m
b //= 2
return x
def mod_inverse(a, m):
return power(a, m - 2, m)
def solve(a, b, n, x):
m = 10**9 + 7
if a == 1:
return (b * n * a + x) % m
p = mod_exp(a, n, m)
return (b * (p - 1) * mod_inverse(a - 1, m) + p * x) % m
a, b, n, x = map(int, input().split())
print(solve(a, b, n, x))
``` | output | 1 | 68,577 | 22 | 137,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,578 | 22 | 137,156 |
Tags: math, number theory
Correct Solution:
```
import math
def modInverse(b,m):
g = math.gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def modDivide(a,b,m):
a = a % m
inv = modInverse(b,m)
return (inv*a)%m
mod=int(10e8+7)
a,b,n,x=map(int,input().split())
if a==1:
print((x%mod+(n*b)%mod)%mod)
exit()
exp=a
ans=1
while n>0:
if(n%2==1):
ans=(ans*exp)%mod
exp=(exp*exp)%mod
n//=2
res=(ans-1)%mod
res=modDivide(res,a-1,mod)
print(((ans*x)%mod+(res*b)%mod)%mod)
``` | output | 1 | 68,578 | 22 | 137,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,579 | 22 | 137,158 |
Tags: math, number theory
Correct Solution:
```
a,b,n,x = (map(int,input().split(' ')))
mod = 10**9+7
if(a==1):
ans = x + n*b
print(ans%mod)
else:
ans = (pow(a,n,mod)*x)%mod
t = pow(a,n,mod)
t = (t-1+mod)%mod
t = (t * pow(a-1,mod-2,mod))%mod
t = (t*b)%mod
print((ans+t)%mod)
``` | output | 1 | 68,579 | 22 | 137,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,580 | 22 | 137,160 |
Tags: math, number theory
Correct Solution:
```
a,b,n,x=map(int,input().split())
m=10**9+7
if a != 1:
print( (pow(a,n,m)*x + b*(pow(a,n,m)-1) * pow(a-1,m-2,m))%m )
else:
print((b*n+x)%m)
``` | output | 1 | 68,580 | 22 | 137,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.
Input
The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.
Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Output
Print the only integer s — the value g(n)(x) modulo 109 + 7.
Examples
Input
3 4 1 1
Output
7
Input
3 4 2 1
Output
25
Input
3 4 3 1
Output
79 | instruction | 0 | 68,581 | 22 | 137,162 |
Tags: math, number theory
Correct Solution:
```
import sys,math
def power(x, y, p):
res = 1;
x = x % p;
while (y > 0):
if (y & 1):
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
return res;
def modInverse(b,m):
g = math.gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def modDivide(a,b,m):
a = a % m
inv = modInverse(b,m)
if(inv == -1):
print("Division not defined")
else:
return (inv*a) % m
#using sum of GP series
A,B,n,X=map(int,sys.stdin.readline().split())
m=10**9+7
if A==1:
print(((n%m)*B+X)%m)
else:
temp=power(A,n,m)
s=(temp*(X%m))%m
s=(s%m+((modDivide(B*(temp-1),A-1,m)%m)%m)%m)%m
print(s%m)
``` | output | 1 | 68,581 | 22 | 137,163 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki are going to together construct a sequence of integers.
First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions:
* The length of a is N.
* Each element in a is an integer between 1 and K, inclusive.
* a is a palindrome, that is, reversing the order of elements in a will result in the same sequence as the original.
Then, Aoki will perform the following operation an arbitrary number of times:
* Move the first element in a to the end of a.
How many sequences a can be obtained after this procedure, modulo 10^9+7?
Constraints
* 1≤N≤10^9
* 1≤K≤10^9
Input
The input is given from Standard Input in the following format:
N K
Output
Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7.
Examples
Input
4 2
Output
6
Input
1 10
Output
10
Input
6 3
Output
75
Input
1000000000 1000000000
Output
875699961 | instruction | 0 | 68,814 | 22 | 137,628 |
"Correct Solution:
```
def prime_factor(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
while n % i == 0:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
def divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
def mebius(n):
res = {}
primes = prime_factor(n)
m = len(primes)
for i in range(1 << m):
mu = 1
d = 1
for j in range(m):
if i >> j & 1:
mu *= -1
d *= primes[j]
res[d] = mu
return res
mod = 10**9+7
N, K = map(int, input().split())
div = divisors(N)
ans = 0
for x in div:
div2 = divisors(x)
mu = mebius(x)
cnt = 0
for y in mu.keys():
cnt += pow(K, ((x//y)+1)//2, mod)*mu[y]
if x % 2 == 0:
cnt *= pow(2, mod-2, mod)
ans += x*cnt
ans %= mod
print(ans)
``` | output | 1 | 68,814 | 22 | 137,629 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki are going to together construct a sequence of integers.
First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions:
* The length of a is N.
* Each element in a is an integer between 1 and K, inclusive.
* a is a palindrome, that is, reversing the order of elements in a will result in the same sequence as the original.
Then, Aoki will perform the following operation an arbitrary number of times:
* Move the first element in a to the end of a.
How many sequences a can be obtained after this procedure, modulo 10^9+7?
Constraints
* 1≤N≤10^9
* 1≤K≤10^9
Input
The input is given from Standard Input in the following format:
N K
Output
Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7.
Examples
Input
4 2
Output
6
Input
1 10
Output
10
Input
6 3
Output
75
Input
1000000000 1000000000
Output
875699961 | instruction | 0 | 68,815 | 22 | 137,630 |
"Correct Solution:
```
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,K = MI()
mod = 10**9+7
def divisor(n): # nの約数のリスト
res = []
for i in range(1,int(n**.5)+1):
if n % i == 0:
res.append(i)
if i != n//i:
res.append(n//i)
return res
A = divisor(N)
d = {} # d[i] = iの約数のリスト(iはNの約数)
for a in A:
d[a] = divisor(a)
prime = [] # Nの素因数のリスト
for i in range(2,int(N**.5)+1):
if N % i == 0:
prime.append(i)
while N % i == 0:
N //= i
if N != 1:
prime.append(N)
mu = {} # mu[i] = μ(i) (iはNの約数)
for a in A:
b = a
r = 1
for p in prime:
if b % p == 0:
r *= -1
if b//p % p == 0:
r = 0
break
mu[a] = r
ans = 0
for a in A:
for b in d[a]:
if a % 2 == 0:
ans += mu[a//b]*pow(K,(b+1)//2,mod)*(a//2)
ans %= mod
else:
ans += mu[a//b]*pow(K,(b+1)//2,mod)*a
ans %= mod
print(ans)
``` | output | 1 | 68,815 | 22 | 137,631 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi and Aoki are going to together construct a sequence of integers.
First, Takahashi will provide a sequence of integers a, satisfying all of the following conditions:
* The length of a is N.
* Each element in a is an integer between 1 and K, inclusive.
* a is a palindrome, that is, reversing the order of elements in a will result in the same sequence as the original.
Then, Aoki will perform the following operation an arbitrary number of times:
* Move the first element in a to the end of a.
How many sequences a can be obtained after this procedure, modulo 10^9+7?
Constraints
* 1≤N≤10^9
* 1≤K≤10^9
Input
The input is given from Standard Input in the following format:
N K
Output
Print the number of the sequences a that can be obtained after the procedure, modulo 10^9+7.
Examples
Input
4 2
Output
6
Input
1 10
Output
10
Input
6 3
Output
75
Input
1000000000 1000000000
Output
875699961 | instruction | 0 | 68,816 | 22 | 137,632 |
"Correct Solution:
```
from math import gcd
def divisors(M):#Mの約数列 O(n^(0.5+e))
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
d.sort()
return d
mod=10**9+7
N,K=map(int,input().split())
div=divisors(N)
res=[0 for i in range(len(div))]
ans=0
if N%2==0:
for i in range(len(div)):
d=div[i]
g=gcd(2*d,N)
res[i]+=pow(K,g//2,mod)
res[i]%=mod
ans+=d*res[i]
ans%=mod
for j in range(i+1,len(div)):
if div[j]%d==0:
res[j]-=res[i]
res[j]%=mod
print(ans%mod)
else:
for i in range(len(div)):
d=div[i]
g=gcd(2*d,N)
res[i]+=pow(K,(g+1)//2,mod)
res[i]%=mod
ans+=d*res[i]
ans%=mod
for j in range(i+1,len(div)):
if div[j]%d==0:
res[j]-=res[i]
res[j]%=mod
print(ans%mod)
``` | output | 1 | 68,816 | 22 | 137,633 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integers in the group.
Both groups have to be non-empty.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5).
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
Output
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise.
If it is possible to split the integers, in the second line print n integers, where the i-th integer is equal to 1 if the integer a_i should be in the first group, and 2 otherwise.
If there are multiple solutions, print any.
Examples
Input
4
2 3 6 7
Output
YES
2 2 1 1
Input
5
6 15 35 77 22
Output
YES
2 1 2 1 1
Input
5
6 10 15 1000 75
Output
NO | instruction | 0 | 69,014 | 22 | 138,028 |
Tags: greedy, number theory, probabilities
Correct Solution:
```
import sys
def gcd(l):
if len(l)==0:
return 0
if len(l)==1:
return l[0]
if len(l)==2:
if l[1]==0:
return l[0]
return gcd([l[1],l[0]%l[1]])
return gcd([gcd(l[:-1]),l[-1]])
def brute_force(l1,l2,l,sol):
if len(l)==0:
g1=gcd(l1)
g2=gcd(l2)
return g1==1 and g2==1,sol
res,s=brute_force(l1+[l[0]],l2,l[1:],sol+[1])
if res:
return True,s
return brute_force(l1,l2+[l[0]],l[1:],sol+[2])
def factor(n):
res=[]
i=2
while i*i<=n:
if n%i==0:
res.append(i)
while n%i==0:
n=int(n/i)
i+=1
if n!=1:
res.append(n)
return res
def dumpsol(sol):
for v in sol:
print(v,end=' ')
n=int(sys.stdin.readline())
l=sys.stdin.readline().strip().split(" ")[0:n]
l=[int(x) for x in l]
if n<12:
ret,sol=brute_force([],[],l,[])
if ret:
print("YES")
dumpsol(sol)
else:
print("NO")
sys.exit()
factors={}
for i in range(10):
for key in factor(l[i]):
factors[key]=0
flists={}
for f in factors:
flists[f]=[]
pos=0
found=False
for v in l:
if v%f!=0:
found=True
factors[f]+=1
flists[f].append(pos)
if (factors[f]>9):
break
pos+=1
if not found:
print("NO")
sys.exit()
oftf=[]
isoftf={}
for f in factors:
if factors[f]==0:
print("NO")
sys.exit()
if factors[f]<10:
oftf.append(f)
isoftf[f]=1
#print(oftf)
sol=[1 for i in range(len(l))]
x=l[0]
sol[0]=2
oxf=factor(x)
#print(oxf)
xf=[]
nxf=0
isxoftf={}
for f in oxf:
if f in isoftf:
nxf+=1
isxoftf[f]=1
xf.append(f)
else:
sol[flists[f][0]]=2
nonxf=[]
for f in oftf:
if not f in isxoftf:
nonxf.append(f)
masks={}
pos=0
#print(xf)
#print(nonxf)
for f in xf+nonxf:
for v in flists[f]:
if not v in masks:
masks[v]=0
masks[v]|=1<<pos
pos+=1
vals=[{} for i in range(len(masks)+1)]
vals[0][0]=0
pos=0
mlist=[]
for mask in masks:
mlist.append(mask)
cmask=masks[mask]
cmask1=cmask<<10
#print(vals)
for v in vals[pos]:
vals[pos+1][v|cmask]=v
# first number is always in group2
if (mask!=0):
vals[pos+1][v|cmask1]=v
pos+=1
#print(vals)
#print(masks)
#print(sol)
test_val=((1<<len(xf))-1)|(((1<<len(oftf))-1)<<10)
#print(test_val)
for v in vals[pos]:
if (v&test_val)==test_val:
print("YES")
#print(pos)
while (pos!=0):
#print(v)
#print(vals[pos])
nv=vals[pos][v]
#print(nv)
if (nv^v<1024 and nv^v!=0):
sol[mlist[pos-1]]=2
v=nv
pos-=1
dumpsol(sol)
sys.exit()
print("NO")
#print(oftf)
#print(masks)
``` | output | 1 | 69,014 | 22 | 138,029 |
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 of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integers in the group.
Both groups have to be non-empty.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5).
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
Output
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise.
If it is possible to split the integers, in the second line print n integers, where the i-th integer is equal to 1 if the integer a_i should be in the first group, and 2 otherwise.
If there are multiple solutions, print any.
Examples
Input
4
2 3 6 7
Output
YES
2 2 1 1
Input
5
6 15 35 77 22
Output
YES
2 1 2 1 1
Input
5
6 10 15 1000 75
Output
NO
Submitted Solution:
```
import random
import sys
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
n = int(input())
a = list(map(int, input().split()))
idx = list(range(n))
arr1, arr2 = None, None
for _ in range(20):
random.shuffle(idx)
cur1, pos1 = a[idx[0]], None
cur2, pos2 = a[idx[-1]], None
for i in range(n):
cur1 = gcd(cur1, a[idx[i]])
if cur1 == 1:
pos1 = i
break
for i in range(n-1, -1, -1):
cur2 = gcd(cur2, a[idx[i]])
if cur2 == 1:
pos2 = i
break
if pos1 is not None and pos2 is not None and pos1 < pos2:
arr1, arr2 = idx[:pos2], idx[pos2:]
break
ans = [1] * n
if arr1 is not None:
for i in arr1:
ans[i] = 2
print('YES')
print(*ans)
else:
print('NO')
``` | instruction | 0 | 69,015 | 22 | 138,030 |
No | output | 1 | 69,015 | 22 | 138,031 |
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 of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integers in the group.
Both groups have to be non-empty.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5).
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
Output
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise.
If it is possible to split the integers, in the second line print n integers, where the i-th integer is equal to 1 if the integer a_i should be in the first group, and 2 otherwise.
If there are multiple solutions, print any.
Examples
Input
4
2 3 6 7
Output
YES
2 2 1 1
Input
5
6 15 35 77 22
Output
YES
2 1 2 1 1
Input
5
6 10 15 1000 75
Output
NO
Submitted Solution:
```
from random import shuffle
from math import gcd
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
A[i] = [A[i], i]
for _ in range(5):
shuffle(A)
g = 0
i = 0
while g != 1 and i < n:
g = gcd(g, A[i][0])
i += 1
g = 0
for j in range(i, n):
g = gcd(g, A[j][0])
if g == 1:
print("YES")
ans = [2] * n
for o in range(i):
ans[A[o][1]] = 1
print(*ans)
exit(0)
print("NO")
``` | instruction | 0 | 69,016 | 22 | 138,032 |
No | output | 1 | 69,016 | 22 | 138,033 |
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 of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integers in the group.
Both groups have to be non-empty.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5).
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
Output
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise.
If it is possible to split the integers, in the second line print n integers, where the i-th integer is equal to 1 if the integer a_i should be in the first group, and 2 otherwise.
If there are multiple solutions, print any.
Examples
Input
4
2 3 6 7
Output
YES
2 2 1 1
Input
5
6 15 35 77 22
Output
YES
2 1 2 1 1
Input
5
6 10 15 1000 75
Output
NO
Submitted Solution:
```
import math
n = int(input()) # 2 <= n <= 10**5
array = [int(i) for i in input().split()] # Every element of the array is in the interval [1, 10**9]
dic_1 = {0: array[0]} # possibly completely useless.
dic_2 = {} # -''-
for i in range(1, len(array)):
# The key is the index, the value is the element.
if math.gcd(array[0], array[i]) == 1:
dic_1[i] = array[i]
else:
dic_2[i] = array[i]
# i.e. if the first element already has a common factor with all the others.
# '- 1' because we already begin with 1 element in 'dic_1'.
if len(dic_2) == n - 1:
print("NO")
elif len(dic_1) == n: # i.e. if all the given elements have a gcd of 1.
print("YES\n2 ", end='')
# or is it n - 1 ???
for i in range(n - 1):
print(1, end=' ')
else:
# Only one element that had a gcd with the first element greater
# than 1. This is still a 'YES' case (or maybe it isn't!!!!!!!)
# and we act accordingly.
if len(dic_2) == 1:
print("YES")
for i in range(n):
if i in dic_2:
print(2, end=' ')
else:
print(1, end=' ')
else:
for element in dic_2.values():
if math.gcd(tuple(dic_2.values())[0], element) != 1 and \
tuple(dic_2.values())[0] != element:
print("NO")
break
else:
print("YES")
for i in range(n):
if i in dic_2:
print(2, end=' ')
else:
print(1, end=' ')
# ID: 1198F.
``` | instruction | 0 | 69,017 | 22 | 138,034 |
No | output | 1 | 69,017 | 22 | 138,035 |
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 of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one.
The GCD of a group of integers is the largest non-negative integer that divides all the integers in the group.
Both groups have to be non-empty.
Input
The first line contains a single integer n (2 ≤ n ≤ 10^5).
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) — the elements of the array.
Output
In the first line print "YES" (without quotes), if it is possible to split the integers into two groups as required, and "NO" (without quotes) otherwise.
If it is possible to split the integers, in the second line print n integers, where the i-th integer is equal to 1 if the integer a_i should be in the first group, and 2 otherwise.
If there are multiple solutions, print any.
Examples
Input
4
2 3 6 7
Output
YES
2 2 1 1
Input
5
6 15 35 77 22
Output
YES
2 1 2 1 1
Input
5
6 10 15 1000 75
Output
NO
Submitted Solution:
```
import sys
def gcd(l):
if len(l)==0:
return 0
if len(l)==1:
return l[0]
if len(l)==2:
if l[1]==0:
return l[0]
return gcd([l[1],l[0]%l[1]])
return gcd([gcd(l[:-1]),l[-1]])
def brute_force(l1,l2,l):
if len(l)==0:
g1=gcd(l1)
g2=gcd(l2)
return g1==1 and g2==1
if brute_force(l1+[l[0]],l2,l[1:]):
return True
return brute_force(l1,l2+[l[0]],l[1:])
def factor(n):
res=[]
i=2
while i*i<=n:
if n%i==0:
res.append(i)
while n%i==0:
n/=i
i+=1
if n!=1:
res.append(n)
return res
n=int(sys.stdin.readline())
l=sys.stdin.readline().strip().split(" ")[0:n]
l=[int(x) for x in l]
if n<12:
if brute_force([],[],l):
print("YES")
else:
print("NO")
sys.exit()
factors={}
for i in range(10):
for key in factor(l[i]):
factors[key]=0
flists={}
for f in factors:
flists[f]=[]
pos=0
found=False
for v in l:
if v%f!=0:
found=True
factors[f]+=1
flists[f].append(pos)
if (factors[f]>9):
break
pos+=1
if not found:
print("NO")
sys.exit()
oftf=[]
isoftf={}
for f in factors:
if factors[f]<10:
oftf.append(f)
isoftf[f]=1
x=oftf[0]
xf=factor(x)
nxf=0
isxoftf={}
for f in xf:
if f in isoftf:
nxf+=1
isxoftf[f]=1
nonxf=[]
for f in oftf:
if not f in isxoftf:
nonxf.append(f)
masks={}
pos=0
for f in xf+nonxf:
for v in flists[f]:
if not v in masks:
masks[v]=0
masks[v]|=1<<pos
pos+=1
vals={}
vals[0]=1
nvals={}
for mask in masks:
cmask=masks[mask]
cmask1=cmask<<10
#print(vals)
for v in vals:
nvals[v|cmask]=1
nvals[v|cmask1]=1
vals=nvals
nvals={}
#print(vals)
test_val=((1<<len(xf))-1)|(((1<<len(oftf))-1)<<10)
for v in vals:
if (v&test_val)==test_val:
print("YES")
sys.exit()
print("NO")
#print(oftf)
#print(masks)
``` | instruction | 0 | 69,018 | 22 | 138,036 |
No | output | 1 | 69,018 | 22 | 138,037 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2).
You want to construct the array a of length n such that:
* The first n/2 elements of a are even (divisible by 2);
* the second n/2 elements of a are odd (not divisible by 2);
* all elements of a are distinct and positive;
* the sum of the first half equals to the sum of the second half (∑_{i=1}^{n/2} a_i = ∑_{i=n/2 + 1}^{n} a_i).
If there are multiple answers, you can print any. It is not guaranteed that the answer exists.
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 one integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the length of the array. It is guaranteed that that n is even (i.e. divisible by 2).
It is guaranteed that the sum of n over all test cases does not exceed 2 ⋅ 10^5 (∑ n ≤ 2 ⋅ 10^5).
Output
For each test case, print the answer — "NO" (without quotes), if there is no suitable answer for the given test case or "YES" in the first line and any suitable array a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) satisfying conditions from the problem statement on the second line.
Example
Input
5
2
4
6
8
10
Output
NO
YES
2 4 1 5
NO
YES
2 4 6 8 1 3 5 11
NO | instruction | 0 | 69,087 | 22 | 138,174 |
Tags: constructive algorithms, math
Correct Solution:
```
for _ in [0]*int(input()):
n = int(input())
if (n//2)%2 == 1:print("NO");continue
print("YES")
l_arr = [x for x in range(2,n+1,2)]
r_arr = [x for x in range(1,n,2)]
r_arr[-1] += sum(l_arr) - sum(r_arr)
print(*l_arr,*r_arr)
``` | output | 1 | 69,087 | 22 | 138,175 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.