message
stringlengths
2
59.7k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
37
108k
cluster
float64
20
20
__index_level_0__
int64
74
217k
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an equation: Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order. Input The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤...
instruction
0
85,997
20
171,994
Tags: math Correct Solution: ``` a,b,c = [int(x) for x in input().split()] if a == 0 and b == 0 and c == 0: print(-1) elif a == 0: if b == 0: print(0) else: print(1) print(-c/b) else: disc = b**2 - 4*a*c denom = 2*a if disc == 0: print(1) print(-b/denom) ...
output
1
85,997
20
171,995
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,054
20
172,108
Tags: implementation Correct Solution: ``` n = int(input()) for i in range(1,n): print(*((i*j//n)*10+(i*j%n) for j in range(1,n))) ```
output
1
86,054
20
172,109
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,055
20
172,110
Tags: implementation Correct Solution: ``` def turn(i, j, k): p = i * j ans = "" while p > 0: t = p % k ans += str(t) p //= k return ans[::-1] k = int(input()) for i in range(1, k): t = [] for j in range(1, k): t.append(turn(i, j, k)) print(*t, sep=" ") ```
output
1
86,055
20
172,111
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,056
20
172,112
Tags: implementation Correct Solution: ``` def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"): return ((num == 0) and numerals[0]) or (baseN(num // b, b, numerals).lstrip(numerals[0]) + numerals[num % b]) n=int(input()) for i in range(1,n): for j in range(1,n): print(baseN(i*j,n),end=" ") print() ...
output
1
86,056
20
172,113
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,057
20
172,114
Tags: implementation Correct Solution: ``` from sys import stdout from sys import stdin def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end = "\n"): stdout.write(str(a) + end) def putf(a, sep = " ", end = "\n"): stdout.write(sep.join(map(str, a)) ...
output
1
86,057
20
172,115
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,058
20
172,116
Tags: implementation Correct Solution: ``` k=int(input()) a=[[1]+[' '*(len(str(k**2))-1-len(str(i)))+str(i) for i in range(2,k)]]+[[i+1]+[0 for j in range(k-2)] for i in range(1,k-1)] for i in range(2,k): for j in range(2,k): b=i*j c='' while b>0: c+=str(b%k) b//=k ...
output
1
86,058
20
172,117
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,059
20
172,118
Tags: implementation Correct Solution: ``` k=int(input()) for i in range(1,k): z,a=i,[] for j in range(k-1): p,s=z,"" while p: s=str(p%k)+s p//=k z+=i a.append(s) print(*a) ```
output
1
86,059
20
172,119
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,060
20
172,120
Tags: implementation Correct Solution: ``` n = int(input()) f = lambda x: x if x < n else f(x // n) * 10 + x % n for i in range(1, n): print(*[f(i * j) for j in range(1, n)]) ```
output
1
86,060
20
172,121
Provide tags and a correct Python 3 solution for this coding contest problem. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to le...
instruction
0
86,061
20
172,122
Tags: implementation Correct Solution: ``` def convert_base(number, base): if base < 2: return False remainders = [] while number > 0: remainders.append(str(number % base)) number //= base remainders.reverse() return ''.join(remainders) n = int(input()) for i in range(1,n): ...
output
1
86,061
20
172,123
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,062
20
172,124
Yes
output
1
86,062
20
172,125
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,063
20
172,126
Yes
output
1
86,063
20
172,127
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,064
20
172,128
Yes
output
1
86,064
20
172,129
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,065
20
172,130
Yes
output
1
86,065
20
172,131
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,066
20
172,132
No
output
1
86,066
20
172,133
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,067
20
172,134
No
output
1
86,067
20
172,135
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,068
20
172,136
No
output
1
86,068
20
172,137
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multipli...
instruction
0
86,069
20
172,138
No
output
1
86,069
20
172,139
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,153
20
172,306
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` import sys input=sys.stdin.readline s=input().rstrip() l=list(s.split(" ")) p=1 m=0 for ss in l: if ss=="+": p+=1 if ss=="-": m+=1 n=int(l[-1]) if n*p-m<n or p-m*n>n: print("Impossible") exit() arr_p=[1...
output
1
86,153
20
172,307
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,154
20
172,308
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` def binp(a,b): st=a[0] fin=a[1] b=[-b[1],-b[0]] while True: s=(st+fin)//2 if s>=b[0]: if s<=b[1]: return(s) else: fin=s-1 else: ...
output
1
86,154
20
172,309
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,155
20
172,310
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` s = ('+ ' + input()).strip().split() plus = 0 minus = 0 for c in s: if c == '+': plus += 1 elif c == '-': minus += 1 n = int(s[-1]) maxn = plus * n - minus minn = plus - minus * n if not (maxn >= n >= minn):...
output
1
86,155
20
172,311
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,156
20
172,312
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` data = input() data = data.split() data.reverse() n = int(data[0]) data.reverse() pos = 1 neg = 0 for x in data: if x == '-': neg += 1 if x == '+': pos += 1 ans = pos - neg if ans <= n: tmp = n - ans ...
output
1
86,156
20
172,313
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,157
20
172,314
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` def max(a, b): if(a>=b): return a else: return b #################################### s=input().split() length=len(s) n=int(s[length-1]) plus=1 minus=0 for i in s: if(i== '+'): plus+=1 if(i== '-'): minus+=1 if(plus*...
output
1
86,157
20
172,315
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,158
20
172,316
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` s=input() a=s.split() n=int(a[-1]) pos=1 neg=0 for item in a: if item=='+': pos+=1 if item=='-': neg+=1 if n<pos-neg*n or n>pos*n-neg: print("Impossible") else: print("Possible") parr=[] narr=[]...
output
1
86,158
20
172,317
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,159
20
172,318
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` a = list(input().split()) n = int(a[-1]) R = int(a[-1]) one, two = 0, 0 for i in range(1,len(a),2): if a[i] == '=': break if a[i] == '+': R -= 1 one += 1 else: R += 1 two += 1 R -= 1...
output
1
86,159
20
172,319
Provide tags and a correct Python 3 solution for this coding contest problem. You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 t...
instruction
0
86,160
20
172,320
Tags: constructive algorithms, expression parsing, greedy, math Correct Solution: ``` from sys import stdin s=stdin.readline().strip().split() def smas(x,mas): for i in range(len(s)): if s[i]==1 and (i==0 or s[i-1]=="+"): if x>0: y=min(n-1,x) s[i]+=y ...
output
1
86,160
20
172,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza...
instruction
0
86,485
20
172,970
No
output
1
86,485
20
172,971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza...
instruction
0
86,486
20
172,972
No
output
1
86,486
20
172,973
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza...
instruction
0
86,487
20
172,974
No
output
1
86,487
20
172,975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. problem If you write a positive integer in decimal notation (without leading 0) and look at the digit numbers in order, when the number increases and decreases alternately, the number is "zigza...
instruction
0
86,488
20
172,976
No
output
1
86,488
20
172,977
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,509
20
173,018
"Correct Solution: ``` def solve(n): ans = 0 mp = {} while (n >= 10): s = str(n) next = -1 for i in range(1, len(s)): next = max(next, int(s[0:i])*int(s[i:])) if next in mp: ans = -1 break mp[next] = True n = next an...
output
1
86,509
20
173,019
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,510
20
173,020
"Correct Solution: ``` from math import log10 for i in range(int(input())): n = int(input()) j = 0 while n >= 10: n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1)) j += 1 print(j) ```
output
1
86,510
20
173,021
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,511
20
173,022
"Correct Solution: ``` #!/usr/bin/env python3 q = int(input()) for _ in range(q): n = input() for k in range(len(n)**2): if len(n) == 1: print(k) break n = str(max(int(n[:i]) * int(n[i:]) for i in range(1, len(n)))) ```
output
1
86,511
20
173,023
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,512
20
173,024
"Correct Solution: ``` # your code goes here #times volume24 2424 Q=int(input()) for i in range(Q): N=str(input()) c=0 while len(N)>1 and c<15: M=0 for j in range(1,len(N)): # print(N[:j]) l=int(N[:j]) r=int(N[j:]) l*=r if M<l: ...
output
1
86,512
20
173,025
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,513
20
173,026
"Correct Solution: ``` "かけざん" "最大のものを取得して、一桁になるまでに操作を行う回数を答える" def kakezan(n): ret = 0 str_n = str(n) digit_amount = len(str_n) for i in range(digit_amount-1): # print(str_n[:i+1]) # print(str_n[i+1:]) # print("") ret = max(ret, int(str_n[:i+1])*int(str_n[i+1:])) r...
output
1
86,513
20
173,027
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,514
20
173,028
"Correct Solution: ``` def calc(n): if n>=10 and n<100: return (n//10)*(n%10) elif n>=100 and n<1000: r1=(n//10)*(n%10) r2=(n//100)*(n%100) return max(r1,r2) elif n>=1000 and n<10000: r1=(n//10)*(n%10) r2=(n//100)*(n%100) r3=(n//1000)*(n%1000) ...
output
1
86,514
20
173,029
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,515
20
173,030
"Correct Solution: ``` #!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().spl...
output
1
86,515
20
173,031
Provide a correct Python 3 solution for this coding contest problem. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow)...
instruction
0
86,516
20
173,032
"Correct Solution: ``` from functools import reduce g=lambda x,y:x*y cv=lambda s:str(max([reduce(g,list(map(int,[s[:i],s[i:]]))) for i in range(1,len(s))])) for _ in range(int(input())): c=0 n=input() s=set() while 1: if len(n)==1:break if n in s: c=-1 break s.add(n) n=cv(n) c+=1 print(c) ```
output
1
86,516
20
173,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,517
20
173,034
Yes
output
1
86,517
20
173,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,518
20
173,036
Yes
output
1
86,518
20
173,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,519
20
173,038
Yes
output
1
86,519
20
173,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,520
20
173,040
Yes
output
1
86,520
20
173,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,521
20
173,042
No
output
1
86,521
20
173,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,522
20
173,044
No
output
1
86,522
20
173,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,523
20
173,046
No
output
1
86,523
20
173,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following fo...
instruction
0
86,524
20
173,048
No
output
1
86,524
20
173,049
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binar...
instruction
0
87,653
20
175,306
Tags: bitmasks, brute force, math Correct Solution: ``` n,p=map(int,input().split()) #print("{0:b}".format(n).count('1')) t=0 while (("{0:b}".format(n).count('1'))>t or n<t) and n>=0: t+=1 n-=p if n<0: print(-1) else: print(t) ```
output
1
87,653
20
175,307
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binar...
instruction
0
87,654
20
175,308
Tags: bitmasks, brute force, math Correct Solution: ``` n, p = map(int, input().split()) n -= p f = False for i in range(100): s = bin(n) #print(n, s, i + 1) if len(s) - 2 >= i + 1 >= s.count('1') > 0 and n > 0: k = i + 1 f = True break else: n -= p if f: print(k) els...
output
1
87,654
20
175,309
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binar...
instruction
0
87,655
20
175,310
Tags: bitmasks, brute force, math Correct Solution: ``` n, p = map(int, input().split()) i = 0 while True: if n - p * i < 0: print(-1) break if bin(n - p * i).count('1') <= i and i <= n - p * i: print(i) break i += 1 ```
output
1
87,655
20
175,311
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binar...
instruction
0
87,656
20
175,312
Tags: bitmasks, brute force, math Correct Solution: ``` n, p = map(int, input().split()) power = [] power.append(1) for i in range(1,31): power.append(power[len(power)-1]*2) ans = -1 i = 1 while i < 31: y = n - i*p if y <= 0 or y < i: break a = [] while y: a.append(y%2) y = y//2 count = 0 for x in a...
output
1
87,656
20
175,313
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer p (which may be positive, negative, or zero). To combine their tastes, they invented p-binar...
instruction
0
87,657
20
175,314
Tags: bitmasks, brute force, math Correct Solution: ``` from math import log def col(n): rez = 0 while n > 0: rez += n%2 n //= 2 return rez def f(n, p): for i in range(1, int(log(n, 2) + 20)): if col(n-p*i) == i: return i if col(n-p*i) < i and n-p*i >= i: ...
output
1
87,657
20
175,315