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.
You're given Q queries of the form (L, R).
For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = ap.
Input
The first line contains the number of queries Q (1 ≤ Q ≤ 105).
The next Q lines contains two integers L, R each (1 ≤ L ≤ R ≤ 1018).
Output
Output Q lines — the answers to the queries.
Example
Input
6
1 4
9 9
5 7
12 29
137 591
1 1000000
Output
2
1
0
3
17
1111
Note
In query one the suitable numbers are 1 and 4.
Submitted Solution:
```
# -*- coding: utf-8 -*-
#import numpy as np
from itertools import combinations, accumulate
from functools import reduce
from math import floor
maxp = 60
mark = [1]*maxp
mark[0] = 0
mark[1] = 1
i = 2
primes = []
while i < maxp:
if mark[i]:
primes.append(i)
p = i; k = p;
while p*k < maxp:
mark[p*k] = 0
k += 1
i += 1
prods = list(accumulate(primes,lambda x,y: x*y))
combs = []
r = 1
while prods[r-1] < 60:
combs.append(list(combinations(primes,r)))
r += 1
def f(k,R):
"""
{x | 2 <= x <= R and x = a^k, a > 0, k >= 2 } = {x | 2 <= x <= floor(R^(1/k))}
"""
ls = int(floor(R**(1/k)))
return max(ls-1,0)
def solve(L,R):
ret = 0
r = 0
for comb in combs:
r += 1
for t in comb:
sign = -1 + 2*(r%2)
k = reduce(lambda x,y: x*y, t)
ret += sign*f(k,R)
ret -= sign*f(k,L-1)
return ret + (1 if L == 1 else 0)
Q = int(input())
for i in range(Q):
L,R = map(int,input().split())
print(solve(L,R))
``` | instruction | 0 | 94,126 | 22 | 188,252 |
No | output | 1 | 94,126 | 22 | 188,253 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,163 | 22 | 188,326 |
"Correct Solution:
```
from fractions import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
a = A[0]
n = 1
while a % 2 == 0:
n *= 2
a //= 2
lcm = 1
for a in A:
if a % n != 0 or a % (2 * n) == 0:
print(0)
exit()
lcm = lcm * a // gcd(lcm, a)
if lcm // 2 > M:
print(0)
exit()
print((M - lcm // 2) // lcm + 1)
``` | output | 1 | 94,163 | 22 | 188,327 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,164 | 22 | 188,328 |
"Correct Solution:
```
from fractions import gcd
from functools import reduce
N, M, *A = map(int, open(0).read().split())
Y = reduce(lambda a, b: a * b // gcd(a, b), A)
print(M // (Y // 2) - (M // Y) if all((Y // a) % 2 for a in A) else 0)
``` | output | 1 | 94,164 | 22 | 188,329 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,165 | 22 | 188,330 |
"Correct Solution:
```
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = 1
num = a[0]
bin = 1
while num % 2 == 0:
bin *= 2
num //= 2
for num in a:
l = (l * num // 2) // gcd(l, num // 2)
if num % bin != 0 or num % (bin * 2) == 0:
print(0)
exit()
print((m + l) // (2 * l))
``` | output | 1 | 94,165 | 22 | 188,331 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,166 | 22 | 188,332 |
"Correct Solution:
```
from math import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [i // 2 for i in A]
lcd = 1
for a in A:
lcd *= a // gcd(lcd, a)
for a in A:
if lcd // a % 2 == 0:
print(0)
exit()
print((M//lcd+1)//2)
``` | output | 1 | 94,166 | 22 | 188,333 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,167 | 22 | 188,334 |
"Correct Solution:
```
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i]//2 for i in range(n)]
lcm_a = 1
for i in range(n):
lcm_a = (lcm_a * b[i]) // gcd(lcm_a, b[i])
for i in range(n):
if (lcm_a//b[i]) % 2 == 0:
print(0)
exit()
if m < lcm_a:
print(0)
else:
m -= lcm_a
print(1 + m // (lcm_a*2))
``` | output | 1 | 94,167 | 22 | 188,335 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,168 | 22 | 188,336 |
"Correct Solution:
```
N,M = map(int,input().split())
A = list(map(int,input().split()))
s = set()
B = []
for a in A:
t = a & -a
s.add(t)
if len(s) > 1:
print(0)
exit()
B.append(a // t)
from fractions import gcd
l = 1
for b in B:
l = b*l // gcd(b,l)
x = l*t // 2
ans = M//x - M//(2*x)
print(ans)
``` | output | 1 | 94,168 | 22 | 188,337 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,169 | 22 | 188,338 |
"Correct Solution:
```
import sys
def gcd(x,y):
while y:
x,y = y , x % y
return x
n,m=map(int,input().split())
a=tuple(map(int,input().split()))
lcm = 1
for i in a:
lcm = lcm * i // gcd(lcm,i)
for i in a:
if (lcm//i)%2 == 0:
print(0)
sys.exit()
print((m+lcm//2)//lcm)
``` | output | 1 | 94,169 | 22 | 188,339 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667 | instruction | 0 | 94,170 | 22 | 188,340 |
"Correct Solution:
```
N, M = map(int, input().split())
A = list(set(map(lambda x : int(x)//2, input().split())))
def gcd(x, y):
return x if y == 0 else gcd(y, x % y)
def lcm(x, y):
return (x * y) // gcd(x, y)
l = A[0]
for a in A[1:]:
l = lcm(l, a)
ans = (M // l + 1) // 2
for a in A[1:]:
if (l // a) % 2 == 0:
ans = 0
break
print(ans)
``` | output | 1 | 94,170 | 22 | 188,341 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import fractions
import sys
n, m = map(int, input().split())
a = list(map(int, input().split()))
lcm = a[0]
for i in range(1, len(a)):
lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
for i in a:
if(lcm//i)%2 == 0:
print(0)
sys.exit()
lcm //= 2
print(m//lcm-(m//(lcm*2)))
``` | instruction | 0 | 94,171 | 22 | 188,342 |
Yes | output | 1 | 94,171 | 22 | 188,343 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
from fractions import gcd
def lcm(a,b):
return a*b//gcd(a,b)
n,m=map(int,input().split())
a=list(map(int,input().split()))
h=list(map(lambda x:x//2,a))
l=1
for i in range(n):
l=lcm(l,h[i])
for i in range(n):
if (l//h[i])%2==0:
print(0)
exit()
print((m//l+1)//2)
``` | instruction | 0 | 94,172 | 22 | 188,344 |
Yes | output | 1 | 94,172 | 22 | 188,345 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import fractions
import sys
input = sys.stdin.readline
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
n,m = map(int,input().split())
a = list(map(int,input().split()))
g = a[0]
for i in range(1, n):
g = g * a[i] // gcd(g, a[i])
for i in a:
if g // 2 % i == 0:
print(0)
exit()
print(-(-(m * 2 // g)//2))
``` | instruction | 0 | 94,173 | 22 | 188,346 |
Yes | output | 1 | 94,173 | 22 | 188,347 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
from math import gcd
from functools import reduce
n,m=map(int,input().split())
lst=list(map(lambda x : int(x)//2,input().split()))
divi=0
x=lst[0]
while x%2==0:
x//=2
divi+=1
for i in range(1,n):
divi2=0
x=lst[i]
while x%2==0:
x//=2
divi2+=1
if divi!=divi2 :
print(0)
exit()
work=reduce(lambda x,y: x*y//gcd(x,y),lst)
print((m//work+1)//2)
``` | instruction | 0 | 94,174 | 22 | 188,348 |
Yes | output | 1 | 94,174 | 22 | 188,349 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
#!/usr/bin/env python3
import sys
def gcd(a, b):
while b: a, b = b, a % b
return abs(a)
def n_lcd(a,b):
return a*b//gcd(a,b)
# lcd of a1*x1+n1 & a2*x2+n2
def lcd(a1, n1, a2, n2, M):
if a1*a2 == 0:
return M, M
x1 = 0
x2 = 0
k1 = n1
k2 = n2
while (k1 != k2)&(k1<M+2)&(k2<M+2):
if k1 < k2:
x1 += 1
k1 = a1*x1 + n1
else:
x2 += 1
k2 = a2*x2 + n2
# print(k1, k2)
return k1, n_lcd(a1, a2)
def solve(N: int, M: int, a: "List[int]"):
a = sorted(list(set(a)))
base = 1
base_n = 0
for i in a:
base_n, base = lcd(base, base_n, i, i//2, M)
if base > M:
print(0)
else:
print((M-base_n)//base + 1)
return
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
M = int(next(tokens)) # type: int
a = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, M, a)
if __name__ == '__main__':
main()
``` | instruction | 0 | 94,176 | 22 | 188,352 |
No | output | 1 | 94,176 | 22 | 188,353 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
def main():
n, m = map(int, input().split())
aa = list(map(int, input().split()))
from fractions import gcd
from math import ceil
from functools import reduce
def lcm(x, y):
return x * y // gcd(x, y)
l = reduce(lcm, aa)
h = l // 2
count = ceil((m - h) / l)
print(count)
if __name__ == "__main__":
main()
``` | instruction | 0 | 94,177 | 22 | 188,354 |
No | output | 1 | 94,177 | 22 | 188,355 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given are a sequence A= {a_1,a_2,......a_N} of N positive even numbers, and an integer M.
Let a semi-common multiple of A be a positive integer X that satisfies the following condition for every k (1 \leq k \leq N):
* There exists a non-negative integer p such that X= a_k \times (p+0.5).
Find the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Constraints
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^9
* 2 \leq a_i \leq 10^9
* a_i is an even number.
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
a_1 a_2 ... a_N
Output
Print the number of semi-common multiples of A among the integers between 1 and M (inclusive).
Examples
Input
2 50
6 10
Output
2
Input
3 100
14 22 40
Output
0
Input
5 1000000000
6 6 2 6 2
Output
166666667
Submitted Solution:
```
import fractions
import math
n, m = map(int, input().split())
a = set(map(int, input().split()))
lcm = 1
for ai in a:
lcm = (lcm * ai) // fractions.gcd(lcm, ai)
print((m+lcm/2) // lcm)
``` | instruction | 0 | 94,178 | 22 | 188,356 |
No | output | 1 | 94,178 | 22 | 188,357 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,179 | 22 | 188,358 |
"Correct Solution:
```
p = int(input())
a = list(map(int, input().split()))
MAX = 3000
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
fact[i] = (fact[i-1]*i) % p
inv = [1]*(MAX+1)
for i in range(2, MAX+1):
inv[i] = inv[p % i]*(p-p//i) % p
fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
fact_inv[i] = fact_inv[i-1] * inv[i] % p
def comb(n, k):
if n < k:
return 0
return fact[n] * fact_inv[n-k] * fact_inv[k] % p
ans = [0]*p
for i,ai in enumerate(a):
if ai == 1:
ans[-1] += 1
for j in range(p):
ans[j] -= pow(-i,j,p)*comb(p-1,j)
ans[j] %= p
print(*ans[::-1])
``` | output | 1 | 94,179 | 22 | 188,359 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,180 | 22 | 188,360 |
"Correct Solution:
```
class Combi():
def __init__(self, N, mod):
self.power = [1 for _ in range(N+1)]
self.rev = [1 for _ in range(N+1)]
self.mod = mod
for i in range(2, N+1):
self.power[i] = (self.power[i-1]*i) % self.mod
self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
for j in range(N, 0, -1):
self.rev[j-1] = (self.rev[j]*j) % self.mod
def C(self, K, R):
if K < R:
return 0
else:
return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod
def P(self, K, R):
if K < R:
return 0
else:
return (self.power[K])*(self.rev[K-R]) % self.mod
P = int(input())
c = Combi(P-1, P)
A = list(map(int,input().split()))
ans = [0 for i in range(P)]
for i in range(P):
if A[i] != 0:
ans[0] += 1
for j in range(P):
ans[j] -= c.C(P-1, j)*pow(-i, P-1-j,P)
for i in range(P):
ans[i] %= P
print(*ans)
``` | output | 1 | 94,180 | 22 | 188,361 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,181 | 22 | 188,362 |
"Correct Solution:
```
p = int(input())
mod = p
def frac(limit):
frac = [1]*limit
for i in range(2,limit):
frac[i] = i * frac[i-1]%mod
fraci = [None]*limit
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -limit-1, -1):
fraci[i] = fraci[i+1] * (limit + i + 1) % mod
return frac, fraci
frac, fraci = frac(p)
A = list(map(int, input().split()))
C = [0]*p
for i in range(p):
a = A[i]
for j in range(i):
a = (a-C[j]*frac[i]*fraci[i-j])
C[i] = fraci[i]*a%p
B = [0]*p
t = [0]*p
t[0] = 1
for i in range(p):
for j in range(p):
B[j] += t[j]*C[i]
t2 = ([0] + t)[:-1]
t2 = [(a-b*i)%p for a, b in zip(t2, t)]
t = t2[:]
B = [b%p for b in B]
print(*B)
``` | output | 1 | 94,181 | 22 | 188,363 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,182 | 22 | 188,364 |
"Correct Solution:
```
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
def inv(a, mod):
b = mod
p = 1; q = 0
while b > 0:
c = a // b
a, b = b, a%b
p, q = q, p-c*q
return p + mod if p < 0 else p
def guess(mod, y):
n = len(y)
dp = [0] * (n+1)
dp[0] = 1
for i in range(n):
for j in range(i, -1, -1):
dp[j+1] += dp[j]
if dp[j+1] >= mod:
dp[j+1] -= mod
dp[j] = dp[j] * -i % mod
if dp[j] < 0:
dp[j] += mod
f = [0] * (n+1)
f[0] = 1
for i in range(1, n+1):
f[i] = f[i-1] * i % mod
ret = [0] * n
for i in range(n):
den = f[i] * f[n-1-i] % mod
if ((i^n-1)&1) == 1:
den = mod - den
iden = inv(den, mod) * y[i] % mod
minus = 0
for j in range(n-1, -1, -1):
minus = (dp[j+1] + minus * i) % mod
ret[j] = (ret[j] + minus * iden) % mod
return ret
p = ni()
a = na()
f = guess(p, a)
for i in range(p):
sys.stdout.write(str(f[i]) + " ")
``` | output | 1 | 94,182 | 22 | 188,365 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,183 | 22 | 188,366 |
"Correct Solution:
```
def f_polynomal_construction(P, A):
class Combination(object):
"""参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
__slots__ = ["mod", "factorial", "inverse"]
def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
fac, inv = [1], []
fac_append, inv_append = fac.append, inv.append
for i in range(1, max_n + 1):
fac_append(fac[-1] * i % mod)
inv_append(pow(fac[-1], mod - 2, mod))
for i in range(max_n, 0, -1):
inv_append(inv[-1] * i % mod)
self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]
def combination(self, n, r):
if n < 0 or r < 0 or n < r:
return 0
return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod
combination = Combination(P - 1, P)
comb = [combination.combination(P - 1, i) for i in range(P)]
ans = [0] * P
for j, a in enumerate(A):
if a == 0:
continue
# 1-(x-j)^{p-1} = 1 - \sum_{k=0}^{p-1} comb(p-1, p-k-1) * x^{p-k-1} * (-j)^k
# なので、定数項に1を足し、x^k の係数から各々引く
# pow(-j, k, P) としたいが、時間がかかるので tmp に掛けていくことにする
ans[0] += 1
tmp = 1
for k in range(P):
index = P - k - 1
if k > 0:
tmp *= (-j)
tmp %= P
ans[index] -= comb[index] * tmp
ans[index] %= P
return ' '.join(map(str, ans))
P = int(input())
A = [int(i) for i in input().split()]
print(f_polynomal_construction(P, A))
``` | output | 1 | 94,183 | 22 | 188,367 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,184 | 22 | 188,368 |
"Correct Solution:
```
p = int(input())
a = list(map(int, input().split()))
MOD = p
MAX = p + 10
fact = [1] * (MAX + 1) # i!
finv = [1] * (MAX + 1) # (i!)^{-1}
iinv = [1] * (MAX + 1) # i^{-1}
for i in range(2, MAX + 1):
fact[i] = fact[i - 1] * i % MOD
iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * iinv[i] % MOD
def comb(n: int, k: int) -> int:
if n < k or n < 0 or k < 0:
return 0
return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD
b = [0] * p
for j in range(p):
if a[j] == 1:
b[0] += 1
for k in range(p):
b[k] += comb(p - 1, k) * pow(j, p - 1 - k, MOD) * (-1)**(
(p - k) % 2)
b[k] %= MOD
print(*b)
``` | output | 1 | 94,184 | 22 | 188,369 |
Provide a correct Python 3 solution for this coding contest problem.
Given are a prime number p and a sequence of p integers a_0, \ldots, a_{p-1} consisting of zeros and ones.
Find a polynomial of degree at most p-1, f(x) = b_{p-1} x^{p-1} + b_{p-2} x^{p-2} + \ldots + b_0, satisfying the following conditions:
* For each i (0 \leq i \leq p-1), b_i is an integer such that 0 \leq b_i \leq p-1.
* For each i (0 \leq i \leq p-1), f(i) \equiv a_i \pmod p.
Constraints
* 2 \leq p \leq 2999
* p is a prime number.
* 0 \leq a_i \leq 1
Input
Input is given from Standard Input in the following format:
p
a_0 a_1 \ldots a_{p-1}
Output
Print b_0, b_1, \ldots, b_{p-1} of a polynomial f(x) satisfying the conditions, in this order, with spaces in between.
It can be proved that a solution always exists. If multiple solutions exist, any of them will be accepted.
Examples
Input
2
1 0
Output
1 1
Input
3
0 0 0
Output
0 0 0
Input
5
0 1 0 1 0
Output
0 2 0 1 3 | instruction | 0 | 94,186 | 22 | 188,372 |
"Correct Solution:
```
import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
def get_factorials(max, mod=None):
"""
階乗 0!, 1!, 2!, ..., max!
:param int max:
:param int mod:
:return:
"""
ret = [1]
n = 1
if mod:
for i in range(1, max + 1):
n *= i
n %= mod
ret.append(n)
else:
for i in range(1, max + 1):
n *= i
ret.append(n)
return ret
def mod_invs(max, mod):
"""
逆元のリスト 0 から max まで
:param int max:
:param int mod:
"""
invs = [1] * (max + 1)
for x in range(2, max + 1):
invs[x] = (-(mod // x) * invs[mod % x]) % mod
return invs
def factorial_invs(max, mod):
"""
階乗 0!, 1!, 2!, ..., max! の逆元
:param int max:
:param int mod:
"""
ret = []
r = 1
for inv in mod_invs(max, mod):
r = r * inv % mod
ret.append(r)
return ret
class Combination:
def __init__(self, max, mod):
"""
:param int max:
:param int mod: 3 以上の素数であること
"""
self._factorials = get_factorials(max, mod)
self._finvs = factorial_invs(max, mod)
self._mod = mod
def ncr(self, n, r):
"""
:param int n:
:param int r:
:rtype: int
"""
if n < r:
return 0
return (
self._factorials[n]
* self._finvs[r]
% self._mod
* self._finvs[n - r]
% self._mod
)
P = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
# A = np.array(A, dtype=int)
# vpow = np.vectorize(lambda a, b: pow(a, b, P))
# mat = []
# for i in range(P):
# mat.append(vpow(i, np.arange(P)))
# print(np.array(mat).sum(axis=1) % P)
# print(np.array(mat).sum(axis=0) % P)
# mat = np.hstack((mat, [[a] for a in A]))
#
# print(mat)
#
# 解説AC
# f(x) = 1−(x - j)^(P - 1) は、x == j のとき1、それ以外のとき0
# A[j] == 1 である j について上記の式を足し合わせる
comb = Combination(max=P - 1, mod=P)
ncr = [comb.ncr(P - 1, i) for i in range(P)]
B = [0] * P
for j, a in enumerate(A):
if a == 0:
continue
pw = 1 # pow(-j, i, P)
for i in range(P):
B[i] -= pw * ncr[i] % P
B[i] %= P
pw = (pw * -j) % P
B[-1] += 1
B[-1] %= P
print(*B[::-1])
``` | output | 1 | 94,186 | 22 | 188,373 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,768 | 22 | 189,536 |
Tags: math
Correct Solution:
```
a,b=map(int, input().split())
m=1000000007
B = int((b*(b-1)/2) % m );
A1 = int((a*(a+1)/2) % m );
A = int((A1*b+a) % m );
res = int((A*B) % m) ;
print(res)
``` | output | 1 | 94,768 | 22 | 189,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,769 | 22 | 189,538 |
Tags: math
Correct Solution:
```
a,b = map(int,input().split())
MOD = 1000000007
x = a*(a + 1)
x = x // 2
x = x % MOD
x = (x * b) % MOD
x = (x + a) % MOD
x = ((x*b*(b - 1)) // 2) % MOD
print(x)
``` | output | 1 | 94,769 | 22 | 189,539 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,770 | 22 | 189,540 |
Tags: math
Correct Solution:
```
a,b=map(int,input().split())
h=1000000007
c=((a*(b*b-b))//2)%h;
d=((a*a+a)//2)%h;
e=((b*b*b-b*b)//2)%h;
print((c+(d*e)%h)%h)
``` | output | 1 | 94,770 | 22 | 189,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,771 | 22 | 189,542 |
Tags: math
Correct Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 7 23:26:09 2021
@author: Kevin Chang
Project: Codeforces Problem 476C
"""
a, b = list(map(int, input().split()))
modu = 10**9+7
res = (b*(b-1)//2)*((b*a*(a+1)//2)+a)%modu
print(res)
``` | output | 1 | 94,771 | 22 | 189,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,772 | 22 | 189,544 |
Tags: math
Correct Solution:
```
mod =10**9+7
a,b = map(int,input().split())
t1 = (b*(b-1)//2)%mod
t2 = (a*(a+1)//2)%mod
t3= (t2*b)%mod +a
ans = (t1 * t3)%mod
print(ans)
``` | output | 1 | 94,772 | 22 | 189,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,773 | 22 | 189,546 |
Tags: math
Correct Solution:
```
a,b = list(map(int,input().split()))
if b ==1 :
print(0)
else :
res = a + b*a*(a+1)//2
res = (res*(b)*(b-1)//2)
print(res%(10**9 +7))
``` | output | 1 | 94,773 | 22 | 189,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,774 | 22 | 189,548 |
Tags: math
Correct Solution:
```
a = input()
a = a.split()
a,b = int(a[0]),int(a[1])
k2 = b*(b-1)*a // 2
k = (b-1)*b//2 * b* (1+a)*a // 2
res = (k + k2) % 1000000007
print(res)
``` | output | 1 | 94,774 | 22 | 189,549 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}. | instruction | 0 | 94,775 | 22 | 189,550 |
Tags: math
Correct Solution:
```
import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65
MODMAX = 1000000007
def getInt():
return int(sys.stdin.readline().rstrip())
def getInts():
return map(int, sys.stdin.readline().rstrip().split(" "))
def getString():
return sys.stdin.readline().rstrip()
def printOutput(ans):
sys.stdout.write()
pass
def termadd(n):
return (n * (n + 1)) // 2
def solve(a, b):
return ((a*(b-1)*(b)*(b*(a+1) + 2))//4) % MODMAX
def readinput():
a, b = getInts()
print(solve(a, b))
readinput()
``` | output | 1 | 94,775 | 22 | 189,551 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}.
Submitted Solution:
```
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
from __future__ import print_function # for PyPy2
# from itertools import permutations
# from functools import cmp_to_key # for adding custom comparator
# from fractions import Fraction
# from collections import *
from sys import stdin
# from bisect import *
from heapq import *
from math import log2, ceil, sqrt, gcd, log
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x : reversed(range(x))
mod = int(1e9)+7
inf = float("inf")
# range = xrange
a, b = gil()
if b == 1:
print(0)
exit()
ans = 0
for k in range(1, a+1):
ans += (k*b + 1)%mod
if ans >= mod:
ans %= mod
# print(ans)
mul = ((b-1)*(b))//2
mul %= mod
ans *= mul
ans %= mod
print(ans)
``` | instruction | 0 | 94,776 | 22 | 189,552 |
Yes | output | 1 | 94,776 | 22 | 189,553 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}.
Submitted Solution:
```
a,b=map(int, input().split())
m=1000000007
B = int((b*(b-1)/2) % m );
A1 = int((a*(a+1)/2) % m );
A = int((A1*b+a) % m );
res = int((A*B) % m) ;#Is the operation divided in fractions of it
print(res)
``` | instruction | 0 | 94,777 | 22 | 189,554 |
Yes | output | 1 | 94,777 | 22 | 189,555 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}.
Submitted Solution:
```
x=[int(i) for i in input().split()]
a=x[0]
b=x[1]
x = ((b*(b-1))//2)%(1000000007)
y = (a + (b*a*(a+1))//2)%(1000000007)
print((x*y)%(1000000007))
``` | instruction | 0 | 94,778 | 22 | 189,556 |
Yes | output | 1 | 94,778 | 22 | 189,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}.
Submitted Solution:
```
'''
Created on Oct 12, 2014
@author: Ismael
'''
#import time
MOD = 10**9+7
def sumTermsArith1(firstTerm,r,nbTerms):
return (nbTerms*(2*firstTerm+(nbTerms-1)*r))//2
def solve(a,b):
s = 0
for rem in range(1,b):
reason = rem*b
s = (s+sumTermsArith1(reason+rem,reason,a))%MOD
return s
def solve2(a,b):
reason = a*(b*(a+1)+2)//2
return sumTermsArith1(reason,reason,b-1)%MOD
#t = time.clock()
a,b = map(int,input().split())
#sol1 = solve(a,b)
sol2 = solve2(a,b)
print(sol2)
#print(sol1 == sol2)
#print(time.clock()-t)
``` | instruction | 0 | 94,779 | 22 | 189,558 |
Yes | output | 1 | 94,779 | 22 | 189,559 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}.
Submitted Solution:
```
a,b=map(int, input().split())
k=1
res=0
while k<=a:
res+=((k*b)+1)*((b*(b-1))/2)
k+=1
print(int(res))
``` | instruction | 0 | 94,782 | 22 | 189,564 |
No | output | 1 | 94,782 | 22 | 189,565 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a].
By <image> we denote the quotient of integer division of x and y. By <image> we denote the remainder of integer division of x and y. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Output
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
Examples
Input
1 1
Output
0
Input
2 2
Output
8
Note
For the first sample, there are no nice integers because <image> is always zero.
For the second sample, the set of nice integers is {3, 5}.
Submitted Solution:
```
mod =10**9+7
b,x = map(int,input().split())
t = (b*(b-1)/2)%mod
ans = (t * ((x *(x+1)/2 * b) %mod+ x))%mod
print(int(ans))
``` | instruction | 0 | 94,783 | 22 | 189,566 |
No | output | 1 | 94,783 | 22 | 189,567 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,898 | 22 | 189,796 |
Tags: binary search, number theory
Correct Solution:
```
import math
from sys import stdout
def print_fast(string):
stdout.write(string + '\n')
def MGCD(_gcd, low, high):
answer = -1
botton = low
index = min(_gcd, high)
while index >= botton:
if _gcd % index == 0:
return index
index -= 1
return answer
_input = input().split()
a = int(_input[0])
b = int(_input[1])
_gcd = math.gcd(a, b)
divisors = []
i = 1
while i * i <= _gcd:
if _gcd % i == 0:
divisors.append(i)
divisors.append(_gcd // i)
i += 1
divisors = sorted(divisors)
testCases = int(input())
ans = []
for i in range(testCases):
_input = input().split()
l = int(_input[0])
h = int(_input[1])
answer = -1
for i in divisors:
if i > h:
break
if i >= l and i <= h:
answer = i
ans.append(str(answer))
#ans.append(str(MGCD(_gcd, l, h)))
print_fast('\n'.join(ans))
``` | output | 1 | 94,898 | 22 | 189,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,899 | 22 | 189,798 |
Tags: binary search, number theory
Correct Solution:
```
from math import gcd
a,b = list(map(int, input().split()))
cd = gcd(a,b)
ar =[]
for i in range(1,int(cd**0.5)+1):
if cd % i == 0:
ar.append(i)
if(i*i != cd):
ar.append(cd//i)
for _ in range(int(input())):
l,h = list(map(int, input().split()))
res = -1
for i in ar:
if(i >= l and i <= h):
res = max(res, i)
print(res)
``` | output | 1 | 94,899 | 22 | 189,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,900 | 22 | 189,800 |
Tags: binary search, number theory
Correct Solution:
```
n,m = [int(i) for i in input().split()]
l = []
for i in range(1,int(n**0.5)+1):
if n%i == 0 and m%i == 0:
l.append(i)
if n%(n//i) == 0 and m%(n//i) == 0:
l.append(n//i)
l.sort()
n = int(input())
for i in range(n):
q,w = [int(j) for j in input().split()]
mx = -1
for j in range(len(l)-1,-1,-1):
if q<=l[j]<=w:
mx = l[j]
break
print(mx)
``` | output | 1 | 94,900 | 22 | 189,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,901 | 22 | 189,802 |
Tags: binary search, number theory
Correct Solution:
```
import math,bisect
a,b=map(int,input().split())
gcd=math.gcd(a,b)
arr=[i for i in range(1,int(math.sqrt(gcd))+1) if gcd%i==0]
for i in arr[::-1]:arr.append(gcd//i)
for _ in range(int(input())):
l,h=map(int,input().split())
idx=bisect.bisect(arr,h)-1
if l>arr[idx]:print(-1)
else:print(arr[idx])
``` | output | 1 | 94,901 | 22 | 189,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,902 | 22 | 189,804 |
Tags: binary search, number theory
Correct Solution:
```
def make_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
a, b = map(int, input().split())
n = int(input())
import math
g = math.gcd(a, b)
D = make_divisors(g)
import bisect
for i in range(n):
low, high = map(int, input().split())
l = bisect.bisect_left(D, low)
r = bisect.bisect_right(D, high)
if l != r:
print(D[r-1])
else:
print(-1)
``` | output | 1 | 94,902 | 22 | 189,805 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,903 | 22 | 189,806 |
Tags: binary search, number theory
Correct Solution:
```
from functools import reduce
import io,os,sys,math
def binarySearchkeeb(data,target,low,high):
if low > high:
return high
else:
mid=(low+high)//2
if data[mid] <=target:
return binarySearchkeeb(data,target,mid+1,high)
else:
return binarySearchkeeb(data,target,low,mid-1)
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def gcd(x,y):return math.gcd(x,y)
def allFactors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
a,b=map(int,input().split())
re=sorted(allFactors(gcd(a,b)))
for _ in range(int(input())):
l,h=map(int,input().split())
ans=binarySearchkeeb(re,h,0,len(re)-1)
if ans == -1:
print(-1)
else:
c=re[ans]
if l <= c:
print(c)
else:
print(-1)
``` | output | 1 | 94,903 | 22 | 189,807 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,904 | 22 | 189,808 |
Tags: binary search, number theory
Correct Solution:
```
# import sys
# sys.stdin = open("input.in","r")
from sys import stdin
input = stdin.readline
from heapq import heapify,heappush,heappop,heappushpop
from collections import defaultdict as dd, deque as dq,Counter as C
from math import factorial as f ,ceil,gcd,sqrt,log
from bisect import bisect_left as bl ,bisect_right as br
from itertools import combinations as c,permutations as p
from math import factorial as f ,ceil,gcd,sqrt,log
mp = lambda : map(int,input().split())
it = lambda: int(input())
ls = lambda : list(input().strip())
def isprime(n):
for j in range(3,int(sqrt(n))+1,2):
if n%j==0:
return 0
return 1
def factors(n):
s = set()
s.add(1)
s.add(n)
for j in range(2,int(sqrt(n))+1):
if n%j==0:
s.add(j)
s.add(n//j)
return s
a,b = mp()
k = sorted(factors(a))
for _ in range(it()):
l,h = mp()
ans =-1
for el in range(br(k,h)-1 ,bl(k,l)-1,-1):
if b%k[el]==0:
ans = k[el]
break
if ans>=l and ans<=h:
print(ans)
else:
print(-1)
``` | output | 1 | 94,904 | 22 | 189,809 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9 | instruction | 0 | 94,905 | 22 | 189,810 |
Tags: binary search, number theory
Correct Solution:
```
from math import gcd
from bisect import bisect
a,b=map(int,input().split())
d=gcd(a,b)
c=int(d**0.5)
m=[]
for i in range(1,c+1):
if d%i==0:
m.append(i)
m.append(d//i)
m.sort()
n=int(input())
for i in range(n):
c,d=map(int,input().split())
e=bisect(m,c)
f=bisect(m,d)
y=0
for i in range(f-1,e-2,-1):
if m[i]>=c and m[i]<=d:
print(m[i])
y=1
break
if y==0:
print("-1")
``` | output | 1 | 94,905 | 22 | 189,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9
Submitted Solution:
```
from math import sqrt
def bin_ser(co_szuk):
start, koniec = 0, len(dzielniki) - 1
while start < koniec:
srodek = (koniec + start + 1) // 2
if dzielniki[srodek] > co_szuk:
koniec = srodek - 1
else:
start = srodek
return dzielniki[start]
def nwd(a, b):
while b:
a, b = b, a % b
return a
a, b = map(int, input().split())
NWD = nwd(a,b)
dzielniki = []
for i in range(1, int(sqrt(NWD)) + 1):
if NWD % i == 0:
dzielniki.append(i)
if i * i != NWD:
dzielniki.append(NWD // i)
dzielniki.sort()
for t in range(int(input())):
low, high = map(int, input().split())
wynik = bin_ser(high)
if wynik <= high and wynik >= low:
print(wynik)
else:
print(-1)
``` | instruction | 0 | 94,906 | 22 | 189,812 |
Yes | output | 1 | 94,906 | 22 | 189,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9
Submitted Solution:
```
import sys
lines = sys.stdin.readlines()
(m, n) = map(int, lines[0].strip().split(" "))
def gcd(a, b):
if a == 0: return b
if a > b: return gcd(b, a)
return gcd(b%a, a)
G = gcd(m, n)
tmp = G
factors = []
i = 2
while i**2 <= tmp:
if tmp % i == 0:
factors.append(i)
tmp//=i
else: i += 1
if tmp != 1: factors.append(tmp)
count = {}
for f in factors:
if f not in count:
count[f] = 0
count[f] += 1
primes = list(count.keys())
primes.sort()
factors = [1]
for p in primes:
tmp = []
for f in factors:
for i in range(1, count[p]+1):
tmp.append(f * p ** i)
factors += tmp
factors.sort()
L = len(factors)
Q = int(lines[1].strip())
for q in range(2, Q+2):
(lo, hi) = map(int, lines[q].strip().split(" "))
l, r = 0, L
while l < r-1:
mid = (r-l)//2 + l
if factors[mid] > hi: r = mid
else: l = mid
if factors[l] >= lo: print(factors[l])
else: print(-1)
``` | instruction | 0 | 94,907 | 22 | 189,814 |
Yes | output | 1 | 94,907 | 22 | 189,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9
Submitted Solution:
```
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(10**4)
from math import ceil,factorial,floor,gcd,log2,log10,sqrt
from collections import defaultdict as dd,Counter as cc,deque
from itertools import permutations as perm, combinations as comb
from heapq import heapify,heappush,heappushpop,nlargest,nsmallest
from bisect import bisect_left,bisect_right,bisect as bs
inpl=lambda : list(map(int,input().split()))
lstinp=lambda : list(input().split())
inpm=lambda : map(int,input().split())
inps=lambda :int(input())
inp=lambda : input()
def Divisors(n) :
l=[]
i = 2
while i <= sqrt(n):
if (n % i == 0) :
if (n // i == i) :
l.append(i)
else :
l.append(i)
l.append(n//i)
i = i + 1
return l
def SieveOfEratosthenes(n):
l=[]
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]:
l.append(p)
return l
def primeFactors(n):
l=[]
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3,int(sqrt(n))+1,2):
while n % i== 0:
l.append(i)
n = n / i
if n > 2:
l.append(n)
return(l)
def Factors(n) :
result = []
for i in range(2,(int)(sqrt(n))+1) :
if (n % i == 0) :
if (i == (n/i)) :
result.append(i)
else :
result.append(i)
result.append(n//i)
result.append(1)
result.append(n)
return result
def maxSubArraySum(a):
max_so_far = 0
max_ending_here = 0
size=len(a)
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
def longestsubarray(arr, n, k):
current_count = 0
# this will contain length of
# longest subarray found
max_count = 0
for i in range(0, n, 1):
if (arr[i] % k != 0):
current_count += 1
else:
current_count = 0
max_count = max(current_count,max_count)
return max_count
def main():
a,b=inpm()
gg=gcd(a,b)
fact=sorted(Factors(gg))
q=inps()
for _ in range(q):
l,r=inpm()
if l>gg:
print(-1)
continue
if r>gg:
r=gg
x=fact[bisect_right(fact,r)-1]
if x in range(l,r+1):
print(x)
else:
print(-1)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 94,908 | 22 | 189,816 |
Yes | output | 1 | 94,908 | 22 | 189,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9
Submitted Solution:
```
from fractions import gcd
a, b = map(int, input().split(' '))
x = gcd(a, b)
div = []
for i in range(1, int(x**0.5+1)):
if x%i==0:
if i*i==x:
div.append(i)
else:
div.append(i)
div.append(x//i)
div.sort()
lenx = len(div)
for i in range(int(input())):
a, b = list(map(int, input().split(' ')))
lo = 0
hi = lenx-1
work = -1
while lo <= hi:
mid = (lo + hi) // 2
if div[mid] < a:
lo = mid+1
elif div[mid] > b:
hi = mid - 1
else:
work = max(work, div[mid])
lo = mid + 1
print(work)
``` | instruction | 0 | 94,909 | 22 | 189,818 |
Yes | output | 1 | 94,909 | 22 | 189,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.
You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.
Input
The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).
Output
Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
Examples
Input
9 27
3
1 5
10 11
9 11
Output
3
-1
9
Submitted Solution:
```
import math,sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili=lambda:list(map(int,sys.stdin.readlines()))
li = lambda:list(map(int,input().split()))
#for deque append(),pop(),appendleft(),popleft(),count()
I=lambda:int(input())
S=lambda:input().strip()
mod = 1000000007
a,b=li()
a,b=min(a,b),max(a,b)
ans=[]
for i in range(1,int(math.sqrt(b)+1)):
if(a%i==0 and b%i==0):
ans.append(i)
if(b%a==0):
ans.append(a)
#print(*ans)
for i in range(I()):
l,r=li()
f=0
for j in ans[::-1]:
if(l<=j and j<=r):
f=1
print(j)
break
if(not f):
print(-1)
``` | instruction | 0 | 94,910 | 22 | 189,820 |
No | output | 1 | 94,910 | 22 | 189,821 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.