message
stringlengths
2
57.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
61
108k
cluster
float64
22
22
__index_level_0__
int64
122
217k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Suppose you have a sequence of k integers A = [a_1, a_2, ... , a_k] where each a_i β‰₯ 2. A sequence of prime integers P = [p_1, p_2, ..., p_k] is called suitable for the sequence A if a_1 is divisible by p_1, a_2 is divisible by p_2 and so on. A sequence of prime integers P is called friendly if there are no unique integers in this sequence. A sequence A is called ideal, if each sequence P that is suitable for A is friendly as well (i. e. there is no sequence P that is suitable for A, but not friendly). For example, the sequence [2, 4, 16] is ideal, while the sequence [2, 4, 6] is not ideal (there exists a sequence P = [2, 2, 3] which is suitable for A, but not friendly). You are given n different integers x_1, x_2, ..., x_n. You have to choose exactly k of them in such a way that they form an ideal sequence, or report that it is impossible. Note that no integer can be chosen more than once. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 1000). The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (2 ≀ x_i ≀ 10^{18}). Output If it is impossible to choose exactly k integers from x_1, x_2, ..., x_n in such a way that the chosen integers form an ideal sequence, print 0. Otherwise, print k pairwise distinct integers β€” the elements of the chosen ideal sequence. If there are multiple answers, print any of them. Examples Input 3 3 2 4 6 Output 0 Input 3 3 2 4 16 Output 2 4 16 Input 4 3 2 4 6 16 Output 2 4 16 Submitted Solution: ``` from collections import defaultdict from math import sqrt, floor, ceil inf = float("inf") b = 10**6 sieve = [True] * (b + 1) smallPrimes = set() for i in range(2, b + 1): #print (i) #print (i) if sieve[i]: smallPrimes.add(i) else: continue j = 2 * i while j < b + 1: sieve[j] = False j += i smallPrimesPowered = dict() for smallPrime in smallPrimes: cur = smallPrime*smallPrime*smallPrime smallPrimesPowered[cur] = smallPrime while cur <= 10**18: cur *= smallPrime smallPrimesPowered[cur] = smallPrime splitted = [int(amit) for amit in input().split(" ")] n = splitted[0] k = splitted[1] arr = [int(amit) for amit in input().split(" ")] freq = defaultdict(lambda: set()) def isPrime(n): if int(n) != n: return False divided = False for i in range(2, ceil(sqrt(n)) + 1): if n % i == 0: divided = True break return (not divided) for item in arr: if item in smallPrimes: freq[item].add(item) elif sqrt(item) in smallPrimes or isPrime(sqrt(item)): freq[int(sqrt(item))].add(item) elif item in smallPrimesPowered: freq[smallPrimesPowered[item]].add(item) importantPrimes = defaultdict(lambda: set()) sumOfGroups = 0 non2 = False for item in freq: if len(freq[item]) >= 2: importantPrimes[item] = freq[item] sumOfGroups += len(importantPrimes[item]) if len(freq[item]) != 2: non2 = True #print (importantPrimes) if k <= sumOfGroups: if non2 == False: if k % 2 == 1: #print ("hi") minNumImportantPrimeFactors = inf minNumImportantPrimeFactorsVal = None minNumImportantPrimeFactorsSet = set() for item in arr: numImportantPrimeFactors = 0 numImportantPrimeFactorsSet = set() cur = item for pf in importantPrimes: divided = False while cur % pf == 0: divided = True cur /= pf if divided: numImportantPrimeFactorsSet.add(pf) numImportantPrimeFactors += 1 if cur != 1: continue if 2 <= numImportantPrimeFactors < minNumImportantPrimeFactors: minNumImportantPrimeFactors = numImportantPrimeFactors minNumImportantPrimeFactorsVal = item minNumImportantPrimeFactorsSet = numImportantPrimeFactorsSet if minNumImportantPrimeFactorsVal is None: print (0) else: #print(freq) ans = set() #print (minNumImportantPrimeFactorsVal) #print (minNumImportantPrimeFactorsSet) if minNumImportantPrimeFactors <= (k-1)//2: for pf in minNumImportantPrimeFactorsSet: for val in importantPrimes[pf]: ans.add(val) ans.add(minNumImportantPrimeFactorsVal) for pf in importantPrimes: if pf in minNumImportantPrimeFactorsSet or len(ans) >= k: continue for val in importantPrimes[pf]: ans.add(val) if len(ans) == k: res = "" for item in ans: res += str(item) + " " print (res) else: #print ("nooo") print ("0") else: ans = set() for pf in importantPrimes: if len(ans) >= k: continue for val in importantPrimes[pf]: ans.add(val) res = "" for item in ans: res += str(item) + " " print (res) else: biggestGroupVal = None biggestGroupSize = -inf for pf in importantPrimes: if len(importantPrimes[pf]) > biggestGroupSize: biggestGroupSize = len(importantPrimes[pf]) biggestGroupVal = pf ans = set() canDiscard = set() for pf in importantPrimes: if pf == biggestGroupVal: continue if len(ans) >= k - biggestGroupSize: break added = 0 for val in importantPrimes[pf]: ans.add(val) added += 1 if added > 2: canDiscard.add(val) addedFromBiggest = 0 for val in importantPrimes[biggestGroupVal]: ans.add(val) addedFromBiggest += 1 if addedFromBiggest > 2: canDiscard.add(val) if addedFromBiggest >= 2 and len(ans) >= k: break while len(ans) > k and len(canDiscard) > 0: discarded = canDiscard.pop() ans.discard(discarded) if len(ans) == 1 or len(ans) != k: print (0) else: res = "" for item in ans: res += str(item) + " " print (res) else: ans = set() for pf in importantPrimes: for val in importantPrimes[pf]: ans.add(val) for item in arr: if len(ans) >= k: break cur = item for pf in importantPrimes: divided = False while cur % pf == 0: divided = True cur /= pf if cur == 1: # entirely divisible by important primes ans.add(item) if len(ans) == k: res = "" for item in ans: res += str(item) + " " print (res) else: print (0) ```
instruction
0
50,718
22
101,436
No
output
1
50,718
22
101,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Suppose you have a sequence of k integers A = [a_1, a_2, ... , a_k] where each a_i β‰₯ 2. A sequence of prime integers P = [p_1, p_2, ..., p_k] is called suitable for the sequence A if a_1 is divisible by p_1, a_2 is divisible by p_2 and so on. A sequence of prime integers P is called friendly if there are no unique integers in this sequence. A sequence A is called ideal, if each sequence P that is suitable for A is friendly as well (i. e. there is no sequence P that is suitable for A, but not friendly). For example, the sequence [2, 4, 16] is ideal, while the sequence [2, 4, 6] is not ideal (there exists a sequence P = [2, 2, 3] which is suitable for A, but not friendly). You are given n different integers x_1, x_2, ..., x_n. You have to choose exactly k of them in such a way that they form an ideal sequence, or report that it is impossible. Note that no integer can be chosen more than once. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 1000). The second line contains n pairwise distinct integers x_1, x_2, ..., x_n (2 ≀ x_i ≀ 10^{18}). Output If it is impossible to choose exactly k integers from x_1, x_2, ..., x_n in such a way that the chosen integers form an ideal sequence, print 0. Otherwise, print k pairwise distinct integers β€” the elements of the chosen ideal sequence. If there are multiple answers, print any of them. Examples Input 3 3 2 4 6 Output 0 Input 3 3 2 4 16 Output 2 4 16 Input 4 3 2 4 6 16 Output 2 4 16 Submitted Solution: ``` from collections import defaultdict from math import sqrt inf = float("inf") b = 10**6 sieve = [True] * (b + 1) smallPrimes = set() for i in range(2, b + 1): #print (i) #print (i) if sieve[i]: smallPrimes.add(i) else: continue j = 2 * i while j < b + 1: sieve[j] = False j += i smallPrimesPowered = dict() for smallPrime in smallPrimes: cur = smallPrime*smallPrime*smallPrime smallPrimesPowered[cur] = smallPrime while cur <= 10**18: cur *= smallPrime smallPrimesPowered[cur] = smallPrime splitted = [int(amit) for amit in input().split(" ")] n = splitted[0] k = splitted[1] arr = [int(amit) for amit in input().split(" ")] freq = defaultdict(lambda: set()) for item in arr: if item in smallPrimes: freq[item].add(item) elif sqrt(item) in smallPrimes: freq[sqrt(item)].add(item) elif item in smallPrimesPowered: freq[smallPrimesPowered[item]].add(item) importantPrimes = defaultdict(lambda: set()) sumOfGroups = 0 non2 = False for item in freq: if len(freq[item]) >= 2: importantPrimes[item] = freq[item] sumOfGroups += len(importantPrimes[item]) if freq[item] != 2: non2 = True print (importantPrimes) if k <= sumOfGroups: if non2 == False: if k % 2 == 1: minNumImportantPrimeFactors = inf minNumImportantPrimeFactorsVal = None minNumImportantPrimeFactorsSet = set() for item in arr: numImportantPrimeFactors = 0 numImportantPrimeFactorsSet = set() cur = item for pf in importantPrimes: divided = False while cur % pf == 0: divided = True cur /= pf if divided: numImportantPrimeFactorsSet.add(pf) numImportantPrimeFactors += 1 if 2 <= numImportantPrimeFactors < minNumImportantPrimeFactors: minNumImportantPrimeFactors = numImportantPrimeFactors minNumImportantPrimeFactorsVal = item minNumImportantPrimeFactorsSet = numImportantPrimeFactorsSet if minNumImportantPrimeFactorsVal is None: print (0) else: ans = set() if minNumImportantPrimeFactors <= (k-1)//2: for pf in minNumImportantPrimeFactorsSet: for val in importantPrimes[pf]: ans.add(val) for pf in importantPrimes: if pf in minNumImportantPrimeFactorsSet or len(ans) >= k: continue for val in importantPrimes[pf]: ans.add(val) if len(ans) == k: res = "" for item in ans: res += str(item) + " " print (res) else: print ("nooo") print ("0") else: ans = set() for pf in importantPrimes: if len(ans) >= k: continue for val in importantPrimes[pf]: ans.add(val) res = "" for item in ans: res += str(item) + " " print (res) else: biggestGroupVal = None biggestGroupSize = -inf for pf in importantPrimes: if len(importantPrimes[pf]) > biggestGroupSize: biggestGroupSize = importantPrimes[pf] biggestGroupVal = pf ans = set() for pf in importantPrimes: if pf == biggestGroupVal: continue for val in importantPrimes[pf]: ans.add(val) for val in importantPrimes[biggestGroupVal]: if len(ans) == k: break ans.add(val) if len(ans) == 1: print (0) else: res = "" for item in ans: res += str(item) + " " print (res) else: ans = set() for pf in importantPrimes: for val in importantPrimes[pf]: ans.add(val) for item in arr: if len(ans) >= k: break cur = item for pf in importantPrimes: divided = False while cur % pf == 0: divided = True cur /= pf if cur == 1: # entirely divisible by important primes ans.add(item) if len(ans) == k: res = "" for item in ans: res += str(item) + " " print (res) else: print (0) ```
instruction
0
50,719
22
101,438
No
output
1
50,719
22
101,439
Provide tags and a correct Python 3 solution for this coding contest problem. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≀ l ≀ r ≀ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal β€” as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≀ n, m ≀ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
instruction
0
50,769
22
101,538
Tags: constructive algorithms, math Correct Solution: ``` n,m=map(int,input().split());MOD=1000000009;o=1;m=pow(2,m,MOD)-1 for i in range(n):o=o*(m-i)%MOD print(o) # Made By Mostafa_Khaled ```
output
1
50,769
22
101,539
Provide tags and a correct Python 3 solution for this coding contest problem. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≀ l ≀ r ≀ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal β€” as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≀ n, m ≀ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
instruction
0
50,770
22
101,540
Tags: constructive algorithms, math Correct Solution: ``` n, m = map(int, input().split()) k = pow(2, m, 1000000009) - 1 ans = 1 for i in range(n): ans = (ans * (k - i)) % 1000000009 print(ans) ```
output
1
50,770
22
101,541
Provide tags and a correct Python 3 solution for this coding contest problem. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≀ l ≀ r ≀ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal β€” as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≀ n, m ≀ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
instruction
0
50,771
22
101,542
Tags: constructive algorithms, math Correct Solution: ``` n, m = map(int, input().split()) MOD = 10 ** 9 + 9 ans = pow(2, m, MOD) - 1 step = pow(2, m, MOD) - 2 for i in range(n - 1): ans = (ans * step) % MOD step -= 1 while ans < 0: ans += MOD while ans >= MOD: ans -= MOD print(ans) ```
output
1
50,771
22
101,543
Provide tags and a correct Python 3 solution for this coding contest problem. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≀ l ≀ r ≀ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal β€” as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≀ n, m ≀ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
instruction
0
50,772
22
101,544
Tags: constructive algorithms, math Correct Solution: ``` n,m=map(int,input().split());MOD=1000000009;o=1;m=pow(2,m,MOD)-1 for i in range(n):o=o*(m-i)%MOD print(o) ```
output
1
50,772
22
101,545
Provide tags and a correct Python 3 solution for this coding contest problem. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≀ l ≀ r ≀ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal β€” as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≀ n, m ≀ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
instruction
0
50,773
22
101,546
Tags: constructive algorithms, math Correct Solution: ``` n, m = map(int, input().split()) mod = 10 ** 9 + 9 s, ans = pow(2, m, mod) - 1, 1 for i in range(n): ans = ans * (s - i) % mod; print (ans) ```
output
1
50,773
22
101,547
Provide tags and a correct Python 3 solution for this coding contest problem. A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≀ l ≀ r ≀ n) such that <image>. In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0. The expression <image> means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal β€” as "xor". In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9). Input The only line of input contains two space-separated integers n and m (1 ≀ n, m ≀ 105). Output Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output. Examples Input 3 2 Output 6 Note Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).
instruction
0
50,774
22
101,548
Tags: constructive algorithms, math Correct Solution: ``` MOD = int(1e9+9) def fast_power(b, e): res = 1 while e: if e % 2 == 1: res = res * b % MOD b = b * b % MOD e >>= 1 return res n, m = map(int, input().split()) a = fast_power(2, m) - 1 a = (a + MOD) % MOD b = a - 1 b = (b + MOD) % MOD for i in range(1, n): a = a * b % MOD b = (b - 1 + MOD) % MOD print(a) ```
output
1
50,774
22
101,549
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,000
22
102,000
Tags: dp, greedy, math, number theory Correct Solution: ``` n = int(input()) i = 0 while i < n: a = int(input()) if (a - 9)%4 == 0 and a >= 9: print(1 + (a-9)//4) elif (a - 6)%4 == 0 and a >= 6: print(1 + (a-6)//4) elif (a - 15)%4 == 0 and a >= 15: print(2 + (a-15)//4) elif a%4 == 0: print(a//4) else: print(-1) i += 1 ```
output
1
51,000
22
102,001
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,001
22
102,002
Tags: dp, greedy, math, number theory Correct Solution: ``` t = int(input()) for i in range(t): n = int(input()) if n%4 == 3: if n >= 15: print((n-15)//4+2) else: print(-1) elif n%4 == 1: if n >= 9: print((n-9)//4+1) else: print(-1) elif n%4 == 0: print(n//4) elif n%4 == 2: if n < 6: print(-1) else: print(n//4) ```
output
1
51,001
22
102,003
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,002
22
102,004
Tags: dp, greedy, math, number theory Correct Solution: ``` for _ in range(int(input())): ni = int(input()) if ni % 2 == 0: print(-1) if ni == 2 else print(ni // 4) else: print(-1) if (ni < 9 or ni == 11) else print((ni - 9) // 4 + 1) ```
output
1
51,002
22
102,005
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,003
22
102,006
Tags: dp, greedy, math, number theory Correct Solution: ``` def check(n): c = 0 if (n == 1)or(n == 2)or(n == 3)or(n == 5)or(n == 7)or(n == 11): c = -1 n = 0 elif (n < 11)and(n != 10)and(n != 8)and(n != 9): c += 1 elif n == 9: c += 1 n -= 9 else: if (n > 11)or(n == 10)or(n == 8): c += n // 4 - 1 n %= 4 n += 4 if check(n) > 0: c += 1 return c; n = int(input()) for i in range(n): k = int(input()) k = check(k) if k == 0: print(-1) else: print(k) ```
output
1
51,003
22
102,007
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,004
22
102,008
Tags: dp, greedy, math, number theory Correct Solution: ``` for _ in range(int(input())): n=int(input()) if n==1 or n==2 or n==3 or n==5 or n==7 or n==11: print(-1) else: if n%2==0: print(n//4) else: print(n//4-1) ```
output
1
51,004
22
102,009
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,005
22
102,010
Tags: dp, greedy, math, number theory Correct Solution: ``` def ans(n): if(n%4 == 0): return n//4 elif(n%4 == 1 and n>=9): return (n-9)//4 + 1 elif(n%4 == 3 and n>=15): return (n-15)//4 + 2 elif(n%4 == 2 and n>=6): return (n-6)//4 + 1 else: return -1 t = int(input()) for _ in range(t): n = int(input()) print(ans(n)) ```
output
1
51,005
22
102,011
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,006
22
102,012
Tags: dp, greedy, math, number theory Correct Solution: ``` from math import * from sys import * from collections import defaultdict import os, sys from io import IOBase, BytesIO M=10**9+7 def pow(a,b): res=1 while b>0: if b&1: res*=a a*=a b>>=1 return res def powmod(a,b,m): res=1 while b>0: if b&1: res=((res*a)%m) a*=a b>>=1 return res def inv(a,m): return powmod(a,m-2,m) def factor(n): potentional_p = 3 itog_list = {} if n % 2 == 0: itog_list[2] = 0 while n % 2 == 0: n = n // 2 itog_list[2] += 1 while n - 1: if potentional_p > (n**0.5): if n in itog_list: itog_list[n] += 1 else: itog_list[n] = 1 return itog_list while n % potentional_p == 0: n = n // potentional_p if potentional_p in itog_list: itog_list[potentional_p] += 1 else: itog_list[potentional_p] = 1 potentional_p += 2 return itog_list def main(): t=int(input()) for _ in range(t): a=int(input()) if a<=3: print(-1) elif a&1: fors=0 if (a-1)%4==0: fors=(a-1)//4 else: fors=(a-1)//4-1 if fors>=2: print((a-1)//4-1) else: print(-1) else: print(a//4) BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s:self.buffer.write(s.encode('ascii')) self.read = lambda:self.buffer.read().decode('ascii') self.readline = lambda:self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') if __name__ == '__main__': main() #threading.Thread(target=main).start() ```
output
1
51,006
22
102,013
Provide tags and a correct Python 3 solution for this coding contest problem. You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings.
instruction
0
51,007
22
102,014
Tags: dp, greedy, math, number theory Correct Solution: ``` n = int(input()) for i in range(n) : a = int(input()) s = 0 if a >= 12 or a == 8 or a == 10: if a % 2 == 1 : a -= 9 s += 1 if a % 4 == 2 : a -= 6 s += 1 s += a // 4 elif a < 4 or a == 5 or a == 7 or a == 11: s =-1 elif a == 4 or a == 6 or a == 9 : s = 1 print(s) ```
output
1
51,007
22
102,015
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` a = int(input()) while a: ans = 0 a -= 1 b = int(input()) if b < 4 or b == 5 or b == 7 or b == 11: ans = -1 else: if b % 2: b -= 9 ans += 1 if b % 4: b -= 6 ans += 1 ans += b // 4 print(ans) ```
instruction
0
51,008
22
102,016
Yes
output
1
51,008
22
102,017
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` import math; from math import log2,sqrt; from bisect import bisect_left,bisect_right import bisect; import sys; from sys import stdin,stdout import os sys.setrecursionlimit(pow(10,6)) import collections from collections import defaultdict from statistics import median # input=stdin.readline # print=stdout.write from queue import Queue inf = float("inf") maxa=pow(10,5) prime=[True for i in range(maxa+1)] def sieve(n=maxa): p=2; while(p*p<=n): if prime[p]: for i in range(p*p,n+1,p): prime[i]=False; p+=1 sieve(maxa) composite=[] least=1000 for i in range(2,least+1): if not prime[i]: composite.append(i) dp=[-inf]*least dp[0]=0 for i in range(len(dp)): for j in range(len(composite)): if composite[j]<=i: dp[i]=max(dp[i],dp[i-composite[j]]+1) else: break; t=int(input()) def fun(n): left=(n-least)%4; n_copy=n; n=least+left-4; dec=n_copy-n; return dec//4,n for i in range(t): n=int(input()) pre_process=0 if n>=least: pre_process,n = fun(n) if dp[n]==-inf: dp[n]=-1 print(dp[n]+pre_process) ```
instruction
0
51,009
22
102,018
Yes
output
1
51,009
22
102,019
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` count = int(input()) results = [] for i in range(count): num = int(input()) if num == 11: n = -1 else: n = num // 4 + { 0: 0, 1: -1, 2: 0, 3: -1 }[num % 4] if n <= 0: n = -1 results.append(n) print('\n'.join([str(i) for i in results])) ```
instruction
0
51,011
22
102,022
Yes
output
1
51,011
22
102,023
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` n = int(input()) for i in range(n) : a = int(input()) s = 0 if a >= 12 or a == 8: if a % 2 == 1 : a -= 9 s += 1 if a % 4 == 2 : a -= 6 s += 1 s += a // 4 elif a < 4 or a == 5 or a == 7 or a in range(9, 12): s =-1 elif a == 4 or a == 6 : s = 1 print(s) ```
instruction
0
51,012
22
102,024
No
output
1
51,012
22
102,025
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` n = 1000 s = [x for x in range(1, n) if x not in [i for sub in [list(range(2 * j, n, j)) for j in range(2, n // 2)] for i in sub]] n = int(input()) flag = False for i in range(n): k = int(input()) if k in s: print(-1) else: for i in range(k,1,-1): if not(k/i in s) and k%i==0: print(i) flag = True break if flag == True: flag == False else: print(-1) ```
instruction
0
51,013
22
102,026
No
output
1
51,013
22
102,027
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` q=int(input()) while q: n=int(input()) if(n==4):print(1) elif(n==6):print(1) elif(n==8):print(2) elif(n==9):print(1) elif(n==10):print(2) elif(n==12):print(3) elif(n==14):print(3) elif(n<14):print(-1) elif(n%2==0): if(n%4==0):print(n//4) else:print((n-6)//4+1) else: n-=9 if(n%4==0):print(n//4+2) else:print((n-6)//4+1+2) q-=1 ```
instruction
0
51,014
22
102,028
No
output
1
51,014
22
102,029
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. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings. An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. Input The first line contains single integer q (1 ≀ q ≀ 105) β€” the number of queries. q lines follow. The (i + 1)-th line contains single integer ni (1 ≀ ni ≀ 109) β€” the i-th query. Output For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. Examples Input 1 12 Output 3 Input 2 6 8 Output 1 2 Input 3 1 2 3 Output -1 -1 -1 Note 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands. 8 = 4 + 4, 6 can't be split into several composite summands. 1, 2, 3 are less than any composite number, so they do not have valid splittings. Submitted Solution: ``` n = int(input()) for i in range(n): z = int(input()) if z in range(1,12): if z in (8,10): ans = 2 elif z in (1,2,3,5,7): ans = -1 else: ans = 1 else: ans = (z // 4) - (z % 2) print(ans) ```
instruction
0
51,015
22
102,030
No
output
1
51,015
22
102,031
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,144
22
102,288
"Correct Solution: ``` n=10**5 p=[0,0]+[1]*~-n for i in range(2,int(n**0.5)+1): if not p[i]:continue for j in range(i*2,n+1,i):p[j]=0 c=[0] for i in range(1,n+1): c.append(c[-1]+(i%2and p[i]and p[-~i//2])) for _ in range(int(input())): l,r=map(int,input().split()) print(c[r]-c[l-1]) ```
output
1
51,144
22
102,289
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,145
22
102,290
"Correct Solution: ``` n=8**6;P=[0,0]+[1]*n;S=[0]*n for i in range(2,n): for j in range(2*i,n,i):P[j]=0 for i in range(1,n):S[i]+=(P[i]==P[(i+1)//2]==1)+S[i-1] for _ in "_"*int(input()):l,r=map(int,input().split());print(S[r]-S[l-1]) ```
output
1
51,145
22
102,291
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,146
22
102,292
"Correct Solution: ``` INF=10**5+1 p=[1]*INF for i in range(2,INF): if p[i]: for j in range(2*i,INF,i):p[j]=0 p[0],p[1]=0,0 q=[0]*INF for i in range(INF): if i%2==0:continue if p[i]*p[(i+1)//2]:q[i]=1 for i in range(1,INF): q[i]+=q[i-1] n=int(input()) for _ in range(n): l,r=map(int,input().split()) print(q[r]-q[l-1]) ```
output
1
51,146
22
102,293
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,147
22
102,294
"Correct Solution: ``` p = [True] * 100010 p[0] = p[1] = False for i in range(2, 100000): if p[i]: for j in range(2 * i, 100000, i): p[j] = False s = [0] * 100010 for i in range(100000): if p[i] and p[(i + 1) // 2]: s[i] = s[i - 1] + 1 else: s[i] = s[i - 1] q = int(input()) for i in range(q): l, r = map(int, input().split()) print(s[r] - s[l - 1]) ```
output
1
51,147
22
102,295
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,148
22
102,296
"Correct Solution: ``` n =10**5+1 p = [False] * 2 + [True] * (n-2) for i in range(2,n): if p[i]: for j in range(i*2,n,i): p[j] = False a=[p[i]==True and p[(i+1)//2]==True for i in range(n)] b=[0]*n b[0]=a[0] for i in range(1,n): b[i]=b[i-1]+a[i] q=int(input()) for i in range(q): l,r=map(int,input().split()) print(b[r]-b[l-1]) ```
output
1
51,148
22
102,297
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,149
22
102,298
"Correct Solution: ``` tf = [True] * 100001 tf[0] = tf[1] = True for i in range(2, 320): if tf[i]: for j in range(i ** 2, 100001, i): tf[j] = False tf2 = [False] * 100001 for i in range(3, 100001): if tf[i] and tf[(i + 1) // 2]: tf2[i] = True count = [] acc = 0 for i in range(100001): acc += tf2[i] count.append(acc) q = int(input()) for _ in range(q): l, r = map(int, input().split()) print(count[r] - count[l - 1]) ```
output
1
51,149
22
102,299
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,150
22
102,300
"Correct Solution: ``` N = 10**5 p = [0]*(N+1) q = [0]*(N+1) p[2] = 1 primes = [2] for i in range(3,N+1): f = 1 for t in primes: if t*t > i: break if i%t == 0: f = 0 break if f == 1: primes.append(i) p[i] = 1 if p[(i+1)//2]: q[i] = 1 m = 0 s = [0]*(N+1) for i in range(1,N+1): m += q[i] s[i] = m for i in range(int(input())): l,r = map(int,input().split()) print(s[r]-s[l-1]) ```
output
1
51,150
22
102,301
Provide a correct Python 3 solution for this coding contest problem. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2
instruction
0
51,151
22
102,302
"Correct Solution: ``` l=[0]*(10**5) for i in range(1,10**5+1): for j in range(2,int(i**0.5)+1): if i%j==0: break else: l[i-1]=1 d=[0]*(10**5) t=3 while t<=10**5: if l[t-1]==1 and l[(t-1)//2]==1: d[t-1]=1 t+=2 r=[0]*(10**5+1) for i in range(10**5): r[i+1]=r[i]+d[i] q=int(input()) for i in range(q): a,b=map(int,input().split()) print(r[b]-r[a-1]) ```
output
1
51,151
22
102,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2 Submitted Solution: ``` import math def isprime(n): if n==1:return(False) if n==2:return(True) for i in range(2,int(math.sqrt(n))+1): if n%i==0:return(False) return(True) s=set([i for i in range(1,10**5,4) if isprime(i) and isprime((i+1)//2)]) s.add(3) l=[i in s for i in range(10**5)] ls=[] tmp=0 for i in l: tmp+=i ls.append(tmp) n=int(input()) for i in range(n): l,r=map(int,input().split()) print(ls[r]-ls[l-1]) ```
instruction
0
51,154
22
102,308
Yes
output
1
51,154
22
102,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2 Submitted Solution: ``` import math is_prime_list = { 1: False } def is_prime(x): global primes if x in is_prime_list: return is_prime_list[x] for divisor in range(2, math.floor(math.sqrt(x))+1): if x % divisor == 0: is_prime_list[x] = False return is_prime_list[x] is_prime_list[x] = True return is_prime_list[x] def main(): global primes Q = int(input()) query_list = [] for i in range(Q): query_list.append([int(_) for _ in input().split()]) for query in query_list: begin = query[0] end = query[1] + 1 like_2017 = 0 for target in range(begin, end, 2): if is_prime(target) and is_prime((target + 1) // 2): like_2017 += 1 print(like_2017) main() ```
instruction
0
51,157
22
102,314
No
output
1
51,157
22
102,315
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2 Submitted Solution: ``` # import bisect # import numpy as np # def seachPrimeNum(N): # max = int(np.sqrt(N)) # seachList = [i for i in range(2, N+1)] # primeNum = [] # while seachList[0] <= max: # primeNum.append(seachList[0]) # tmp = seachList[0] # seachList = [i for i in seachList if i % tmp != 0] # primeNum.extend(seachList) # return primeNum # pn = np.array(seachPrimeNum(100002)) # pn2 = pn*2-1 # n2017 = sorted(list(set(pn) & set(pn2))) n2017=[3, 5, 13, 37, 61, 73, 157, 193, 277, 313, 397, 421, 457, 541, 613, 661, 673, 733, 757, 877, 997, 1093, 1153, 1201, 1213, 1237, 1321, 1381, 1453, 1621, 1657, 1753, 1873, 1933, 1993, 2017, 2137, 2341, 2473, 2557, 2593, 2797, 2857, 2917, 3061, 3217, 3253, 3313, 3517, 3733, 4021, 4057, 4177, 4261, 4273, 4357, 4441, 4561, 4621, 4933, 5077, 5101, 5113, 5233, 5413, 5437, 5581, 5701, 6037, 6073, 6121, 6133, 6217, 6337, 6361, 6373, 6637, 6661, 6781, 6997, 7057, 7213, 7393, 7417, 7477, 7537, 7753, 7933, 8053, 8101, 8221, 8317, 8353, 8461, 8521, 8677, 8713, 8893, 9013, 9133, 9181, 9241, 9277, 9601, 9661, 9721, 9817, 9901, 9973, 10333, 10357, 10453, 10837, 10861, 10957, 11113, 11161, 11317, 11497, 11677, 11701, 12073, 12157, 12241, 12301, 12421, 12433, 12457, 12541, 12553, 12601, 12721, 12757, 12841, 12853, 13093, 13381, 13417, 13681, 13921, 13933, 14437, 14593, 14737, 14821, 15013, 15073, 15121, 15241, 15277, 15361, 15373, 15733, 15901, 16033, 16333, 16381, 16417, 16573, 16633, 16657, 16921, 17041, 17053, 17077, 17257, 17293, 17377, 17881, 18013, 18097, 18133, 18181, 18217, 18253, 18301, 18313, 18397, 18481, 18553, 18637, 18793, 19237, 19441, 19477, 19717, 19801, 19813, 19861, 20353, 20533, 20641, 20857, 21001, 21061, 21193, 21277, 21313, 21577, 21661, 21673, 21817, 22093, 22501, 22573, 22621, 22993, 23053, 23173, 23557, 23677, 23773, 23917, 24097, 24421, 24481, 24781, 24841, 25033, 25153, 25237, 25561, 25657, 25933, 26017, 26293, 26317, 26437, 26497, 26821, 26833, 26881, 26953, 27073, 27253, 27337, 27361, 27457, 27997, 28057, 28297, 28393, 28813, 28837, 28921, 29101, 29473, 29641, 30181, 30241, 30517, 30553, 30577, 30637, 30661, 30697, 30781, 30853, 31081, 31237, 31321, 31333, 31357, 31477, 31573, 31873, 31981, 32173, 32377, 32497, 32533, 32833, 33037, 33301, 33457, 33493, 33757, 33961, 34057, 34213, 34273, 34381, 34513, 34897, 34981, 35317, 35521, 35677, 35977, 36097, 36241, 36433, 36457, 36793, 36877, 36901, 36913, 37273, 37321, 37357, 37573, 37717, 37957, 38281, 38461, 38833, 38953, 38977, 39217, 39373, 39397, 39733, 40093, 40177, 40213, 40693, 40813, 41017, 41221, 41281, 41413, 41617, 41893, 42061, 42337, 42373, 42793, 42961, 43117, 43177, 43201, 43321, 43573, 43597, 43633, 43717, 44053, 44101, 44221, 44257, 44293, 44893, 45061, 45337, 45433, 45481, 45553, 45613, 45841, 46021, 46141, 46261, 46861, 46993, 47017, 47161, 47353, 47521, 47533, 47653, 47713, 47737, 47797, 47857, 48121, 48193, 48337, 48673, 48757, 48781, 49033, 49261, 49393, 49417, 49597, 49681, 49957, 50221, 50341, 50377, 50821, 50893, 51157, 51217, 51241, 51481, 51517, 51637, 52057, 52081, 52237, 52321, 52453, 52501, 52813, 52861, 52957, 53077, 53113, 53281, 53401, 53917, 54121, 54133, 54181, 54217, 54421, 54517, 54541, 54673, 54721, 54973, 55057, 55381, 55501, 55633, 55837, 55921, 55933, 56053, 56101, 56113, 56197, 56401, 56437, 56701, 56773, 56821, 56857, 56893, 57073, 57097, 57193, 57241, 57373, 57457, 57853, 58153, 58417, 58441, 58537, 58573, 58693, 59053, 59197, 59221, 59281, 59341, 59833, 60217, 60337, 60373, 60637, 60733, 60937, 61057, 61153, 61261, 61297, 61561, 61657, 61681, 61717, 61861, 62137, 62473, 62497, 62533, 62653, 62773, 63313, 63397, 63541, 63697, 63781, 63913, 64153, 64237, 64381, 64513, 64717, 65173, 65293, 65413, 65437, 65497, 65557, 65677, 65881, 66301, 66361, 66601, 66697, 66853, 66973, 67057, 67153, 67273, 67477, 67537, 67741, 67777, 67933, 67993, 68113, 68281, 68521, 68737, 69001, 69073, 69457, 69493, 69697, 69877, 70117, 70177, 70297, 70501, 70621, 70921, 70981, 71233, 71341, 71353, 71593, 71821, 72073, 72481, 72613, 72901, 72937, 73141, 73417, 73477, 73561, 73693, 74077, 74317, 74377, 74713, 75013, 75133, 75181, 75721, 75793, 75913, 76333, 76561, 76597, 76753, 77137, 77641, 78157, 78193, 78277, 78877, 78901, 79333, 79357, 79537, 79657, 79693, 79801, 79873, 80077, 80173, 80221, 80473, 80701, 80713, 80917, 81013, 81181, 81517, 81637, 81853, 82021, 82153, 82261, 82561, 82981, 83077, 83221, 83233, 83437, 83617, 83701, 83773, 84121, 84313, 84673, 84697, 84793, 84913, 85297, 85333, 85453, 85717, 85933, 86353, 86413, 87181, 87253, 87337, 87421, 87433, 87517, 87553, 87973, 88117, 88177, 88237, 88261, 88513, 88741, 88897, 88993, 89293, 89833, 89917, 90121, 91081, 91381, 91393, 91513, 91957, 92041, 92557, 92761, 92821, 92893, 92941, 93097, 93133, 93493, 93637, 93913, 94033, 94117, 94273, 94321, 94441, 94573, 94777, 94837, 94993, 95257, 95317, 95401, 95581, 95617, 95713, 95737, 96097, 96157, 96181, 96493, 96517, 96973, 97081, 97177, 97501, 97561, 97777, 97813, 98017, 98737, 98953, 99277, 99577, 99661, 99877] Q = int(input()) for i in range(Q): l, r = map(int, input().split()) print(bisect.bisect_right(n2017, r)-bisect.bisect_left(n2017, l)) ```
instruction
0
51,158
22
102,316
No
output
1
51,158
22
102,317
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≀ x ≀ r_i. Constraints * 1≀Q≀10^5 * 1≀l_i≀r_i≀10^5 * l_i and r_i are odd. * All input values are integers. Input Input is given from Standard Input in the following format: Q l_1 r_1 : l_Q r_Q Output Print Q lines. The i-th line (1≀i≀Q) should contain the response to the i-th query. Examples Input 1 3 7 Output 2 Input 4 13 13 7 11 7 11 2017 2017 Output 1 0 0 1 Input 6 1 53 13 91 37 55 19 51 73 91 13 49 Output 4 4 1 1 1 2 Submitted Solution: ``` #!/usr/bin/env python3 # coding=utf-8 import sys import random import functools @functools.lru_cache(1000000) def is_prime3(q, k=50): if q == 2: return True if q < 2 or q & 1 == 0: return False d = (q - 1) >> 1 while d & 1 == 0: d >>= 1 for i in range(k): a = random.randint(1, q - 1) t = d y = pow(a, t, q) while t != q - 1 and y != 1 and y != q - 1: y = pow(y, 2, q) t <<= 1 if y != q - 1 and t & 1 == 0: return False return True q = int(sys.stdin.readline().strip()) for _ in range(q): l, r = sys.stdin.readline().strip().split(" ") l = int(l) r = int(r) ans = 0 for i in range(l, r + 1, 2): if is_prime3(i) and is_prime3((i + 1) // 2): ans += 1 print(ans) ```
instruction
0
51,159
22
102,318
No
output
1
51,159
22
102,319
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,208
22
102,416
"Correct Solution: ``` MAX = 50001 is_prime = [True for _ in range(MAX)] is_prime[0] = is_prime[1] = False for i in range(2, int(MAX ** (1 / 2)) + 1): if is_prime[i]: for j in range(i ** 2, MAX, i): is_prime[j] = False primes = [i for i in range(MAX) if is_prime[i]] def main(): while True: n = int(input()) if not n: break ans = 0 for i in primes: if i > n // 2: break if is_prime[n - i]: ans += 1 print(ans) main() ```
output
1
51,208
22
102,417
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,209
22
102,418
"Correct Solution: ``` import bisect primes = [0,0] + [1]*49999 for i in range(2, 224): if primes[i]: for j in range(i*i, 50001, i): primes[j] = 0 values = [k for k, b in enumerate(primes) if b] while True: n = int(input()) if n == 0: break end = bisect.bisect_right(values, n//2) print(sum(1 for i in values[:end] if primes[n-i])) ```
output
1
51,209
22
102,419
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,210
22
102,420
"Correct Solution: ``` MAX = 50001 is_prime = [True for _ in range(MAX)] is_prime[0] = is_prime[1] = False for i in range(2, int(MAX ** (1 / 2)) + 1): if is_prime[i]: for j in range(i ** 2, MAX, i): is_prime[j] = False primes = [i for i in range(MAX) if is_prime[i]] while True: n = int(input()) if not n: break ans = 0 for i in primes: if i > n // 2: break if is_prime[n - i]: ans += 1 print(ans) ```
output
1
51,210
22
102,421
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,211
22
102,422
"Correct Solution: ``` # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0056 """ from math import sqrt, ceil, pow import bisect # https://github.com/mccricardo/sieve_of_atkin/blob/master/sieve_of_atkin.py class SieveOfAtkin: def __init__(self, limit): self.limit = limit self.primes = [] self.sieve = [False] * (self.limit + 1) def flip(self, prime): try: self.sieve[prime] = True if self.sieve[prime] == False else False except KeyError: pass def invalidate(self, prime): try: if self.sieve[prime] == True: self.sieve[prime] = False except KeyError: pass def isPrime(self, prime): try: return self.sieve[prime] except KeyError: return False def getPrimes(self): testingLimit = int(ceil(sqrt(self.limit))) for i in range(testingLimit): for j in range(testingLimit): # n = 4*i^2 + j^2 n = 4 * int(pow(i, 2)) + int(pow(j, 2)) if n <= self.limit and (n % 12 == 1 or n % 12 == 5): self.flip(n) # n = 3*i^2 + j^2 n = 3 * int(pow(i, 2)) + int(pow(j, 2)) if n <= self.limit and n % 12 == 7: self.flip(n) # n = 3*i^2 - j^2 n = 3 * int(pow(i, 2)) - int(pow(j, 2)) if n <= self.limit and i > j and n % 12 == 11: self.flip(n) for i in range(5, testingLimit): if self.isPrime(i): k = int(pow(i, 2)) for j in range(k, self.limit, k): self.invalidate(j) self.primes = [2, 3] + [x for x in range(len(self.sieve)) if self.isPrime(x) and x >= 5] return self.primes def solve1(num, primes): # 6.94[s] result = 0 # list_primes = [x for x in primes if x < num] i = bisect.bisect_left(primes, num) list_primes = primes[:i] set_primes = set(list_primes) for x in list_primes: if x > num/2: break if (num-x) in set_primes: # print('solve1: {} + {} = {}'.format(x, num-x, num)) result += 1 return result def solve2(num, primes): result = 0 sub_primes = set(x for x in primes if x < num) while sub_primes: x = sub_primes.pop() if x*2 == num: result += 1 elif (num-x) in sub_primes: result += 1 sub_primes.remove(num-x) return result def solve3(num, primes): # 17.96[s] result = 0 sub_primes = [x for x in primes if x < num] primes_len = len(sub_primes) # print('solve3: primes_len: {}'.format(primes_len)) # print(sub_primes) n = 0 while True: if sub_primes[n] > num/2: break i = bisect.bisect_left(sub_primes, num-sub_primes[n]) if i != primes_len and sub_primes[i] == num-sub_primes[n]: # print('solve3: {} + {} = {}'.format(sub_primes[n], num-sub_primes[n], num)) result += 1 n += 1 return result if __name__ == '__main__': A = SieveOfAtkin(50000) A.getPrimes() while True: num = int(input()) if num == 0: break # ????????Β¨???????????Β¨??? result = solve1(num, A.primes) print(result) ```
output
1
51,211
22
102,423
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,212
22
102,424
"Correct Solution: ``` import bisect primes = [0, 0] + [1] * 49999 for i in range(2, 224): if primes[i]: for j in range(i*i, 50001, i): primes[j] = 0 values = [i for i, k in enumerate(primes) if k] while True: n = int(input()) if n == 0: break I = bisect.bisect(values, n//2) print(sum(1 for v in values[:I] if primes[n-v])) ```
output
1
51,212
22
102,425
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,213
22
102,426
"Correct Solution: ``` def make_tbl(n): tbl = [False, True, False, False, False, True] * (n // 6 + 1) for i in range(1, 4): tbl[i] = not tbl[i] p, stp, sqrt = 5, 2, n ** 0.5 while p < sqrt: for i in range(p ** 2, n, 2 * p): tbl[i] = False while True: p += stp stp = 6 - stp if tbl[p]: break return tbl tbl = make_tbl(50000) ps = [i for i in range(50000) if tbl[i]] while True: n = int(input()) if not n: break res = 0 if n % 2: if tbl[n - 2]: res += 1 else: res = 0 for p in ps: if 2 * p > n: break if tbl[n - p]: res += 1 print(res) ```
output
1
51,213
22
102,427
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,214
22
102,428
"Correct Solution: ``` import bisect primes = [0, 0] + [1] * 49999 for i in range(2, 225): if primes[i]: for j in range(i*i, 50001, i): primes[j] = 0 values = [i for i, k in enumerate(primes) if k] while True: n = int(input()) if n == 0: break I = bisect.bisect(values, n//2) print(sum(primes[n-v] for v in values[:I])) ```
output
1
51,214
22
102,429
Provide a correct Python 3 solution for this coding contest problem. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0
instruction
0
51,215
22
102,430
"Correct Solution: ``` import bisect,sys from itertools import * n=range(50001);a=list(n);a[1]=0 for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i]) p=list(compress(n,a)) for x in sys.stdin: x=int(x) if x:print(sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d])) ```
output
1
51,215
22
102,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` import math num = 50000 L = [True] * (num+1) L[0] = L[1] = False sqrt = int(num**0.5) +1 for i in range(2, sqrt): if L[i] == False: continue for j in range(i*2,num+1,i): L[j] = False p = [x for x in range(num+1) if L[x] ] #pset = set(p) while True: num = int(input()) if num == 0: break half = num // 2 c = 0 for i in p: if i > half: break j = num - i if L[j]: c += 1 print(c) ```
instruction
0
51,216
22
102,432
Yes
output
1
51,216
22
102,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` import bisect primes = [0, 0] + [1] * 49999 for i in range(2, 224): if primes[i]: for j in range(i*i, 50001, i): primes[j] = 0 values = [i for i, k in enumerate(primes) if k] while True: n = int(input()) if n == 0: break I = bisect.bisect(values, n//2) print(len([1 for v in values[:I] if primes[n-v]])) ```
instruction
0
51,217
22
102,434
Yes
output
1
51,217
22
102,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` def primes(n): l = [1 for i in range(n+1)] l[0] = l[1] = 0 for i in range(2,int((n)**(1/2))+1): if l[i] == 1: for j in range(2,n//i+1): l[i*j] = 0 return l l = primes(50000) while True: n = int(input()) if n == 0: break count = 0 if not(n%2): for i in range(3,n//2+1,2): if (l[i] and l[n-i]): count += 1 if n == 4: count = 1 else: if l[n-2]: count += 1 print(count) ```
instruction
0
51,218
22
102,436
Yes
output
1
51,218
22
102,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` import bisect,sys from itertools import * n=range(50001);a=list(n);a[1]=0 for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i]) p=list(compress(n,a)) for x in map(int,sys.stdin): if x:print(sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d])) ```
instruction
0
51,219
22
102,438
Yes
output
1
51,219
22
102,439
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` def primes(n): l = [1 for i in range(n+1)] l[0] = l[1] = 0 for i in range(2,int((n)**(1/2))+1): if l[i] == 1: for j in range(2,n//i+1): l[i*j] = 0 return l while True: n = int(input()) if n == 0: break l = primes(n) count = 0 for i in range(2,n//2+1): if (l[i] and l[n-i]): count += 1 print(count) ```
instruction
0
51,220
22
102,440
No
output
1
51,220
22
102,441
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` from itertools import * n=range(49994);a=list(n) for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i]) p=list(compress(n,a)) for x in iter(input,'0'): x=int(x) if x%2:print(sum(1 for c in p[1:x]if 2+c==x)) elif x-4:print(sum(1 for a,b in combinations_with_replacement(p[1:x],2)if a+b==x)) else:print(1) ```
instruction
0
51,221
22
102,442
No
output
1
51,221
22
102,443
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5. Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even. Input Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000. Output For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line. Example Input 10 11 0 Output 2 0 Submitted Solution: ``` def get_input(): while True: try: yield ''.join(input()) except EOFError: break MAX = 50000 primes = list() for i in range(MAX): primes.append(True) primes[0] = False primes[1] = False for i in range(2, MAX): j = i + i while j < MAX: primes[j] = False j = j + i while True: N = int(input()) if N == 0: break ans = 0 if N % 2 == 0: for i in range(1,N//2 + 1): if primes[i] and primes[N-i]: ans += 1 else: if primes[2] and primes[N-2]: ans += 1 print(ans) ```
instruction
0
51,222
22
102,444
No
output
1
51,222
22
102,445