message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
Output
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.
Examples
Input
3 14
Output
2
Input
10 123
Output
3
Input
100000 1000000000
Output
10000 | instruction | 0 | 97,676 | 22 | 195,352 |
"Correct Solution:
```
n,m=map(int,input().split())
ans=1
for i in range(1,int(m**0.5)+1):
if m%i==0:
y=m//i
if m//i>=n and ans<i:
ans=i
if m//y>=n and ans<y:
ans=y
print(ans)
``` | output | 1 | 97,676 | 22 | 195,353 |
Provide a correct Python 3 solution for this coding contest problem.
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
Output
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.
Examples
Input
3 14
Output
2
Input
10 123
Output
3
Input
100000 1000000000
Output
10000 | instruction | 0 | 97,677 | 22 | 195,354 |
"Correct Solution:
```
import sys
n,m=map(int,input().split())
a=m//n
ans=1
if m%n==0:
print(int(m//n))
sys.exit()
for i in range(1,a+1):
if m%i==0:
ans=max(ans,i)
print(ans)
``` | output | 1 | 97,677 | 22 | 195,355 |
Provide a correct Python 3 solution for this coding contest problem.
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
Output
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.
Examples
Input
3 14
Output
2
Input
10 123
Output
3
Input
100000 1000000000
Output
10000 | instruction | 0 | 97,678 | 22 | 195,356 |
"Correct Solution:
```
n,m = map(int,input().split())
ans = 1
for i in range(1,int(m**0.5)+1):
if m%i!=0:continue
if m//i>=n:
ans = max(i,ans)
if i>=n:
ans = max(m//i,ans)
print(ans)
``` | output | 1 | 97,678 | 22 | 195,357 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
Output
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.
Examples
Input
3 14
Output
2
Input
10 123
Output
3
Input
100000 1000000000
Output
10000
Submitted Solution:
```
N,M = map(int,input().split())
gcd = M//N
while gcd*N!=M:
gcd = M//N
N = 1+(M-1)//gcd
print(gcd)
``` | instruction | 0 | 97,682 | 22 | 195,364 |
Yes | output | 1 | 97,682 | 22 | 195,365 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
Output
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.
Examples
Input
3 14
Output
2
Input
10 123
Output
3
Input
100000 1000000000
Output
10000
Submitted Solution:
```
# D - Partition
# Mの約数で、しかもN倍してもMを超えないもののうち、最大のものを探す
N, M = map(int, input().split())
x = 1
while x * N <= M:
if M % x == 0:
ans = x
x += 1
print(ans)
``` | instruction | 0 | 97,684 | 22 | 195,368 |
No | output | 1 | 97,684 | 22 | 195,369 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.
Constraints
* All values in input are integers.
* 1 \leq N \leq 10^5
* N \leq M \leq 10^9
Input
Input is given from Standard Input in the following format:
N M
Output
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.
Examples
Input
3 14
Output
2
Input
10 123
Output
3
Input
100000 1000000000
Output
10000
Submitted Solution:
```
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
while y: x,y = y,x%y
return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
"""Return a tuple list of divisor of n"""
return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
"""Return a list of prime numbers n or less"""
is_prime = [True]*(n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(n**0.5)+1):
if not is_prime[i]: continue
for j in range(i*2, n+1, i): is_prime[j] = False
return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
"""Return a list of prime factorization numbers of n"""
res = []
for i in range(2,int(n**0.5)+1):
while n%i==0: res.append(i); n //= i
if n != 1: res.append(n)
return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
n, m = MII()
divs = enumerate_divs(m)
ans = []
h = m/n
for i,j in divs:
if i <= h:
ans.append(i)
if j <= h:
ans.append(i)
print(max(ans))
if __name__ == '__main__':
main()
``` | instruction | 0 | 97,686 | 22 | 195,372 |
No | output | 1 | 97,686 | 22 | 195,373 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,687 | 22 | 195,374 |
"Correct Solution:
```
import sys
N = int(input())
if N == 3:
print('2 5 63')
sys.exit()
if N == 4:
print('2 5 20 63')
sys.exit()
if N == 5:
print('2 3 6 4 9')
sys.exit()
S = '2 3 6 4 9'
N -= 5
print(S, end='')
if N == 1:
print(' 12')
sys.exit()
for i in range(5001):
Tmp1 = 6 * i + 8
Tmp2 = 6 * i + 10
if Tmp2 > 30000:
break
print(' %d %d' %(Tmp1, Tmp2) , end='')
N -= 2
if N == 0:
print()
sys.exit()
elif N == 1:
print(' 12')
sys.exit()
for i in range(5001):
Tmp1 = 12 * i + 15
Tmp2 = 12 * i + 21
if Tmp2 > 30000:
break
print(' %d %d' %(Tmp1, Tmp2), end='')
N -= 2
if N == 0:
print()
sys.exit()
elif N == 1:
print(' 12')
sys.exit()
for i in range(N):
Tmp1 = 6 * (i + 2)
if Tmp1 > 30000:
break
print(' %d' %(Tmp1) , end='')
print()
``` | output | 1 | 97,687 | 22 | 195,375 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,688 | 22 | 195,376 |
"Correct Solution:
```
n = int(input())
ANS = []
even = [2, 10, 3, 9, 4, 8, 6, 12]
odd = [12, 2, 10, 3, 9, 4, 8, 6]
if n == 3:
print(2, 5, 63)
else:
p = n // 8
r = n % 8
if r % 2 == 0:
tmp = even
else:
tmp = odd
ANS += [12 * i + x for x in tmp for i in range(p)]
ANS += [12 * p + x for x in tmp[:r]]
print(*ANS)
``` | output | 1 | 97,688 | 22 | 195,377 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,689 | 22 | 195,378 |
"Correct Solution:
```
n=int(input())
if n==3:
print(2,5,63)
else:
if n%2==0:
ans=[3,9]
cnt=2
for i in range(30001):
if i%6==2:
if i+2<=30000:
ans.append(i)
ans.append(i+2)
cnt+=2
if cnt==n:
break
else:
continue
if cnt<n:
for i in range(12,30001):
if i%12==3:
if i+9<=30000:
ans.append(i)
ans.append(i+6)
cnt+=2
if cnt==n:
break
else:
continue
if cnt<n:
for i in range(1,30001):
if i%6==0:
ans.append(i)
cnt+=1
if cnt==n:
break
print(*ans)
else:
ans=[3,6,9]
cnt=3
for i in range(30001):
if i%6==2:
if i+2<=30000:
ans.append(i)
ans.append(i+2)
cnt+=2
if cnt==n:
break
else:
continue
if cnt<n:
for i in range(12,30001):
if i%12==3:
if i+9<=30000:
ans.append(i)
ans.append(i+6)
cnt+=2
if cnt==n:
break
else:
continue
if cnt<n:
for i in range(7,30001):
if i%6==0:
ans.append(i)
cnt+=1
if cnt==n:
break
print(*ans)
``` | output | 1 | 97,689 | 22 | 195,379 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,690 | 22 | 195,380 |
"Correct Solution:
```
n=int(input())
ret=[2,3,4] if n>=6 else [2,5,63] if n==3 else [2,5,20,63] if n==4 else [2,5,20,30,63]
if n>=6:
def getnext(a):
if a%6==0:
return a+2
elif a%6==2:
return a+1
elif a%6==3:
return a+1
elif a%6==4:
return a+2
while len(ret)<n:
ret.append(getnext(ret[-1]))
if sum(ret)%6==5:
ret[-1]=getnext(ret[-1])
elif sum(ret)%6!=0:
ret.remove((sum(ret)%6)+6)
ret.append(getnext(ret[-1]))
while sum(ret)%6!=0:
ret[-1]=getnext(ret[-1])
print(" ".join(map(str,ret)))
``` | output | 1 | 97,690 | 22 | 195,381 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,691 | 22 | 195,382 |
"Correct Solution:
```
N = int(input())
if N == 3:
ans = [2, 3, 25]
else:
# [合計が6の倍数]を常に満たすように追加する
if N % 2 == 0:
As = [2, 10, 3, 9, 4, 8, 6, 12]
else:
As = [6, 2, 10, 3, 9, 4, 8, 12]
ans = []
for i in range(N):
ans.append(As[i % 8] + 12 * (i // 8))
print(' '.join(map(str, ans)))
``` | output | 1 | 97,691 | 22 | 195,383 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,692 | 22 | 195,384 |
"Correct Solution:
```
n=int(input())
if n==3:exit(print(2,5,63))
l=[6,2,10,3,9,4,8,12]if n%2else[2,10,3,9,4,8,6,12]
for i in range(n):print(i//8*12+l[i%8],end=" ")
``` | output | 1 | 97,692 | 22 | 195,385 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,693 | 22 | 195,386 |
"Correct Solution:
```
n = int(input())
ANS = []
A = [2, 10, 3, 9, 4, 8, 6, 12]
if n == 3:
print(2, 5, 63)
else:
p = n // 8
r = n % 8
ANS += [12 * i + a for a in A for i in range(p)]
ANS += [12 * p + a for a in A[:r]]
if r % 2 == 1:
ANS.pop()
ANS.append(12 * p + 12)
print(*ANS)
``` | output | 1 | 97,693 | 22 | 195,387 |
Provide a correct Python 3 solution for this coding contest problem.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63 | instruction | 0 | 97,694 | 22 | 195,388 |
"Correct Solution:
```
import sys
stdin = sys.stdin
def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())
def solve(n:int) -> list:
x6o2 = [(6*i+2, 6*i+4) for i in range(5000)]
x6o3 = [(12*i+3, 12*i+9) for i in range(2500)]
o6 = [6*i+6 for i in range(5000)]
x6 = []
for i in range(2500):
x6.append(x6o3[i])
x6.append(x6o2[2*i])
x6.append(x6o2[2*i+1])
ans = []
if n == 3:
ans = [2, 5, 63]
elif n <= 15000:
idx = n//2
for i, (mn,mx) in enumerate(x6[:idx]):
ans.extend([mn,mx])
if n%2:
ans = ans + [6]
else:
for i, (mn,mx) in enumerate(x6):
ans.extend([mn,mx])
for o6i in o6[:n-15000]:
ans.append(o6i)
return ans
n = ni()
print(*solve(n))
``` | output | 1 | 97,694 | 22 | 195,389 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
# -*- coding: utf-8 -*-
from sys import stdin
d_in = lambda: int(stdin.readline()) # N = d_in()
MAX = 30000
N = d_in()
base = [3, 25, 2, 35, 55]
cand = []
for i in range(4, MAX // 2, 2):
cand.append(i)
cand.append(MAX - i)
for i in range(9, MAX // 2, 6):
cand.append(i)
cand.append(MAX - i)
ans = []
if N < 5:
ans.extend(base[:3])
if N == 4:
ans.append(MAX)
elif N % 2 == 1:
ans.extend(base)
ans.extend(cand[:N-5])
else:
ans.extend(base)
ans.append(MAX)
ans.extend(cand[:N-6])
print(*ans)
``` | instruction | 0 | 97,695 | 22 | 195,390 |
Yes | output | 1 | 97,695 | 22 | 195,391 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
import sys
from math import gcd
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def debug(res):
tot = sum(res)
for num in res:
if gcd(tot - num, num) == 1:
return False
return True
def resolve():
n = int(input())
if n == 3:
res = [2, 5, 63]
elif n == 4:
res = [2, 5, 20, 63]
elif n == 5:
res = [2, 5, 20, 30, 63]
else:
nums = [num for num in range(2, 30001) if num % 2 == 0 or num % 3 == 0]
res = [nums[i] for i in range(n)]
total = sum(res)
if total % 6 == 2:
res.pop(res.index(8))
for i in range(n, len(nums)):
if nums[i] % 6 == 0:
res.append(nums[i])
break
elif total % 6 == 3:
res.pop(res.index(9))
for i in range(n, len(nums)):
if nums[i] % 6 == 0:
res.append(nums[i])
break
elif total % 6 == 5:
res.pop(res.index(9))
for i in range(n, len(nums)):
if nums[i] % 6 == 4:
res.append(nums[i])
break
print(*res)
# print(debug(res))
if __name__ == '__main__':
resolve()
``` | instruction | 0 | 97,696 | 22 | 195,392 |
Yes | output | 1 | 97,696 | 22 | 195,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
import sys
N=int(input())
if N==3:
print(2,5,63)
sys.exit()
if N==4:
print(2,5,20,63)
sys.exit()
S=[]
L=[0,2,3,4]
for i in range(1,30001):
j=i%6
if j in L:
S.append(i)
if len(S)==N-1:
break
s=sum(S)
def f(L):
return print(' '.join(map(str,L)))
if s%6==0:
f(S+[30000])
elif s%6==2:
f(S+[29998])
elif s%6==3:
f(S+[29997])
elif s%6==5:
f(S[1:]+[29997,30000])
#print(len(S),s%6)
``` | instruction | 0 | 97,697 | 22 | 195,394 |
Yes | output | 1 | 97,697 | 22 | 195,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
N = int(input())
if N == 3:
ret = [2, 5, 63]
else:
ret = []
if N <= 15000:
if N % 3 == 0:
b = 4
else:
b = 2
a = N - b
else:
a = 15000 - N%2
b = N - a
for i in range(1, a+1):
ret.append(2*i)
for i in range(b):
ret.append(3*(2 * i + 1))
assert len(ret) == N
print(' '.join([str(_) for _ in ret]))
``` | instruction | 0 | 97,698 | 22 | 195,396 |
Yes | output | 1 | 97,698 | 22 | 195,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
import random
def main():
N = int(input().strip())
cand = []
for i in range(30000 // 6):
cand.append(6 * i + 2)
cand.append(6 * i + 3)
cand.append(6 * i + 4)
cand.append(6 * i + 6)
while True:
S = [random.choice(cand) for _ in range(N)]
if sum(S) % 6 == 0:
break
return ' '.join(map(str, S))
if __name__ == '__main__':
print(main())
``` | instruction | 0 | 97,699 | 22 | 195,398 |
No | output | 1 | 97,699 | 22 | 195,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
n=int(input())
ans=[0]*n
i=0
for k in range(1,30001):
if k%2==0 or k%3==0:
ans[i]=k
i+=1
if i==n-1:
break
x=sum(ans)
def gcd(a,b):
while b:
a,b=b,a%b
return a
for k in range(30000,0,-1):
if (x+k)%6==0 and (k%2==0 or k%3==0):
ans[-1]=k
break
print(*ans)
``` | instruction | 0 | 97,700 | 22 | 195,400 |
No | output | 1 | 97,700 | 22 | 195,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
n = int(input())
h = 30000
if n == 3:
print("2 5 63")
exit()
if n == 4:
print("2 5 20 63")
exit()
if n == 5:
print("2 5 20 30 63")
exit()
pret = [2, 3, 4]
it_count = int(n/4)
pret.extend([6*i for i in range(1, it_count)])
pret.extend( [6*i + 2 for i in range(1, it_count)])
pret.extend([6*i +3 for i in range(1, it_count)])
pret.extend( [6*i + 4 for i in range(1, it_count)])
pret.sort()
ret = pret[:n]
sum_of_ret = sum(ret) % 6
if sum_of_ret == 2:
ret.remove(8)
ret.append(6* (it_count))
if sum_of_ret == 3:
ret.remove(9)
ret.append(6* (it_count))
if sum_of_ret == 5:
ret.remove(9)
ret.append(6* (it_count) + 4)
print(" ".join(list(map(str,ret))))
``` | instruction | 0 | 97,701 | 22 | 195,402 |
No | output | 1 | 97,701 | 22 | 195,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.
She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.
Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
Constraints
* 3 \leq N \leq 20000
Input
Input is given from Standard Input in the following format:
N
Output
Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :
* The elements must be distinct positive integers not exceeding 30000.
* The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.
* S is a special set.
If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.
Examples
Input
3
Output
2 5 63
Input
4
Output
2 5 20 63
Submitted Solution:
```
n=int(input())
nn=n//6
nr=n%6
if n==3:
print(2,5,63)
elif n==4:
print(2,5,20,63)
elif n==5:
print(2,5,20,30,63)
else:
Ans=[]
count=0
k=1
while count<n:
if k%6==2 or k%6==3 or k%6==4 or k%6==0:
Ans.append(k)
count+=1
k+=1
s=sum(Ans)
if s%6==2:
Ans.remove(8)
Ans.append(6*(k//6+1))
elif s%6==3:
Ans.remove(9)
Ans.append(6*(k//6+1))
elif s%6==5:
Ans.remove(9)
Ans.append(6*(k//6+1)+4)
print(*Ans)
``` | instruction | 0 | 97,702 | 22 | 195,404 |
No | output | 1 | 97,702 | 22 | 195,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,922 | 22 | 195,844 |
Tags: implementation
Correct Solution:
```
a,b,c=map(int,input().split())
def nod(a,b):
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
return max(a,b)
while True:
if c > nod(a,c):
c -= nod(a,c)
else:
print(0)
break
if c > nod(b,c):
c -= nod(b,c)
else:
print(1)
break
``` | output | 1 | 97,922 | 22 | 195,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,923 | 22 | 195,846 |
Tags: implementation
Correct Solution:
```
import math
a,b,n=map(int,input().split())
i=0
while True:
if i%2==0:
d=math.gcd(a,n)
n=n-d
if n==0:
print("0")
break
else:
d=math.gcd(b,n)
n=n-d
if n==0:
print("1")
break
i=i+1
``` | output | 1 | 97,923 | 22 | 195,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,924 | 22 | 195,848 |
Tags: implementation
Correct Solution:
```
#119A
[a,b,n] = list(map(int,input().split()))
def gcd(x,y):
p = max(x,y)
q = min(x,y)
r = p%q
while r > 0:
p = q
q = r
r = p%q
return q
i = -1
curn = n
players = [a,b]
while curn > 0:
i+=1
curp = players[i%2]
curn -= gcd(curp,curn)
print(i%2)
``` | output | 1 | 97,924 | 22 | 195,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,925 | 22 | 195,850 |
Tags: implementation
Correct Solution:
```
import math
n=list(map(int,input().split()))
i=0
while n[2]>=0:
n[2]=n[2]-math.gcd(n[i],n[2])
i=1-i
print(i)
``` | output | 1 | 97,925 | 22 | 195,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,926 | 22 | 195,852 |
Tags: implementation
Correct Solution:
```
from fractions import gcd
par = input()
par = par.split()
a = int(par[0])
b = int(par[1])
n = int(par[2])
count = 0
while 1:
if count % 2 == 0 :
r = gcd(a, n)
w = 0
else:
r = gcd(b, n)
w = 1
count += 1
if n > r:
n -= r
else:
break
print(w)
``` | output | 1 | 97,926 | 22 | 195,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,927 | 22 | 195,854 |
Tags: implementation
Correct Solution:
```
def gcd(a,b):
if b==0:
return a
else:
return gcd(b,a%b)
a,b,n=map(int,input().split())
count=0
while(1<2):
if n==0:
print(1-int(count%2))
break
else:
if count%2==0:
n-=gcd(n,a)
count+=1
else:
n-=gcd(n,b)
count+=1
``` | output | 1 | 97,927 | 22 | 195,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,928 | 22 | 195,856 |
Tags: implementation
Correct Solution:
```
def gcd(m,n):
if(m==0):
return n
elif(n==0):
return m
else:
return(gcd(min(m,n),max(m,n)%min(m,n)))
a,b,n=map(int,input().strip().split())
f=0
while(n):
if(f==0):
n-=gcd(n,a)
f=1
elif(f==1):
n-=gcd(n,b)
f=0
if(f==0):
print("1")
else:
print("0")
``` | output | 1 | 97,928 | 22 | 195,857 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note
The greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.
In the first sample the game will go like that:
* Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
* Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
* Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
* Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
* Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
* Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.
In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that. | instruction | 0 | 97,929 | 22 | 195,858 |
Tags: implementation
Correct Solution:
```
def gcd(x,y):
if x>y:
smaller=y
else:
smaller=x
if x!=0 and y!=0:
for i in range(1,smaller+1):
if y%i==0 and x%i==0:
output=i
else:
pass
else:
output=x+y
return output
a,b,c=map(int,input().split())
turn=0
while c>0:
if turn%2==0:
c-=gcd(a,c)
else:
c-=gcd(b,c)
turn+=1
if turn%2==0:
print('1')
else:
print('0')
``` | output | 1 | 97,929 | 22 | 195,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.
First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that:
* Decimal representation of x (without leading zeroes) consists of exactly n digits;
* There exists some integer y > 0 such that:
* <image>;
* decimal representation of y is a suffix of decimal representation of x.
As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.
Can you help Amr escape this embarrassing situation?
Input
Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 109).
Output
Print the required number modulo m.
Examples
Input
1 2 1000
Output
4
Input
2 2 1000
Output
45
Input
5 3 1103
Output
590
Note
A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S. | instruction | 0 | 98,238 | 22 | 196,476 |
Tags: dp, implementation
Correct Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
# M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]
def find(a,mod,n):
rem = n - len(bin(a)[2:])
ans = 0
while rem:
temp = min(rem,50)
ans = (ans + 2**temp)%mod
rem -= temp
return ans
n, k, m = li()
f=[0 for i in range(k)]
s=0
for v in range(n):
tens = 10**v%k
f=[ (sum( [f[(j+k-(x+1)*tens)%k] for x in range(9)] )+f[j])%m for j in range(k)]
for x in range(9):
f[(x+1)*tens%k]+=1
if n-v-1==0:
s+=(f[0]%m)
else:
s+=f[0]*((10**(n-v-2)*9))%m
f[0]=0
print(s%m)
``` | output | 1 | 98,238 | 22 | 196,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,351 | 22 | 196,702 |
Tags: implementation, math
Correct Solution:
```
l, r = input().split()
s = 0
for x in range(0, 34):
for y in range(0, 34):
m = (2**x)*(3**y)
if int(l) <= m <= int(r):
s += 1
print(s)
``` | output | 1 | 98,351 | 22 | 196,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,352 | 22 | 196,704 |
Tags: implementation, math
Correct Solution:
```
l, r = input().split()
l = int(l)
r = int(r)
a, b = [0] * 50, [0] * 50
a[0] = 1
b[0] = 1
for i in range(1, 40):
a[i], b[i] = a[i - 1] * 2, b[i - 1] * 3
ans = 0
for i in range(40):
for j in range(40):
if a[i] * b[j] >= l and a[i] * b[j] <= r:
ans += 1
print(ans)
``` | output | 1 | 98,352 | 22 | 196,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,353 | 22 | 196,706 |
Tags: implementation, math
Correct Solution:
```
a = [0, 1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54, 64, 72, 81, 96, 108, 128, 144, 162, 192, 216, 243, 256, 288, 324, 384, 432, 486, 512, 576, 648, 729, 768, 864, 972, 1024, 1152, 1296, 1458, 1536, 1728, 1944, 2048, 2187, 2304, 2592, 2916, 3072, 3456, 3888, 4096, 4374, 4608, 5184, 5832, 6144, 6561, 6912, 7776, 8192, 8748, 9216, 10368, 11664, 12288, 13122, 13824, 15552, 16384, 17496, 18432, 19683, 20736, 23328, 24576, 26244, 27648, 31104, 32768, 34992, 36864, 39366, 41472, 46656, 49152, 52488, 55296, 59049, 62208, 65536, 69984, 73728, 78732, 82944, 93312, 98304, 104976, 110592, 118098, 124416, 131072, 139968, 147456, 157464, 165888, 177147, 186624, 196608, 209952, 221184, 236196, 248832, 262144, 279936, 294912, 314928, 331776, 354294, 373248, 393216, 419904, 442368, 472392, 497664, 524288, 531441, 559872, 589824, 629856, 663552, 708588, 746496, 786432, 839808, 884736, 944784, 995328, 1048576, 1062882, 1119744, 1179648, 1259712, 1327104, 1417176, 1492992, 1572864, 1594323, 1679616, 1769472, 1889568, 1990656, 2097152, 2125764, 2239488, 2359296, 2519424, 2654208, 2834352, 2985984, 3145728, 3188646, 3359232, 3538944, 3779136, 3981312, 4194304, 4251528, 4478976, 4718592, 4782969, 5038848, 5308416, 5668704, 5971968, 6291456, 6377292, 6718464, 7077888, 7558272, 7962624, 8388608, 8503056, 8957952, 9437184, 9565938, 10077696, 10616832, 11337408, 11943936, 12582912, 12754584, 13436928, 14155776, 14348907, 15116544, 15925248, 16777216, 17006112, 17915904, 18874368, 19131876, 20155392, 21233664, 22674816, 23887872, 25165824, 25509168, 26873856, 28311552, 28697814, 30233088, 31850496, 33554432, 34012224, 35831808, 37748736, 38263752, 40310784, 42467328, 43046721, 45349632, 47775744, 50331648, 51018336, 53747712, 56623104, 57395628, 60466176, 63700992, 67108864, 68024448, 71663616, 75497472, 76527504, 80621568, 84934656, 86093442, 90699264, 95551488, 100663296, 102036672, 107495424, 113246208, 114791256, 120932352, 127401984, 129140163, 134217728, 136048896, 143327232, 150994944, 153055008, 161243136, 169869312, 172186884, 181398528, 191102976, 201326592, 204073344, 214990848, 226492416, 229582512, 241864704, 254803968, 258280326, 268435456, 272097792, 286654464, 301989888, 306110016, 322486272, 339738624, 344373768, 362797056, 382205952, 387420489, 402653184, 408146688, 429981696, 452984832, 459165024, 483729408, 509607936, 516560652, 536870912, 544195584, 573308928, 603979776, 612220032, 644972544, 679477248, 688747536, 725594112, 764411904, 774840978, 805306368, 816293376, 859963392, 905969664, 918330048, 967458816, 1019215872, 1033121304, 1073741824, 1088391168, 1146617856, 1162261467, 1207959552, 1224440064, 1289945088, 1358954496, 1377495072, 1451188224, 1528823808, 1549681956, 1610612736, 1632586752, 1719926784, 1811939328, 1836660096, 1934917632, 2038431744, 2066242608, 2147483648, 2176782336, 2293235712, 2324522934, 2415919104, 2448880128, 2579890176, 2717908992, 2754990144, 2902376448, 3057647616, 3099363912, 3221225472, 3265173504, 3439853568, 3486784401, 3623878656, 3673320192, 3869835264, 4076863488, 4132485216, 4294967296, 4353564672, 4586471424, 4649045868, 4831838208, 4897760256, 5159780352, 5435817984, 5509980288, 5804752896, 6115295232, 6198727824, 6442450944, 6530347008, 6879707136, 6973568802, 7247757312, 7346640384, 7739670528, 8153726976, 8264970432, 8589934592, 8707129344, 9172942848, 9298091736, 9663676416, 9795520512, 10319560704, 10460353203, 10871635968, 11019960576, 11609505792, 12230590464, 12397455648, 12884901888, 13060694016, 13759414272, 13947137604, 14495514624, 14693280768, 15479341056, 16307453952, 16529940864, 17179869184, 17414258688, 18345885696, 18596183472, 19327352832, 19591041024]
l, r = map(int, input().split())
ansr = 0
ansl = 398
while a[ansr] < r:
ansr += 1
if a[ansr] > r:
ansr -= 1
while a[ansl] > l:
ansl -= 1
if a[ansl] < l:
ansl += 1
print(ansr - ansl + 1)
``` | output | 1 | 98,353 | 22 | 196,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,354 | 22 | 196,708 |
Tags: implementation, math
Correct Solution:
```
l, r = map(int, input().split())
two = []
three = []
for i in range(31):
two.append(2 ** i)
for i in range(20):
three.append(3 ** i)
s = set()
for i in range(31):
for j in range(20):
s.add(two[i] * three[j])
k = 0
for i in s:
if l <= i <= r:
k += 1
print(k)
``` | output | 1 | 98,354 | 22 | 196,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,355 | 22 | 196,710 |
Tags: implementation, math
Correct Solution:
```
count = 0
l, r = map(int, input().split())
for i in range(50):
for j in range(50):
if l <= (2 ** i) * (3 ** j) <= r:
count += 1
if (2 ** i) * (3 ** j) > r:
break
print(count)
``` | output | 1 | 98,355 | 22 | 196,711 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,356 | 22 | 196,712 |
Tags: implementation, math
Correct Solution:
```
#import time
l, r = map(int, input().split())
checked = set()
def howNums(num):
if num in checked: return 0
checked.add(num)
c = 0
subnum1 = num * 2
subnum2 = num * 3
if(subnum1 <= r and (subnum1 not in checked)):
if(subnum1 >= l): c+=1
c+=howNums(subnum1)
#if(subnum1 >= l): print(subnum1)
if(subnum2 <= r and (subnum2 not in checked)):
if(subnum2 >= l): c+=1
c+=howNums(subnum2)
#if(subnum2 >= l): print(subnum2)
if((subnum1 > r) and (subnum2 > r)):
return 0
return c
#start_time = time.time()
count = howNums(1)
if(l is 1): count+=1
#print("ans:" + str(count))
print(count)
#print(str(time.time() - start_time))
``` | output | 1 | 98,356 | 22 | 196,713 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,357 | 22 | 196,714 |
Tags: implementation, math
Correct Solution:
```
l,r=list(map(int,input().split()))
count=0
for i in range(0,32):
temp=(1<<i)
if((temp >= l) and(temp<=r)):
count+=1
for j in range(1,21):
n=3**j
if(((n*temp)>= l) and((n*temp)<=r)):
count+=1
print(count)
``` | output | 1 | 98,357 | 22 | 196,715 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | instruction | 0 | 98,358 | 22 | 196,716 |
Tags: implementation, math
Correct Solution:
```
from collections import defaultdict
d = {}
left, right = map(int, input().split())
N = max(left, right) + 1
stack = [1]
d[1] = 1
while stack:
p = stack.pop()
for i in ( 2*p, 3*p):
if i < N:
if not i in d:
d[i] = 1
stack.append(i)
ans = 0
for a in d:
if left <= a <= right:
ans += 1
print(ans)
``` | output | 1 | 98,358 | 22 | 196,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
l,r=map(int,input().split())
counter=0
for i in range(50):
for j in range(50):
if l<=(2**i)*(3**j)<=r:
counter+=1
print(counter)
``` | instruction | 0 | 98,359 | 22 | 196,718 |
Yes | output | 1 | 98,359 | 22 | 196,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
l, r = map(int, input().split())
counter = 0
for x in range(31):
for y in range(20):
num = 2 ** x * 3 ** y
if l <= num <= r:
counter += 1
elif num > r:
break
print(counter)
``` | instruction | 0 | 98,360 | 22 | 196,720 |
Yes | output | 1 | 98,360 | 22 | 196,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
n, m = input().split()
n = int(n)
m = int(m)
ans = 0
for i in range(31):
for j in range(20):
if 2 ** i * 3 ** j >= n and 2 ** i * 3 ** j <= m:
ans = ans + 1
print(ans)
``` | instruction | 0 | 98,361 | 22 | 196,722 |
Yes | output | 1 | 98,361 | 22 | 196,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
import math
l, r=map(int,input().split())
ans = 0
if (l<=1) & (r>=1) : ans = ans + 1
if (l<=2) & (r>=2) : ans = ans + 1
if (l<=3) & (r>=3) : ans = ans + 1
if (l<=4) & (r>=4) : ans = ans + 1
if (l<=6) & (r>=6) : ans = ans + 1
if (l<=8) & (r>=8) : ans = ans + 1
if (l<=9) & (r>=9) : ans = ans + 1
if (l<=12) & (r>=12) : ans = ans + 1
if (l<=16) & (r>=16) : ans = ans + 1
if (l<=18) & (r>=18) : ans = ans + 1
if (l<=24) & (r>=24) : ans = ans + 1
if (l<=27) & (r>=27) : ans = ans + 1
if (l<=32) & (r>=32) : ans = ans + 1
if (l<=36) & (r>=36) : ans = ans + 1
if (l<=48) & (r>=48) : ans = ans + 1
if (l<=54) & (r>=54) : ans = ans + 1
if (l<=64) & (r>=64) : ans = ans + 1
if (l<=72) & (r>=72) : ans = ans + 1
if (l<=81) & (r>=81) : ans = ans + 1
if (l<=96) & (r>=96) : ans = ans + 1
if (l<=108) & (r>=108) : ans = ans + 1
if (l<=128) & (r>=128) : ans = ans + 1
if (l<=144) & (r>=144) : ans = ans + 1
if (l<=162) & (r>=162) : ans = ans + 1
if (l<=192) & (r>=192) : ans = ans + 1
if (l<=216) & (r>=216) : ans = ans + 1
if (l<=243) & (r>=243) : ans = ans + 1
if (l<=256) & (r>=256) : ans = ans + 1
if (l<=288) & (r>=288) : ans = ans + 1
if (l<=324) & (r>=324) : ans = ans + 1
if (l<=384) & (r>=384) : ans = ans + 1
if (l<=432) & (r>=432) : ans = ans + 1
if (l<=486) & (r>=486) : ans = ans + 1
if (l<=512) & (r>=512) : ans = ans + 1
if (l<=576) & (r>=576) : ans = ans + 1
if (l<=648) & (r>=648) : ans = ans + 1
if (l<=729) & (r>=729) : ans = ans + 1
if (l<=768) & (r>=768) : ans = ans + 1
if (l<=864) & (r>=864) : ans = ans + 1
if (l<=972) & (r>=972) : ans = ans + 1
if (l<=1024) & (r>=1024) : ans = ans + 1
if (l<=1152) & (r>=1152) : ans = ans + 1
if (l<=1296) & (r>=1296) : ans = ans + 1
if (l<=1458) & (r>=1458) : ans = ans + 1
if (l<=1536) & (r>=1536) : ans = ans + 1
if (l<=1728) & (r>=1728) : ans = ans + 1
if (l<=1944) & (r>=1944) : ans = ans + 1
if (l<=2048) & (r>=2048) : ans = ans + 1
if (l<=2187) & (r>=2187) : ans = ans + 1
if (l<=2304) & (r>=2304) : ans = ans + 1
if (l<=2592) & (r>=2592) : ans = ans + 1
if (l<=2916) & (r>=2916) : ans = ans + 1
if (l<=3072) & (r>=3072) : ans = ans + 1
if (l<=3456) & (r>=3456) : ans = ans + 1
if (l<=3888) & (r>=3888) : ans = ans + 1
if (l<=4096) & (r>=4096) : ans = ans + 1
if (l<=4374) & (r>=4374) : ans = ans + 1
if (l<=4608) & (r>=4608) : ans = ans + 1
if (l<=5184) & (r>=5184) : ans = ans + 1
if (l<=5832) & (r>=5832) : ans = ans + 1
if (l<=6144) & (r>=6144) : ans = ans + 1
if (l<=6561) & (r>=6561) : ans = ans + 1
if (l<=6912) & (r>=6912) : ans = ans + 1
if (l<=7776) & (r>=7776) : ans = ans + 1
if (l<=8192) & (r>=8192) : ans = ans + 1
if (l<=8748) & (r>=8748) : ans = ans + 1
if (l<=9216) & (r>=9216) : ans = ans + 1
if (l<=10368) & (r>=10368) : ans = ans + 1
if (l<=11664) & (r>=11664) : ans = ans + 1
if (l<=12288) & (r>=12288) : ans = ans + 1
if (l<=13122) & (r>=13122) : ans = ans + 1
if (l<=13824) & (r>=13824) : ans = ans + 1
if (l<=15552) & (r>=15552) : ans = ans + 1
if (l<=16384) & (r>=16384) : ans = ans + 1
if (l<=17496) & (r>=17496) : ans = ans + 1
if (l<=18432) & (r>=18432) : ans = ans + 1
if (l<=19683) & (r>=19683) : ans = ans + 1
if (l<=20736) & (r>=20736) : ans = ans + 1
if (l<=23328) & (r>=23328) : ans = ans + 1
if (l<=24576) & (r>=24576) : ans = ans + 1
if (l<=26244) & (r>=26244) : ans = ans + 1
if (l<=27648) & (r>=27648) : ans = ans + 1
if (l<=31104) & (r>=31104) : ans = ans + 1
if (l<=32768) & (r>=32768) : ans = ans + 1
if (l<=34992) & (r>=34992) : ans = ans + 1
if (l<=36864) & (r>=36864) : ans = ans + 1
if (l<=39366) & (r>=39366) : ans = ans + 1
if (l<=41472) & (r>=41472) : ans = ans + 1
if (l<=46656) & (r>=46656) : ans = ans + 1
if (l<=49152) & (r>=49152) : ans = ans + 1
if (l<=52488) & (r>=52488) : ans = ans + 1
if (l<=55296) & (r>=55296) : ans = ans + 1
if (l<=59049) & (r>=59049) : ans = ans + 1
if (l<=62208) & (r>=62208) : ans = ans + 1
if (l<=65536) & (r>=65536) : ans = ans + 1
if (l<=69984) & (r>=69984) : ans = ans + 1
if (l<=73728) & (r>=73728) : ans = ans + 1
if (l<=78732) & (r>=78732) : ans = ans + 1
if (l<=82944) & (r>=82944) : ans = ans + 1
if (l<=93312) & (r>=93312) : ans = ans + 1
if (l<=98304) & (r>=98304) : ans = ans + 1
if (l<=104976) & (r>=104976) : ans = ans + 1
if (l<=110592) & (r>=110592) : ans = ans + 1
if (l<=118098) & (r>=118098) : ans = ans + 1
if (l<=124416) & (r>=124416) : ans = ans + 1
if (l<=131072) & (r>=131072) : ans = ans + 1
if (l<=139968) & (r>=139968) : ans = ans + 1
if (l<=147456) & (r>=147456) : ans = ans + 1
if (l<=157464) & (r>=157464) : ans = ans + 1
if (l<=165888) & (r>=165888) : ans = ans + 1
if (l<=177147) & (r>=177147) : ans = ans + 1
if (l<=186624) & (r>=186624) : ans = ans + 1
if (l<=196608) & (r>=196608) : ans = ans + 1
if (l<=209952) & (r>=209952) : ans = ans + 1
if (l<=221184) & (r>=221184) : ans = ans + 1
if (l<=236196) & (r>=236196) : ans = ans + 1
if (l<=248832) & (r>=248832) : ans = ans + 1
if (l<=262144) & (r>=262144) : ans = ans + 1
if (l<=279936) & (r>=279936) : ans = ans + 1
if (l<=294912) & (r>=294912) : ans = ans + 1
if (l<=314928) & (r>=314928) : ans = ans + 1
if (l<=331776) & (r>=331776) : ans = ans + 1
if (l<=354294) & (r>=354294) : ans = ans + 1
if (l<=373248) & (r>=373248) : ans = ans + 1
if (l<=393216) & (r>=393216) : ans = ans + 1
if (l<=419904) & (r>=419904) : ans = ans + 1
if (l<=442368) & (r>=442368) : ans = ans + 1
if (l<=472392) & (r>=472392) : ans = ans + 1
if (l<=497664) & (r>=497664) : ans = ans + 1
if (l<=524288) & (r>=524288) : ans = ans + 1
if (l<=531441) & (r>=531441) : ans = ans + 1
if (l<=559872) & (r>=559872) : ans = ans + 1
if (l<=589824) & (r>=589824) : ans = ans + 1
if (l<=629856) & (r>=629856) : ans = ans + 1
if (l<=663552) & (r>=663552) : ans = ans + 1
if (l<=708588) & (r>=708588) : ans = ans + 1
if (l<=746496) & (r>=746496) : ans = ans + 1
if (l<=786432) & (r>=786432) : ans = ans + 1
if (l<=839808) & (r>=839808) : ans = ans + 1
if (l<=884736) & (r>=884736) : ans = ans + 1
if (l<=944784) & (r>=944784) : ans = ans + 1
if (l<=995328) & (r>=995328) : ans = ans + 1
if (l<=1048576) & (r>=1048576) : ans = ans + 1
if (l<=1062882) & (r>=1062882) : ans = ans + 1
if (l<=1119744) & (r>=1119744) : ans = ans + 1
if (l<=1179648) & (r>=1179648) : ans = ans + 1
if (l<=1259712) & (r>=1259712) : ans = ans + 1
if (l<=1327104) & (r>=1327104) : ans = ans + 1
if (l<=1417176) & (r>=1417176) : ans = ans + 1
if (l<=1492992) & (r>=1492992) : ans = ans + 1
if (l<=1572864) & (r>=1572864) : ans = ans + 1
if (l<=1594323) & (r>=1594323) : ans = ans + 1
if (l<=1679616) & (r>=1679616) : ans = ans + 1
if (l<=1769472) & (r>=1769472) : ans = ans + 1
if (l<=1889568) & (r>=1889568) : ans = ans + 1
if (l<=1990656) & (r>=1990656) : ans = ans + 1
if (l<=2097152) & (r>=2097152) : ans = ans + 1
if (l<=2125764) & (r>=2125764) : ans = ans + 1
if (l<=2239488) & (r>=2239488) : ans = ans + 1
if (l<=2359296) & (r>=2359296) : ans = ans + 1
if (l<=2519424) & (r>=2519424) : ans = ans + 1
if (l<=2654208) & (r>=2654208) : ans = ans + 1
if (l<=2834352) & (r>=2834352) : ans = ans + 1
if (l<=2985984) & (r>=2985984) : ans = ans + 1
if (l<=3145728) & (r>=3145728) : ans = ans + 1
if (l<=3188646) & (r>=3188646) : ans = ans + 1
if (l<=3359232) & (r>=3359232) : ans = ans + 1
if (l<=3538944) & (r>=3538944) : ans = ans + 1
if (l<=3779136) & (r>=3779136) : ans = ans + 1
if (l<=3981312) & (r>=3981312) : ans = ans + 1
if (l<=4194304) & (r>=4194304) : ans = ans + 1
if (l<=4251528) & (r>=4251528) : ans = ans + 1
if (l<=4478976) & (r>=4478976) : ans = ans + 1
if (l<=4718592) & (r>=4718592) : ans = ans + 1
if (l<=4782969) & (r>=4782969) : ans = ans + 1
if (l<=5038848) & (r>=5038848) : ans = ans + 1
if (l<=5308416) & (r>=5308416) : ans = ans + 1
if (l<=5668704) & (r>=5668704) : ans = ans + 1
if (l<=5971968) & (r>=5971968) : ans = ans + 1
if (l<=6291456) & (r>=6291456) : ans = ans + 1
if (l<=6377292) & (r>=6377292) : ans = ans + 1
if (l<=6718464) & (r>=6718464) : ans = ans + 1
if (l<=7077888) & (r>=7077888) : ans = ans + 1
if (l<=7558272) & (r>=7558272) : ans = ans + 1
if (l<=7962624) & (r>=7962624) : ans = ans + 1
if (l<=8388608) & (r>=8388608) : ans = ans + 1
if (l<=8503056) & (r>=8503056) : ans = ans + 1
if (l<=8957952) & (r>=8957952) : ans = ans + 1
if (l<=9437184) & (r>=9437184) : ans = ans + 1
if (l<=9565938) & (r>=9565938) : ans = ans + 1
if (l<=10077696) & (r>=10077696) : ans = ans + 1
if (l<=10616832) & (r>=10616832) : ans = ans + 1
if (l<=11337408) & (r>=11337408) : ans = ans + 1
if (l<=11943936) & (r>=11943936) : ans = ans + 1
if (l<=12582912) & (r>=12582912) : ans = ans + 1
if (l<=12754584) & (r>=12754584) : ans = ans + 1
if (l<=13436928) & (r>=13436928) : ans = ans + 1
if (l<=14155776) & (r>=14155776) : ans = ans + 1
if (l<=14348907) & (r>=14348907) : ans = ans + 1
if (l<=15116544) & (r>=15116544) : ans = ans + 1
if (l<=15925248) & (r>=15925248) : ans = ans + 1
if (l<=16777216) & (r>=16777216) : ans = ans + 1
if (l<=17006112) & (r>=17006112) : ans = ans + 1
if (l<=17915904) & (r>=17915904) : ans = ans + 1
if (l<=18874368) & (r>=18874368) : ans = ans + 1
if (l<=19131876) & (r>=19131876) : ans = ans + 1
if (l<=20155392) & (r>=20155392) : ans = ans + 1
if (l<=21233664) & (r>=21233664) : ans = ans + 1
if (l<=22674816) & (r>=22674816) : ans = ans + 1
if (l<=23887872) & (r>=23887872) : ans = ans + 1
if (l<=25165824) & (r>=25165824) : ans = ans + 1
if (l<=25509168) & (r>=25509168) : ans = ans + 1
if (l<=26873856) & (r>=26873856) : ans = ans + 1
if (l<=28311552) & (r>=28311552) : ans = ans + 1
if (l<=28697814) & (r>=28697814) : ans = ans + 1
if (l<=30233088) & (r>=30233088) : ans = ans + 1
if (l<=31850496) & (r>=31850496) : ans = ans + 1
if (l<=33554432) & (r>=33554432) : ans = ans + 1
if (l<=34012224) & (r>=34012224) : ans = ans + 1
if (l<=35831808) & (r>=35831808) : ans = ans + 1
if (l<=37748736) & (r>=37748736) : ans = ans + 1
if (l<=38263752) & (r>=38263752) : ans = ans + 1
if (l<=40310784) & (r>=40310784) : ans = ans + 1
if (l<=42467328) & (r>=42467328) : ans = ans + 1
if (l<=43046721) & (r>=43046721) : ans = ans + 1
if (l<=45349632) & (r>=45349632) : ans = ans + 1
if (l<=47775744) & (r>=47775744) : ans = ans + 1
if (l<=50331648) & (r>=50331648) : ans = ans + 1
if (l<=51018336) & (r>=51018336) : ans = ans + 1
if (l<=53747712) & (r>=53747712) : ans = ans + 1
if (l<=56623104) & (r>=56623104) : ans = ans + 1
if (l<=57395628) & (r>=57395628) : ans = ans + 1
if (l<=60466176) & (r>=60466176) : ans = ans + 1
if (l<=63700992) & (r>=63700992) : ans = ans + 1
if (l<=67108864) & (r>=67108864) : ans = ans + 1
if (l<=68024448) & (r>=68024448) : ans = ans + 1
if (l<=71663616) & (r>=71663616) : ans = ans + 1
if (l<=75497472) & (r>=75497472) : ans = ans + 1
if (l<=76527504) & (r>=76527504) : ans = ans + 1
if (l<=80621568) & (r>=80621568) : ans = ans + 1
if (l<=84934656) & (r>=84934656) : ans = ans + 1
if (l<=86093442) & (r>=86093442) : ans = ans + 1
if (l<=90699264) & (r>=90699264) : ans = ans + 1
if (l<=95551488) & (r>=95551488) : ans = ans + 1
if (l<=100663296) & (r>=100663296) : ans = ans + 1
if (l<=102036672) & (r>=102036672) : ans = ans + 1
if (l<=107495424) & (r>=107495424) : ans = ans + 1
if (l<=113246208) & (r>=113246208) : ans = ans + 1
if (l<=114791256) & (r>=114791256) : ans = ans + 1
if (l<=120932352) & (r>=120932352) : ans = ans + 1
if (l<=127401984) & (r>=127401984) : ans = ans + 1
if (l<=129140163) & (r>=129140163) : ans = ans + 1
if (l<=134217728) & (r>=134217728) : ans = ans + 1
if (l<=136048896) & (r>=136048896) : ans = ans + 1
if (l<=143327232) & (r>=143327232) : ans = ans + 1
if (l<=150994944) & (r>=150994944) : ans = ans + 1
if (l<=153055008) & (r>=153055008) : ans = ans + 1
if (l<=161243136) & (r>=161243136) : ans = ans + 1
if (l<=169869312) & (r>=169869312) : ans = ans + 1
if (l<=172186884) & (r>=172186884) : ans = ans + 1
if (l<=181398528) & (r>=181398528) : ans = ans + 1
if (l<=191102976) & (r>=191102976) : ans = ans + 1
if (l<=201326592) & (r>=201326592) : ans = ans + 1
if (l<=204073344) & (r>=204073344) : ans = ans + 1
if (l<=214990848) & (r>=214990848) : ans = ans + 1
if (l<=226492416) & (r>=226492416) : ans = ans + 1
if (l<=229582512) & (r>=229582512) : ans = ans + 1
if (l<=241864704) & (r>=241864704) : ans = ans + 1
if (l<=254803968) & (r>=254803968) : ans = ans + 1
if (l<=258280326) & (r>=258280326) : ans = ans + 1
if (l<=268435456) & (r>=268435456) : ans = ans + 1
if (l<=272097792) & (r>=272097792) : ans = ans + 1
if (l<=286654464) & (r>=286654464) : ans = ans + 1
if (l<=301989888) & (r>=301989888) : ans = ans + 1
if (l<=306110016) & (r>=306110016) : ans = ans + 1
if (l<=322486272) & (r>=322486272) : ans = ans + 1
if (l<=339738624) & (r>=339738624) : ans = ans + 1
if (l<=344373768) & (r>=344373768) : ans = ans + 1
if (l<=362797056) & (r>=362797056) : ans = ans + 1
if (l<=382205952) & (r>=382205952) : ans = ans + 1
if (l<=387420489) & (r>=387420489) : ans = ans + 1
if (l<=402653184) & (r>=402653184) : ans = ans + 1
if (l<=408146688) & (r>=408146688) : ans = ans + 1
if (l<=429981696) & (r>=429981696) : ans = ans + 1
if (l<=452984832) & (r>=452984832) : ans = ans + 1
if (l<=459165024) & (r>=459165024) : ans = ans + 1
if (l<=483729408) & (r>=483729408) : ans = ans + 1
if (l<=509607936) & (r>=509607936) : ans = ans + 1
if (l<=516560652) & (r>=516560652) : ans = ans + 1
if (l<=536870912) & (r>=536870912) : ans = ans + 1
if (l<=544195584) & (r>=544195584) : ans = ans + 1
if (l<=573308928) & (r>=573308928) : ans = ans + 1
if (l<=603979776) & (r>=603979776) : ans = ans + 1
if (l<=612220032) & (r>=612220032) : ans = ans + 1
if (l<=644972544) & (r>=644972544) : ans = ans + 1
if (l<=679477248) & (r>=679477248) : ans = ans + 1
if (l<=688747536) & (r>=688747536) : ans = ans + 1
if (l<=725594112) & (r>=725594112) : ans = ans + 1
if (l<=764411904) & (r>=764411904) : ans = ans + 1
if (l<=774840978) & (r>=774840978) : ans = ans + 1
if (l<=805306368) & (r>=805306368) : ans = ans + 1
if (l<=816293376) & (r>=816293376) : ans = ans + 1
if (l<=859963392) & (r>=859963392) : ans = ans + 1
if (l<=905969664) & (r>=905969664) : ans = ans + 1
if (l<=918330048) & (r>=918330048) : ans = ans + 1
if (l<=967458816) & (r>=967458816) : ans = ans + 1
if (l<=1019215872) & (r>=1019215872) : ans = ans + 1
if (l<=1033121304) & (r>=1033121304) : ans = ans + 1
if (l<=1073741824) & (r>=1073741824) : ans = ans + 1
if (l<=1088391168) & (r>=1088391168) : ans = ans + 1
if (l<=1146617856) & (r>=1146617856) : ans = ans + 1
if (l<=1162261467) & (r>=1162261467) : ans = ans + 1
if (l<=1207959552) & (r>=1207959552) : ans = ans + 1
if (l<=1224440064) & (r>=1224440064) : ans = ans + 1
if (l<=1289945088) & (r>=1289945088) : ans = ans + 1
if (l<=1358954496) & (r>=1358954496) : ans = ans + 1
if (l<=1377495072) & (r>=1377495072) : ans = ans + 1
if (l<=1451188224) & (r>=1451188224) : ans = ans + 1
if (l<=1528823808) & (r>=1528823808) : ans = ans + 1
if (l<=1549681956) & (r>=1549681956) : ans = ans + 1
if (l<=1610612736) & (r>=1610612736) : ans = ans + 1
if (l<=1632586752) & (r>=1632586752) : ans = ans + 1
if (l<=1719926784) & (r>=1719926784) : ans = ans + 1
if (l<=1811939328) & (r>=1811939328) : ans = ans + 1
if (l<=1836660096) & (r>=1836660096) : ans = ans + 1
if (l<=1934917632) & (r>=1934917632) : ans = ans + 1
print(ans)
``` | instruction | 0 | 98,362 | 22 | 196,724 |
Yes | output | 1 | 98,362 | 22 | 196,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
import math
l,r = map(int,input().split())
a,b = math.log(2),math.log(3)
t = math.log(r)
z = math.log(r)
i = 1
toe = 0
while (t>=0):
toe += int(t/b)+1
t = z - i*a
i += 1
if l == 1:
print(toe)
else:
t = math.log(l-1)
z = math.log(l-1)
i = 1
toi = 0
while (t>=0):
y = t/b
toi += int(t/b)+1
t = z - i*a
i += 1
print(toe-toi)
``` | instruction | 0 | 98,363 | 22 | 196,726 |
No | output | 1 | 98,363 | 22 | 196,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
l, r = map(int, input().split())
print(sum(l <= 2 ** i * 3 ** j <= r for i in range(29) for j in range(20)))
``` | instruction | 0 | 98,364 | 22 | 196,728 |
No | output | 1 | 98,364 | 22 | 196,729 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
import math
l,r = map(int,input().split())
a,b = math.log(2),math.log(3)
if l == 1:
t,z = math.log(r), math.log(r)
i,toe = 1,0
while (t>=0):
toe += int(t/b)+1
t = z - i*a
i += 1
print(toe)
else:
t,z = math.log(l-1), math.log(l-1)
i,toi = 1,0
while (t>=0):
toi += int(t/b)+1
t = z - i*a
i += 1
print(toe-toi)
``` | instruction | 0 | 98,365 | 22 | 196,730 |
No | output | 1 | 98,365 | 22 | 196,731 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.
Input
The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).
Output
Print a single integer the number of 2-3-integers on the segment [l, r].
Examples
Input
1 10
Output
7
Input
100 200
Output
5
Input
1 2000000000
Output
326
Note
In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192.
Submitted Solution:
```
l, r = input().split()
l = (int(l))
r = (int(r))
a = set()
sc = 0
for i in range (0, 30):
cur = 2**i
for j in range (0, 20):
if cur > r:
break
if cur >= l:
a.add(cur)
cur *= 3
print(len(a))
``` | instruction | 0 | 98,366 | 22 | 196,732 |
No | output | 1 | 98,366 | 22 | 196,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace "Zmey-Gorynych", and offers Alex a job: if he shows his programming skills by solving a task, he'll work as a cybersecurity specialist. Otherwise, he'll be delivering some doubtful products for the next two years.
You're given n positive integers a_1, a_2, ..., a_n. Using each of them exactly at once, you're to make such sequence b_1, b_2, ..., b_n that sequence c_1, c_2, ..., c_n is lexicographically maximal, where c_i=GCD(b_1,...,b_i) - the greatest common divisor of the first i elements of b.
Alexander is really afraid of the conditions of this simple task, so he asks you to solve it.
A sequence a is lexicographically smaller than a sequence b if and only if one of the following holds:
* a is a prefix of b, but a ≠ b;
* in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^3). Description of the test cases follows.
The first line of each test case contains a single integer n (1 ≤ n ≤ 10^3) — the length of the sequence a.
The second line of each test case contains n integers a_1,...,a_n (1 ≤ a_i ≤ 10^3) — the sequence a.
It is guaranteed that the sum of n over all test cases does not exceed 10^3.
Output
For each test case output the answer in a single line — the desired sequence b. If there are multiple answers, print any.
Example
Input
7
2
2 5
4
1 8 2 3
3
3 8 9
5
64 25 75 100 50
1
42
6
96 128 88 80 52 7
5
2 4 8 16 17
Output
5 2
8 2 1 3
9 3 8
100 50 25 75 64
42
128 96 80 88 52 7
17 2 4 8 16
Note
In the first test case of the example, there are only two possible permutations b — [2, 5] and [5, 2]: for the first one c=[2, 1], for the second one c=[5, 1].
In the third test case of the example, number 9 should be the first in b, and GCD(9, 3)=3, GCD(9, 8)=1, so the second number of b should be 3.
In the seventh test case of the example, first four numbers pairwise have a common divisor (a power of two), but none of them can be the first in the optimal permutation b. | instruction | 0 | 98,824 | 22 | 197,648 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
t=int(input())
import math
while t:
t-=1
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=[]
ans.append(a[n-1])
del a[n-1]
curg=ans[0]
while len(a):
ma=0
inl=0
flag=0
mi=1
for i in range(len(a)):
if math.gcd(curg,a[i])>mi:
ma=a[i]
inl=i
mi=math.gcd(curg,a[i])
flag+=1
if flag==0:
break
else:
ans.append(ma)
del a[inl]
curg=math.gcd(curg,ans[-1])
ans+=a
print(*ans,sep=" ")
``` | output | 1 | 98,824 | 22 | 197,649 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace "Zmey-Gorynych", and offers Alex a job: if he shows his programming skills by solving a task, he'll work as a cybersecurity specialist. Otherwise, he'll be delivering some doubtful products for the next two years.
You're given n positive integers a_1, a_2, ..., a_n. Using each of them exactly at once, you're to make such sequence b_1, b_2, ..., b_n that sequence c_1, c_2, ..., c_n is lexicographically maximal, where c_i=GCD(b_1,...,b_i) - the greatest common divisor of the first i elements of b.
Alexander is really afraid of the conditions of this simple task, so he asks you to solve it.
A sequence a is lexicographically smaller than a sequence b if and only if one of the following holds:
* a is a prefix of b, but a ≠ b;
* in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^3). Description of the test cases follows.
The first line of each test case contains a single integer n (1 ≤ n ≤ 10^3) — the length of the sequence a.
The second line of each test case contains n integers a_1,...,a_n (1 ≤ a_i ≤ 10^3) — the sequence a.
It is guaranteed that the sum of n over all test cases does not exceed 10^3.
Output
For each test case output the answer in a single line — the desired sequence b. If there are multiple answers, print any.
Example
Input
7
2
2 5
4
1 8 2 3
3
3 8 9
5
64 25 75 100 50
1
42
6
96 128 88 80 52 7
5
2 4 8 16 17
Output
5 2
8 2 1 3
9 3 8
100 50 25 75 64
42
128 96 80 88 52 7
17 2 4 8 16
Note
In the first test case of the example, there are only two possible permutations b — [2, 5] and [5, 2]: for the first one c=[2, 1], for the second one c=[5, 1].
In the third test case of the example, number 9 should be the first in b, and GCD(9, 3)=3, GCD(9, 8)=1, so the second number of b should be 3.
In the seventh test case of the example, first four numbers pairwise have a common divisor (a power of two), but none of them can be the first in the optimal permutation b. | instruction | 0 | 98,825 | 22 | 197,650 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
from sys import stdin
def inp():
return stdin.buffer.readline().rstrip().decode('utf8')
def itg():
return int(stdin.buffer.readline())
def mpint():
return map(int, stdin.buffer.readline().split())
# ############################## import
def gcd(x, y):
"""greatest common divisor of x and y"""
while y:
x, y = y, x % y
return x
# ############################## main
from collections import Counter
for __ in range(itg()):
n = itg()
arr = list(mpint())
arr.sort()
gg = arr.pop()
ans = [gg]
counter = Counter(arr)
while counter:
best_key, best_value = None, 0
for key in counter.keys():
g = gcd(key, gg)
if g > best_value:
best_key, best_value = key, g
elif g == best_value:
best_key = max(best_key, key)
ans.append(best_key)
gg = gcd(gg, best_key)
counter[best_key] -= 1
if counter[best_key] == 0:
del counter[best_key]
print(*ans)
# Please check!
``` | output | 1 | 98,825 | 22 | 197,651 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace "Zmey-Gorynych", and offers Alex a job: if he shows his programming skills by solving a task, he'll work as a cybersecurity specialist. Otherwise, he'll be delivering some doubtful products for the next two years.
You're given n positive integers a_1, a_2, ..., a_n. Using each of them exactly at once, you're to make such sequence b_1, b_2, ..., b_n that sequence c_1, c_2, ..., c_n is lexicographically maximal, where c_i=GCD(b_1,...,b_i) - the greatest common divisor of the first i elements of b.
Alexander is really afraid of the conditions of this simple task, so he asks you to solve it.
A sequence a is lexicographically smaller than a sequence b if and only if one of the following holds:
* a is a prefix of b, but a ≠ b;
* in the first position where a and b differ, the sequence a has a smaller element than the corresponding element in b.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^3). Description of the test cases follows.
The first line of each test case contains a single integer n (1 ≤ n ≤ 10^3) — the length of the sequence a.
The second line of each test case contains n integers a_1,...,a_n (1 ≤ a_i ≤ 10^3) — the sequence a.
It is guaranteed that the sum of n over all test cases does not exceed 10^3.
Output
For each test case output the answer in a single line — the desired sequence b. If there are multiple answers, print any.
Example
Input
7
2
2 5
4
1 8 2 3
3
3 8 9
5
64 25 75 100 50
1
42
6
96 128 88 80 52 7
5
2 4 8 16 17
Output
5 2
8 2 1 3
9 3 8
100 50 25 75 64
42
128 96 80 88 52 7
17 2 4 8 16
Note
In the first test case of the example, there are only two possible permutations b — [2, 5] and [5, 2]: for the first one c=[2, 1], for the second one c=[5, 1].
In the third test case of the example, number 9 should be the first in b, and GCD(9, 3)=3, GCD(9, 8)=1, so the second number of b should be 3.
In the seventh test case of the example, first four numbers pairwise have a common divisor (a power of two), but none of them can be the first in the optimal permutation b. | instruction | 0 | 98,826 | 22 | 197,652 |
Tags: brute force, greedy, math, number theory
Correct Solution:
```
import sys
sys.setrecursionlimit(10**6)
from collections import Counter,defaultdict as dft
def mp():return map(int,input().split())
def ml():return list(map(int,input().split()))
def solve():
n=int(input())
arr=ml()
vis=[0]*(n+5)
#print(fac)
arr.sort(reverse=True)
res=[]
for p in range(10**3+1,0,-1):
case=0
for i in range(len(res)):
if res[i]%p!=0:
case=1
break
if case:
continue
for i in range(n):
if vis[i]==0 and arr[i]%p==0:
res.append(arr[i])
vis[i]=1
print(*res)
t=int(input())
for _ in range(t):
solve()
#pass
``` | output | 1 | 98,826 | 22 | 197,653 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.