message
stringlengths
2
57.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
61
108k
cluster
float64
22
22
__index_level_0__
int64
122
217k
Provide tags and a correct Python 3 solution for this coding contest problem. You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x). Input The first line contains the single positive integer n (1 ≀ n ...
instruction
0
11,250
22
22,500
Tags: brute force, data structures, implementation, math Correct Solution: ``` from collections import Counter,defaultdict,deque #import heapq as hq #import itertools from operator import itemgetter #from itertools import count, islice #from functools import reduce #alph = 'abcdefghijklmnopqrstuvwxyz' #from math import...
output
1
11,250
22
22,501
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite n...
instruction
0
11,382
22
22,764
Tags: implementation, math Correct Solution: ``` def mod(b, q): #computes b^k mod q for large k for i in range(6): b = (b * b) % q return b n = int(input()) s = '' for i in range(n - 1): p, q, b = list(map(int, input().split())) if (p * mod(b, q))%q: #checks if p * b^k is not divisible by q for...
output
1
11,382
22
22,765
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite n...
instruction
0
11,383
22
22,766
Tags: implementation, math Correct Solution: ``` n = int(input()) s = '' for i in range(n): p, q, b = map(int, input().split()) for i in range(6): b = (b * b) % q if ((p * b) % q): s += 'Infinite\n' else: s += 'Finite\n' print(s) ```
output
1
11,383
22
22,767
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite n...
instruction
0
11,384
22
22,768
Tags: implementation, math Correct Solution: ``` import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) import math for i in range(n): p, q, b = map(int, input().split()) g = math.gcd(p, q) p //= g q //= g if p == 0 or q == 1: print('Finite') ...
output
1
11,384
22
22,769
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite n...
instruction
0
11,385
22
22,770
Tags: implementation, math Correct Solution: ``` print('\n'.join([(lambda p, q, b: 'Infinite' if p * pow(b, 99, q) % q else 'Finite')(*map(int, input().split())) for _ in range(int(input()))])) ```
output
1
11,385
22
22,771
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite n...
instruction
0
11,386
22
22,772
Tags: implementation, math Correct Solution: ``` print('\n'.join(('F','Inf')[pow(b,64,q)*p%q>0]+'inite'for p,q,b in(map(int,input().split())for _ in[0]*int(input())))) ```
output
1
11,386
22
22,773
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notation with base b is finite if it contains finite n...
instruction
0
11,387
22
22,774
Tags: implementation, math Correct Solution: ``` from sys import stdin, stdout n=int(stdin.readline()) s='' for i in range(n): p,q,b=map(int,input().split()) for i in range(6): b=(b*b)%q if((p*b)%q): s+='Infinite\n' else: s+='Finite\n' print(s) ```
output
1
11,387
22
22,775
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notatio...
instruction
0
11,388
22
22,776
No
output
1
11,388
22
22,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notatio...
instruction
0
11,389
22
22,778
No
output
1
11,389
22
22,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notatio...
instruction
0
11,390
22
22,780
No
output
1
11,390
22
22,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given several queries. Each query consists of three integers p, q and b. You need to answer whether the result of p/q in notation with base b is a finite fraction. A fraction in notatio...
instruction
0
11,391
22
22,782
No
output
1
11,391
22
22,783
Provide tags and a correct Python 3 solution for this coding contest problem. Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of s...
instruction
0
11,764
22
23,528
Tags: brute force, dfs and similar, math, number theory Correct Solution: ``` def gc(a,b,rs): if b==1: return [1,rs+a-1] if b==0: return [a,rs] rs+=(a//b) return gc(b,a%b,rs) x=int(input()) res=10**9 for n in range(1,x): u=gc(x,n,0) if u[0]==1: res=min(res,u[1]) if res...
output
1
11,764
22
23,529
Provide tags and a correct Python 3 solution for this coding contest problem. Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of s...
instruction
0
11,765
22
23,530
Tags: brute force, dfs and similar, math, number theory Correct Solution: ``` def solve(N, M): ans = 0 while M > 1: ans += N // M N, M = M, N % M if M == 0: return 1000000 return N - 1 + ans N = int(input()) ans = 1000000 for M in range(1, N + 1): ans = min([ans, solve(N, M)]) print...
output
1
11,765
22
23,531
Provide tags and a correct Python 3 solution for this coding contest problem. Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of s...
instruction
0
11,768
22
23,536
Tags: brute force, dfs and similar, math, number theory Correct Solution: ``` def calc(n,m): ans=0 while(m>1): ans+=n//m n,m=m,n%m if m==0: return float("inf") return ans+n-1 n=int(input()) ans=n-1 for i in range(1,n+1): ans=min(ans,calc(n,i)) print(ans) ```
output
1
11,768
22
23,537
Provide tags and a correct Python 3 solution for this coding contest problem. Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of s...
instruction
0
11,771
22
23,542
Tags: brute force, dfs and similar, math, number theory Correct Solution: ``` TMP = 0 def dfs(a, b, n): global TMP if not b: TMP = n return None if b == 1: TMP += a - 1 return None TMP += a // b dfs(b, a % b, n) class CodeforcesTask134BSolution: def __init__(s...
output
1
11,771
22
23,543
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,844
22
23,688
Tags: brute force, greedy, math, number theory Correct Solution: ``` import sys input=sys.stdin.buffer.readline for t in range(int(input())): A,B=map(int,input().split()) X=0 C,D=A,B if B==1: X=1 D=2 while C>0: C//=D X+=1 ANS=X for i in range(1,X): C,D=A,B+i while C>0: C//=D...
output
1
11,844
22
23,689
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,845
22
23,690
Tags: brute force, greedy, math, number theory Correct Solution: ``` import sys from collections import defaultdict as dd from collections import Counter as cc from queue import Queue import math from math import sqrt import itertools try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') exc...
output
1
11,845
22
23,691
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,846
22
23,692
Tags: brute force, greedy, math, number theory Correct Solution: ``` def do(cnt,a,b): while a>=1: cnt+=1 a=a//b return cnt for _ in range(int(input())): a,b=[int(x) for x in input().split()] cnt=0 if b==1: b+=1;cnt+=1 print(min([do(cnt+i,a,b+i) for i in range(10)])) ...
output
1
11,846
22
23,693
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,847
22
23,694
Tags: brute force, greedy, math, number theory Correct Solution: ``` import math for _ in range(int(input())): s=0 min = 9999 a, b = input().split() a, b = int(a), int(b) for i in range(b, b+20): if i == 1: continue s1 = math.ceil(math.log(a, i)) + (i-b) if a // p...
output
1
11,847
22
23,695
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,848
22
23,696
Tags: brute force, greedy, math, number theory Correct Solution: ``` import sys input = sys.stdin.readline import math t = int(input()) for f in range(t): a,b = map(int,input().split()) ans = 1000000000 for i in range(10000): temp = i check = b comp = a check += i if...
output
1
11,848
22
23,697
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,849
22
23,698
Tags: brute force, greedy, math, number theory Correct Solution: ``` for _ in range(int(input())): a, b = map(int, input().split()) ans = float("inf") i = 0 while i*i <= a: if b == 1 and i == 0: i += 1 continue c = a count = i while c: ...
output
1
11,849
22
23,699
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,850
22
23,700
Tags: brute force, greedy, math, number theory Correct Solution: ``` import math def f(a, b): cnt = 0 while a != 0: a //= b cnt += 1 return cnt t = int(input()) for _ in range(t): a, b = map(int, input().split()) ans = 32 if b < 10: for i in range(max(2, b), 10): cur = i - b + f(a, i) ...
output
1
11,850
22
23,701
Provide tags and a correct Python 3 solution for this coding contest problem. You have two positive integers a and b. You can perform two kinds of operations: * a = ⌊ a/b βŒ‹ (replace a with the integer part of the division between a and b) * b=b+1 (increase b by 1) Find the minimum number of operations requi...
instruction
0
11,851
22
23,702
Tags: brute force, greedy, math, number theory Correct Solution: ``` import sys def get_array(): return list(map(int , sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() import math for _ in range(int(input())): ...
output
1
11,851
22
23,703
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,210
22
24,420
Tags: constructive algorithms Correct Solution: ``` n, x = map(int, input().split()) if n == 1: print("YES") print(x) exit() elif n == 2: if x == 0: print("NO") else: print("YES") print(0, x) exit() l = [i for i in range(1, n-2)] v = 0 for i in range(1,n-2): v = v^i r...
output
1
12,210
22
24,421
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,211
22
24,422
Tags: constructive algorithms Correct Solution: ``` n, x = map(int, input().split()) if n == 2 and x == 0: print('NO') exit() if n == 1: print('YES') print(x) exit() a = [i for i in range(1, n-2)] xr = 0 for i in a: xr ^= i if xr == x: a += [2**17, 2**18, 2**17 ^ 2**18] else: if n >=3: ...
output
1
12,211
22
24,423
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,212
22
24,424
Tags: constructive algorithms Correct Solution: ``` n, x = map(int, input().split()) if n == 2 and x == 0: print("NO") else: print("YES") if n > 1: temp = x for i in range(n-1): temp ^= i if temp: for i in range(1, n-1): print(i, end = ' ') print(2**17, 2**17 + temp) else: ...
output
1
12,212
22
24,425
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,213
22
24,426
Tags: constructive algorithms Correct Solution: ``` def main(): n, x = map(int, input().split()) if n == 1: print('YES') print(x) return if n == 2: if x == 0: print('NO') else: print('YES') print(0, x) return o = 0 f...
output
1
12,213
22
24,427
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,214
22
24,428
Tags: constructive algorithms Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Mon Jun 26 14:24:58 2017 """ def xor(a,b): a=bin(a)[2:] b=bin(b)[2:] while(len(a)>len(b)): b='0' + b while(len(b)>len(a)): a='0' + a c=['0']*len(a) for i in range(len(a)): if(a[i]!...
output
1
12,214
22
24,429
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,215
22
24,430
Tags: constructive algorithms Correct Solution: ``` def comp(n) : if n % 4 == 0 : return n if n % 4 == 1 : return 1 if n % 4 == 2 : return n + 1 return 0 n , x = map(int,input().split()) a=1<<17 if n==2: if x==0: print("NO") else: print("YES") ...
output
1
12,215
22
24,431
Provide tags and a correct Python 3 solution for this coding contest problem. Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of...
instruction
0
12,216
22
24,432
Tags: constructive algorithms Correct Solution: ``` from sys import stdin, stdout class Solve: def __init__(self): R = stdin.readline W = stdout.write n, x = map(int, R().split()) ans = [] if n == 2 and x == 0: W('NO\n') return elif n == 1: W('YES\n%d' % x) return ...
output
1
12,216
22
24,433
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,602
22
25,204
Tags: greedy, implementation, math, sortings Correct Solution: ``` #!/usr/bin/env python #pyrival orz import os import sys from io import BytesIO, IOBase """ for _ in range(int(input())): n,m=map(int,input().split()) n=int(input()) a = [int(x) for x in input().split()] """ def main(): mod=10**9+7 ...
output
1
12,602
22
25,205
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,603
22
25,206
Tags: greedy, implementation, math, sortings Correct Solution: ``` import sys readline = sys.stdin.readline T = int(readline()) Ans = [None]*T MOD = 10**9+7 mod = 10**9+9 for qu in range(T): N, P = map(int, readline().split()) A = list(map(int, readline().split())) if P == 1: if N&1: An...
output
1
12,603
22
25,207
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,604
22
25,208
Tags: greedy, implementation, math, sortings Correct Solution: ``` #created by nit1n import sys input = sys.stdin.readline m = 1000000007 for T in range(int(input())) : n, p = list(map(int ,input().split())) arr = list(map(int, input().split())) if p ==1 : if n&1 : print(1) else...
output
1
12,604
22
25,209
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,605
22
25,210
Tags: greedy, implementation, math, sortings Correct Solution: ``` from sys import stdin,stderr def rl(): return [int(w) for w in stdin.readline().split()] M = 1000000007 def pow(p, x): r = 1 p2k = p while x > 0: if x & 1: r = r * p2k % M x >>= 1 p2k = p2k * p2k % M...
output
1
12,605
22
25,211
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,606
22
25,212
Tags: greedy, implementation, math, sortings Correct Solution: ``` # ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ---...
output
1
12,606
22
25,213
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,607
22
25,214
Tags: greedy, implementation, math, sortings Correct Solution: ``` import sys input = sys.stdin.readline for _ in range(int(input())): n, p = map(int, input().split()) s = list(map(int, input().split())) s.sort(reverse=True) if p == 1: print(n % 2) continue c = -1 ci = 0 ...
output
1
12,607
22
25,215
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,608
22
25,216
Tags: greedy, implementation, math, sortings Correct Solution: ``` from sys import stdin, gettrace, stdout from collections import defaultdict if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def modInt(mod): class...
output
1
12,608
22
25,217
Provide tags and a correct Python 3 solution for this coding contest problem. Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems...
instruction
0
12,609
22
25,218
Tags: greedy, implementation, math, sortings Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) P = 10 ** 9 + 7 for _ in range(T): N, b = map(int, input().split()) A = sorted([int(a) for a in input().split()]) if b == 1: print(N % 2) continue ...
output
1
12,609
22
25,219
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,891
22
25,782
Tags: geometry, math Correct Solution: ``` import sys a, b = list(map(int, sys.stdin.readline().split())) if b > a : print(-1) elif b == a: print(a) else: t = (a+b)/(2*int((a+b)/b/2)) print(t) ```
output
1
12,891
22
25,783
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,892
22
25,784
Tags: geometry, math Correct Solution: ``` a, b = map(int, input().split()) if a < b: print(-1) else: print((a + b) / (2 * ((a + b) // (2 * b)))) ```
output
1
12,892
22
25,785
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,894
22
25,788
Tags: geometry, math Correct Solution: ``` a,b = map(float,input().split(" ")) if a==b: print(b) elif a<b: print(-1) else: n=(a-b)//b+1 if n%2==0:n-=1 if n>1: x1=(a-b)/(n-1) else: x1=999999999999999999 n=(a+b)//b-1 if n%2==0:n-=1 x2=(a+b)/(n+1) print(min(x1,x2)) ```
output
1
12,894
22
25,789
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,895
22
25,790
Tags: geometry, math Correct Solution: ``` from fractions import Fraction def solve(a, b): x = Fraction(b) n = a // (x*2) a_ = a % (x*2) if b > a: return -1 if a_ == x: return float(x) if a_ < x: return float((a+b)/(2*n)) if a_ > x: return float((a+b)/(2*n+2...
output
1
12,895
22
25,791
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,896
22
25,792
Tags: geometry, math Correct Solution: ``` def find(x,b): if x/2//b>0: return x/2/(x/2//b) else: return 10000000000 a,b=map(int,input().split()) if a==b: print("%.9f"%a) elif b>a: print(-1) else: print("%.9f"%min(find(a-b,b),find(a+b,b))) ```
output
1
12,896
22
25,793
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,897
22
25,794
Tags: geometry, math Correct Solution: ``` from math import floor a, b = map(int, input().split()) if a < b: print(-1) else: if floor((a-b)/(2*b)) == 0: print((a+b)/(2*floor((a+b)/(2*b)))) else: print(min((a-b)/(2*floor((a-b)/(2*b))), (a+b)/(2*floor((a+b)/(2*b))))) ```
output
1
12,897
22
25,795
Provide tags and a correct Python 3 solution for this coding contest problem. There is a polyline going through points (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... We know that the polyline passes through the point (a, b). Find minimum positive value x such that it is true or ...
instruction
0
12,898
22
25,796
Tags: geometry, math Correct Solution: ``` def main(a,b): if b > a: return(-1) # ver1 k1 = (a - b) // (2*b) if k1 > 0: x1 = (a - b) / (2 * k1) else: x1 = 10**9 k2 = (a + b) // (2*b) x2 = (a + b) / (2*k2) return min(x1, x2) a,b = list(map(int, input().split())) print(main(a,b)) ```
output
1
12,898
22
25,797
Provide tags and a correct Python 3 solution for this coding contest problem. You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. Input The first line contains two integers n, m (1 ≀ n, m ...
instruction
0
12,910
22
25,820
Tags: binary search, data structures, sortings, two pointers Correct Solution: ``` ## necessary imports import sys import random from math import log2, log, ceil input = sys.stdin.readline # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp ## gcd function def gcd(a,...
output
1
12,910
22
25,821
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. Input The f...
instruction
0
12,915
22
25,830
Yes
output
1
12,915
22
25,831
Provide tags and a correct Python 3 solution for this coding contest problem. Imp is watching a documentary about cave painting. <image> Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i fr...
instruction
0
13,059
22
26,118
Tags: brute force, number theory Correct Solution: ``` def gcd(a, b): while b != 0: a, b = b, a % b return a n, k = map(int, input().split()) cur = 1 if k >= 1e6: print("NO") exit() for i in range(1, k+ 1): cur = cur // gcd(cur, i) * i if cur > n + 1: print("No") exit() i...
output
1
13,059
22
26,119
Provide tags and a correct Python 3 solution for this coding contest problem. Imp is watching a documentary about cave painting. <image> Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i fr...
instruction
0
13,060
22
26,120
Tags: brute force, number theory Correct Solution: ``` n, k = [int(x) for x in input().split()] ost = set() i = 1 f = True while i <= k: if n % i not in ost: ost.add(n % i) i += 1 else: f = False break if f: print("Yes") else: print("No") ```
output
1
13,060
22
26,121
Provide tags and a correct Python 3 solution for this coding contest problem. Imp is watching a documentary about cave painting. <image> Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i fr...
instruction
0
13,061
22
26,122
Tags: brute force, number theory Correct Solution: ``` # IAWT n, k = list(map(int, input().split())) ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43] def LCM(): lcm = 1 for p in ps: max_p = 0 while p ** max_p <= k: max_p += 1 max_p -= 1 lcm *= p ** max_p if lcm ...
output
1
13,061
22
26,123