message
stringlengths
2
57.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
61
108k
cluster
float64
22
22
__index_level_0__
int64
122
217k
Provide a correct Python 3 solution for this coding contest problem. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2
instruction
0
64,765
22
129,530
"Correct Solution: ``` ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973,1000000] from queue import Queue while(True): n = int(input()) ans = 0 if n == 0: quit() lis = Queue() nowsum = 0 for i in ps: while(nowsum > n): x = lis.get() nowsum -= x if nowsum == n: ans += 1 lis.put(i) nowsum += i print(ans) ```
output
1
64,765
22
129,531
Provide a correct Python 3 solution for this coding contest problem. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2
instruction
0
64,766
22
129,532
"Correct Solution: ``` import math primes = [] for p in range(2,10001): for m in range(2,math.floor(math.sqrt(p)) + 1): if p % m == 0: break else: primes.append(p) targ = int(input()) while targ != 0: ans = 0 for p in range(len(primes)): if primes[p] > targ: break tempsum = 0 for l in range(p,len(primes)): tempsum += primes[l] if tempsum > targ: break elif tempsum == targ: ans += 1 break print(ans) targ = int(input()) ```
output
1
64,766
22
129,533
Provide a correct Python 3 solution for this coding contest problem. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2
instruction
0
64,767
22
129,534
"Correct Solution: ``` primes = [0, 0] + [1]*9999 for i in range(2, 101): if primes[i]: for j in range(i*i, 10001, i): primes[j] = 0 while True: n = int(input()) if n == 0: break m = n while not primes[m]: m -= 1 pnum = [i for i in range(m+1) if primes[i]] ans = 0 for i in range(len(pnum)): tmp = 0 for j in range(i, len(pnum)): tmp += pnum[j] if tmp == n: ans += 1 break if tmp > n: break print(ans) ```
output
1
64,767
22
129,535
Provide a correct Python 3 solution for this coding contest problem. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2
instruction
0
64,768
22
129,536
"Correct Solution: ``` # エラトステネスの篩 def Eratosthenes(N): ans = [True for i in range(N + 1)] ans[0], ans[1] = False, False for i in range(int(N ** (1 / 2)) + 1): if ans[i]: for j in range(2 * i, N, i): ans[j] = False return [i for i in range(N + 1) if ans[i]] # 累積和の前準備 def Cumulative_sum(lists): ans = [0] for i in lists: ans.append(ans[-1] + i) return ans ans = [] while True: N = int(input()) if not N: break prime_sum = Cumulative_sum(Eratosthenes(N + 10)) left, right = 0, 1 tmp_ans = 0 while left != right: # 一致していた場合 if prime_sum[right] - prime_sum[left] == N: tmp_ans += 1 right += 1 # 入力より大きい場合 elif prime_sum[right] - prime_sum[left] > N: left += 1 # 入力より小さい場合 else: right += 1 ans.append(tmp_ans) # 出力 [print(i) for i in ans] ```
output
1
64,768
22
129,537
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` import sys sys.setrecursionlimit(10000000) MOD = 10 ** 9 + 7 INF = 10 ** 15 def sieve(n): if n == 1:return [] primes = [1 if i%2 == 1 else 0 for i in range(n + 1)] primes[1] = 0 primes[2] = 1 for i in range(3,n + 1,2): if i * i > n: break if primes[i]: for j in range(i * i,n + 1,i): primes[j] = 0 return [p for p in range(2,n + 1) if primes[p] == 1] primes = sieve(10005) P = len(primes) def solve(N): ans = 0 r = 0 tot = 0 for l in range(P): if primes[l] > N: break while r < P and tot + primes[r] <= N: tot += primes[r] r += 1 if tot == N: ans += 1 tot -= primes[l] print(ans) while True: N = int(input()) if N == 0: exit() solve(N) ```
instruction
0
64,769
22
129,538
Yes
output
1
64,769
22
129,539
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` def solve(): # making a list of prime numbers primes = [2, 3] for n in range(5, 10000, 2): l = n ** 0.5 for p in primes: if n % p == 0: break if l < p: primes.append(n) break primes = [0] + primes from itertools import accumulate ac_primes = list(accumulate(primes)) from bisect import bisect_left, bisect_right from sys import stdin file_input = stdin for line in file_input: n = int(line) if n == 0: break low = bisect_left(ac_primes, n) high = bisect_right(primes, n) ans = 0 for x in ac_primes[low:high]: t = x - n if t == ac_primes[bisect_left(ac_primes, t)]: ans += 1 print(ans) solve() ```
instruction
0
64,770
22
129,540
Yes
output
1
64,770
22
129,541
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` """ Problem A: Sum of Consecutive Prime Numbers https://onlinejudge.u-aizu.ac.jp/problems/1257 input : 2 < n < 10000 """ def prime_list(n): is_prime = [True]*(n+1) is_prime[0] = False is_prime[1] = False for i in range(2, int(n**0.5)+1 ): if not is_prime[i]: continue for j in range(i*2, n+1, i): is_prime[j] = False return [i for i in range(n+1) if is_prime[i]] def subset_sum_problem(prime_list, length): subset_dict = {} for i in range(length): now = 0 for j in range(i, length): now += prime_list[j] if not now in subset_dict: subset_dict[now] = 1 else: subset_dict[now] = subset_dict[now] + 1 return subset_dict if __name__ == '__main__': prime_list = prime_list(10000) length = len(prime_list) subset_dict = subset_sum_problem(prime_list, length) ans = [] while(True): n = int(input()) if n == 0: break if not n in subset_dict: ans.append(0) else: ans.append(subset_dict[n]) print(*ans, sep='\n') ```
instruction
0
64,771
22
129,542
Yes
output
1
64,771
22
129,543
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` p=[] a=[0]*2+[1]*10001 for i in range(2,int(10000**0.5)+1): if a[i]: for j in range(i*i,10001,i): a[j]=0 for i in range(2,10001): if a[i]:p+=[i] b=[0]*5736397 for i in range(len(p)): c=0 for j in range(i,len(p)): c+=p[j] b[c]+=1 while 1: n=int(input()) if n==0:break print(b[n]) ```
instruction
0
64,772
22
129,544
Yes
output
1
64,772
22
129,545
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` import math isPrime = [1 for _ in range (10002)] isPrime[:2] = [0, 0] for i in range(2, 101): for j in range(i*i, 10001, i): isPrime[j] = 0 prime = [] for i in range(10001): if isPrime[i] == 1: prime.append(i) while True: n = int(input()) if n == 0: break cnt = 0 for i in range(n + 1): sum = 0 for j in range(i,n + 1): sum += prime[j] if sum == n: cnt += 1 break if sum > n: break print(cnt) ```
instruction
0
64,773
22
129,546
No
output
1
64,773
22
129,547
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` primes = [0, 0] + [1]*996 for i in range(2, 32): if primes[i]: for j in range(i*i, 998, i): primes[j] = 0 while True: n = int(input()) if n == 0: break m = n while not primes[m]: m -= 1 pnum = [i for i in range(m+1) if primes[i]] ans = 0 for i in range(len(pnum)): tmp = 0 for j in range(i, len(pnum)): tmp += pnum[j] if tmp == n: ans += 1 break if tmp > n: break print(ans) ```
instruction
0
64,774
22
129,548
No
output
1
64,774
22
129,549
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` primes = [0, 0] + [1]*999 for i in range(2, 32): if primes[i]: for j in range(i*i, 1001, i): primes[j] = 0 while True: n = int(input()) if n == 0: break m = n while not primes[m]: m -= 1 pnum = [i for i in range(m+1) if primes[i]] ans = 0 for i in range(len(pnum)): tmp = 0 for j in range(i, len(pnum)): tmp += pnum[j] if tmp == n: ans += 1 break if tmp > n: break print(ans) ```
instruction
0
64,775
22
129,550
No
output
1
64,775
22
129,551
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20. Your mission is to write a program that reports the number of representations for the given positive integer. Input The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero. Output The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output. Example Input 2 3 17 41 20 666 12 53 0 Output 1 1 2 3 0 0 1 2 Submitted Solution: ``` import math isPrime = [1 for _ in range (10002)] isPrime[:2] = [0, 0] for i in range(2, 101): for j in range(i*i, 10001, i): isPrime[j] = 0 prime = [] for i in range(10001): if isPrime[i] == 1: prime.append(i) while True: n = int(input()) if n == 0: break cnt = 0 for i in range(n): sum = 0 for j in range(i,n): sum += prime[j] if sum == n: cnt += 1 break if sum > n: break print(cnt) ```
instruction
0
64,776
22
129,552
No
output
1
64,776
22
129,553
Provide tags and a correct Python 2 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,849
22
129,698
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): for i in arr: stdout.write(str(i)+' ') stdout.write('\n') range = xrange # not for python 3.0+ # main code n=int(raw_input()) l=map(int,raw_input().split()) ans=[] sm=0 for i in range(n/2): if 1: f=0 i1=1 mn=10000000 while i1*i1<l[i]: if l[i]%i1==0: a=i1 b=l[i]/i1 if (b-a)%2==0: temp=(b-a)/2 if temp**2-sm>0: mn=min(mn,temp) f=1 i1+=1 if f: temp=mn else: pr('No') exit() else: temp=l[i]-1 #print i,temp,a,b a=temp x=(a**2)-sm if x<0: pr('No') exit() ans.append(x) ans.append(l[i]) sm+=ans[-1]+ans[-2] pr('Yes\n') pr_arr(ans) ```
output
1
64,849
22
129,699
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,850
22
129,700
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` import math def completar_lista(lista,n): X=[] s=0 cadena = '' for x in lista: parar = True for div1 in range(int(math.sqrt(x)),0,-1): if x%div1 == 0: div2=x//div1 if (div1 + div2)%2==0: s_1 = ((div2-div1)//2)**2 if s_1>s: temp = s_1-s X.append(temp) X.append(x) s = s+temp+x parar = False break if parar: return None return X n = int(input()) lista = map(int,input().split()) lista_entera = completar_lista(lista,n//2) if lista_entera is None: print('No') else: print('Yes') print(*lista_entera) ```
output
1
64,850
22
129,701
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,851
22
129,702
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` import sys import math n=int(input()) A=list(map(int,input().split())) ANS=[None]*(n//2+1) ANS[0]=[0,0] for i in range(n//2): NEXT=[] #x**2=? #y**2=A[i//2] z=A[i] xr=math.ceil(math.sqrt(z)) LIST=[] for j in range(1,xr+1): if z%j==0: LIST.append(j) #print(LIST) for l in LIST[::-1]: if (l+z//l)%2==1: continue y=(l+z//l)//2 x=y-l #print(x,y) _,N=ANS[i] if x**2>N: NEXT=[x**2,y**2] break #print(NEXT) if NEXT==[]: print("No") sys.exit() ANS[i+1]=NEXT #print(ANS) print("Yes") for i in range(1,n//2+1): print(ANS[i][0]-ANS[i-1][1],end=" ") print(ANS[i][1]-ANS[i][0],end=" ") ```
output
1
64,851
22
129,703
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,852
22
129,704
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` n=int(input())//2 s=list(map(int,input().split())) sqs=[0]*(2*n+2) sqs[-1]=sqs[-2]=999999999999999999 for i in range(n-1,-1,-1): N=s[i] d=1 sqi=sqi_1=-1 while d*d<=N: if(N%d==0): f=N//d if (f+d)%2:d+=1;continue if(d==(d+f)//2):d+=1;continue sqi=(d+f)//2 sqi_1=abs(d-sqi) if(sqs[i*2+2]>sqi): break d+=1 if sqi==-1:exit(print('No')) sqs[i*2+1]=sqi sqs[i*2]=sqi_1 if sqs!=sorted(sqs):exit(print('No')) cs=0 print('Yes') for i in sqs[:-2]: print(i*i-cs,end=' ') cs+=i*i-cs #print(*sqs) ```
output
1
64,852
22
129,705
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,853
22
129,706
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` #!/usr/bin/env python """ This file is part of https://github.com/Cheran-Senthil/PyRival. Copyright 2018 Cheran Senthilkumar all rights reserved, Cheran Senthilkumar <hello@cheran.io> Permission to use, modify, and distribute this software is given under the terms of the MIT License. """ from __future__ import division, print_function import cmath import itertools import math import operator as op # import random import sys from atexit import register from bisect import bisect_left, bisect_right # from collections import Counter, MutableSequence, defaultdict, deque # from copy import deepcopy # from decimal import Decimal # from difflib import SequenceMatcher # from fractions import Fraction # from heapq import heappop, heappush if sys.version_info[0] < 3: # from cPickle import dumps from io import BytesIO as stream # from Queue import PriorityQueue, Queue else: from functools import reduce from io import StringIO as stream from math import gcd # from pickle import dumps # from queue import PriorityQueue, Queue if sys.version_info[0] < 3: class dict(dict): """dict() -> new empty dictionary""" def items(self): """D.items() -> a set-like object providing a view on D's items""" return dict.iteritems(self) def keys(self): """D.keys() -> a set-like object providing a view on D's keys""" return dict.iterkeys(self) def values(self): """D.values() -> an object providing a view on D's values""" return dict.itervalues(self) def gcd(x, y): """gcd(x, y) -> int greatest common divisor of x and y """ while y: x, y = y, x % y return x input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip def sync_with_stdio(sync=True): """Set whether the standard Python streams are allowed to buffer their I/O. Args: sync (bool, optional): The new synchronization setting. """ global input, flush if sync: flush = sys.stdout.flush else: sys.stdin = stream(sys.stdin.read()) input = lambda: sys.stdin.readline().rstrip('\r\n') sys.stdout = stream() register(lambda: sys.__stdout__.write(sys.stdout.getvalue())) def memodict(f): """ Memoization decorator for a function taking a single argument. """ class memodict(dict): def __missing__(self, key): ret = self[key] = f(key) return ret return memodict().__getitem__ @memodict def all_factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1, 2 if n % 2 else 1) if n % i == 0))) def main(): n = int(input()) x = list(map(int, input().split(' '))) a, b = 0, 0 f = all_factors(x[0]) for fi in f: if (fi + (x[0] // fi)) % 2 == 0: na = (fi + (x[0] // fi)) // 2 nb = fi - na if fi > na else (x[0] // fi) - na if (a == 0) or (b == 0): a, b = na, nb else: if na < a: a, b = na, nb if (a == 0) or (b == 0): print('No') return res = [b*b, x[0]] pref_sum = sum(res) for i in range(1, n // 2): a, b = 0, 0 pref_sum += x[i] f = all_factors(x[i]) for fi in f: if (fi + (x[i] // fi)) % 2 == 0: na = (fi + (x[i] // fi)) // 2 nb = fi - na if fi > na else (x[i] // fi) - na if na*na > pref_sum: if (a == 0) or (b == 0): a, b = na, nb else: if na < a: a, b = na, nb if (a == 0) or (b == 0): print('No') return res.append(a*a - pref_sum) pref_sum += res[-1] res.append(x[i]) print('Yes') print(*res) if __name__ == '__main__': sync_with_stdio(False) main() ```
output
1
64,853
22
129,707
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,854
22
129,708
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` import math n=int(input()) a=list(map(int,input().split())) r=lambda y:int(math.sqrt(y)) def R(x): y=r(x) return y*y==x z=0 b=[] for i in a: f=0 for q in range(r(z)+1,3160000): y=q*q-z; if R(q*q+i): b+=[y,i];z+=i+y;f=1;break if f<1: print('No');exit(0) print('Yes\n',*b) ```
output
1
64,854
22
129,709
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,855
22
129,710
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` import math def completar_lista(lista,n): X=[] s=0 cadena = '' for x in lista: if x%2==0 and x%4!=0: return None parar = True for div1 in range(int(math.sqrt(x)),0,-1): if x%div1 == 0: div2=x//div1 if (div1 + div2)%2==0: s_1 = ((div2-div1)//2)**2 if s_1>s: temp = s_1-s X.append(temp) X.append(x) s = s+temp+x parar = False break if parar: return None return X n = int(input()) lista = map(int,input().split()) lista_entera = completar_lista(lista,n//2) if lista_entera is None: print('No') else: print('Yes') print(*lista_entera) ```
output
1
64,855
22
129,711
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,856
22
129,712
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` from sys import stdin,stdout from itertools import combinations from collections import defaultdict,OrderedDict import math import heapq def listIn(): return list((map(int,stdin.readline().strip().split()))) def stringListIn(): return([x for x in stdin.readline().split()]) def intIn(): return (int(stdin.readline())) def stringIn(): return (stdin.readline().strip()) def perfectSquare(k): s=math.sqrt(k) if s-int(s)==0: return 1 else: return 0 def check(a,b,op,i): e1,e2=a,b if op=="-": diff=e2-e1 else: diff=e2+e1 if perfectSquare(diff): #print(diff) if diff-arr[i-1]>0 or i==0: arr[i]=diff arr[i+1]=e2 return 1 else: return 0 else: return 0 if __name__=="__main__": n=intIn() even=listIn() arr=[0]*n j=0 for i in range(n): if i%2!=0: arr[i]=even[j] j+=1 k=0 #arr[0]+...arr[i] =k*k current sum l=0 #arr[0]+...arr[i+1] =l*l forward sum s=0 #arr[0]+...arr[i-1] =s previous sum zcnt=0 b_end=10**13 flag=False for i in range(0,n,2): found=False while(not found): k+=1 if (k*k-s>b_end): print('No') exit(0) #given current sum=k^2 #then checking if k*k+arr[i+1]=l^2 forward_sum=k*k+arr[i+1] while(forward_sum>l*l): l+=1 if forward_sum==l*l: found=True arr[i]=k*k-s s=forward_sum k=l #print(arr,s) print('Yes') print(*arr) ```
output
1
64,856
22
129,713
Provide tags and a correct Python 3 solution for this coding contest problem. Chouti is working on a strange math problem. There was a sequence of n positive integers x_1, x_2, …, x_n, where n is even. The sequence was very special, namely for every integer t from 1 to n, x_1+x_2+...+x_t is a square of some integer number (that is, a [perfect square](https://en.wikipedia.org/wiki/Square_number)). Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x_2, x_4, x_6, …, x_n. The task for him is to restore the original sequence. Again, it's your turn to help him. The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any. Input The first line contains an even number n (2 ≤ n ≤ 10^5). The second line contains n/2 positive integers x_2, x_4, …, x_n (1 ≤ x_i ≤ 2 ⋅ 10^5). Output If there are no possible sequence, print "No". Otherwise, print "Yes" and then n positive integers x_1, x_2, …, x_n (1 ≤ x_i ≤ 10^{13}), where x_2, x_4, …, x_n should be same as in input data. If there are multiple answers, print any. Note, that the limit for x_i is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1 ≤ x_i ≤ 10^{13}. Examples Input 6 5 11 44 Output Yes 4 5 16 11 64 44 Input 2 9900 Output Yes 100 9900 Input 6 314 1592 6535 Output No Note In the first example * x_1=4 * x_1+x_2=9 * x_1+x_2+x_3=25 * x_1+x_2+x_3+x_4=36 * x_1+x_2+x_3+x_4+x_5=100 * x_1+x_2+x_3+x_4+x_5+x_6=144 All these numbers are perfect squares. In the second example, x_1=100, x_1+x_2=10000. They are all perfect squares. There're other answers possible. For example, x_1=22500 is another answer. In the third example, it is possible to show, that no such sequence exists.
instruction
0
64,857
22
129,714
Tags: binary search, constructive algorithms, greedy, math, number theory Correct Solution: ``` ''' Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College Date:10/06/2020 ''' from os import path import sys from functools import cmp_to_key as ctk from collections import deque,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right from itertools import permutations from datetime import datetime from math import ceil,sqrt,log,gcd def ii():return int(input()) def si():return input() def mi():return map(int,input().split()) def li():return list(mi()) abc='abcdefghijklmnopqrstuvwxyz' abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def bo(i): return ord(i)-ord('a') def check(x): x1=int(sqrt(x)) return x1*x1==x def solve(): # for _ in range(ii()): n=ii() a=li() tmp=[0]*n tot=0 x=1 for i in range(n//2): tmp[2*i+1]=a[i] while(x<1000000): if x*x>tot and check(x*x+a[i]): tmp[2*i]=x*x-tot break x+=1 if(x==1000000): print('No') exit(0) tot+=tmp[2*i]+a[i] print('Yes') print(*tmp) if __name__ =="__main__": solve() ```
output
1
64,857
22
129,715
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,975
22
129,950
Tags: brute force, math Correct Solution: ``` import string from collections import defaultdict,Counter from math import sqrt, log10, log2, log, gcd, ceil, floor,factorial from bisect import bisect_left, bisect_right from itertools import permutations,combinations_with_replacement import sys,io,os; input=sys.stdin.readline # input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # print=sys.stdout.write sys.setrecursionlimit(10000) mod=int(pow(10,7)+9) inf = float('inf') def get_list(): return [int(i) for i in input().split()] def yn(a): print("YES" if a else "NO") n=20000 l=[] m=[[]] mrev=[[] for i in range(n+1)] for i in range(1,n+1): m.append([]) for j in range(i,n+1,i): m[-1].append(j) mrev[j].append(i) l.append([i,j]) t = 1 t=int(input()) def update(a,b,c,i,j,k): return abs(i-a)+abs(j-b)+abs(k-c) for _ in range(t): a,b,c=get_list() if c%b==0 and b%a==0: print(0) print(a,b,c) continue mina=inf ans=[a,b,c] for iter in l: i=iter[0] j=iter[1] k=((c)//j)*j; if k<j: k=j; version=update(a,b,c,i,j,k) if version<mina: mina=version answer=[i,j,k] k+=j; version = update(a,b,c,i,j,k) if version < mina: mina = version answer = [i, j, k] print(mina) print(*answer) ```
output
1
64,975
22
129,951
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,976
22
129,952
Tags: brute force, math Correct Solution: ``` import math maxx=15000 for _ in range(int(input())): a,b,c=map(int,input().split()) xa=xb=xc=0 ans=math.inf for i in range(1,maxx+1): for j in range(i,maxx+1,i): for k in range(j,maxx+1,j): if(abs(a-i)+abs(b-j)+abs(c-k)<ans): ans=abs(a-i)+abs(b-j)+abs(c-k) xa,xb,xc=i,j,k print(ans) print(xa,xb,xc) ```
output
1
64,976
22
129,953
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,977
22
129,954
Tags: brute force, math Correct Solution: ``` t = int(input()) for _ in range(t): a,b,c = map(int,input().split()) cnt = 10**9 A,B,C = a,b,c for i in range(1,2*a+1): for j in range(i,2*b+1,i): cc = (c//j) * j if c-cc > cc+j-c: cc = cc+j if abs(c-cc) + abs(b-j) + abs(a-i) < cnt and cc >= j: A,B,C = i,j,cc cnt = abs(c-C) + abs(b-B) + abs(a-A) print(cnt) print(A,B,C) ```
output
1
64,977
22
129,955
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,978
22
129,956
Tags: brute force, math Correct Solution: ``` #! /usr/bin/python3 import os import sys from io import BytesIO, IOBase from itertools import accumulate def main(): for _ in range(int(input())): a, b, c = map(int, input().split()) ans = float("inf") for i in range(1, 20000): for j in range(i, 20000, i): for k in range(j, 20000, j): if abs(a - i) + abs(b - j) + abs(c - k) < ans: ans = abs(a - i) + abs(b - j) + abs(c -k) aa = i bb = j cc = k print(ans) print(aa, bb, cc) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
64,978
22
129,957
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,979
22
129,958
Tags: brute force, math Correct Solution: ``` import random, math from copy import deepcopy as dc from bisect import bisect_left, bisect_right # Function to call the actual solution def solution(a, b, c): fin = float('inf') A, B, C = 0, 0, 0 for i in range(1, 11000): for j in range(i, 11000, i): a_f = i + 1 - 1 b_f = j + 1 - 1 prev_c = (c//b_f)*b_f nex_c = ((c//b_f) + 1)*b_f op = 0 if abs(prev_c - c) <= abs(nex_c - c) and prev_c != 0: op += abs(prev_c - c) c_f = prev_c + 1 - 1 else: op += abs(nex_c - c) c_f = nex_c + 1 - 1 op += abs(a_f - a) op += abs(b_f - b) if op < fin: fin = op + 1 - 1 A, B, C = a_f, b_f, c_f return [fin, A, B, C] # Function to take input def input_test(): for _ in range(int(input())): # n = int(input()) # a, b = map(int, input().strip().split(" ")) a, b, c = map(int, input().strip().split(" ")) # li = list(map(int, input().strip().split(" "))) out = solution(a, b, c) print(out[0]) print(*out[1:]) # Function to check test my code def test(): pass input_test() # test() ```
output
1
64,979
22
129,959
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,980
22
129,960
Tags: brute force, math Correct Solution: ``` from math import factorial from collections import Counter from heapq import heapify, heappop, heappush import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------------------ def RL(): return map(int, sys.stdin.readline().rstrip().split()) def N(): return int(input()) def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0 def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0 def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2) mod = 1000000007 INF = float('inf') # ------------------------------ import bisect def main(): for _ in range(N()): a, b, c = RL() res = INF ret = (-1, -1, -1) for i in range(1, 2*a+1): for j in range(i, 2*b+1, i): aa, bb = i, j dif = abs(aa-a)+abs(bb-b) for nx in [bb, c//bb*bb, c//bb*bb+bb]: op = abs(nx-c) td = dif + op if td<res: res = td ret = (aa, bb, nx) print(res) print(*ret) if __name__ == "__main__": main() ```
output
1
64,980
22
129,961
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,981
22
129,962
Tags: brute force, math Correct Solution: ``` import math for _ in range(int(input())): a,b,c=map(int,input().split()) minn=math.inf for i in range(1,2*a+1): for j in range(i,2*b+1,i): for k in range(2): cC=j*(c//j)+k*j ans=abs(i-a)+abs(j-b)+abs(cC-c) if ans<minn: minn=ans A=i B=j C=cC print(minn) print(A,B,C) ```
output
1
64,981
22
129,963
Provide tags and a correct Python 3 solution for this coding contest problem. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48
instruction
0
64,982
22
129,964
Tags: brute force, math Correct Solution: ``` t=int(input()) for _ in range(t): a, b, c=map(int, input().split()) ans=[0,0,0] m=9999999999 for i in range(1, 10500): for j in range(i, 10500, i): for k in range(j, 10500, j): if m>abs(a-i)+abs(b-j)+abs(c-k): m=abs(a-i)+abs(b-j)+abs(c-k) ans=[i, j, k] print(m) print(*ans) ```
output
1
64,982
22
129,965
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` for _ in range(int(input())): a,b,c=map(int,input().split()) x=float("inf") s,d,f=0,0,0 w=[] for i in range(1,11000): for j in range(i,11000,i): for k in range(j,11000,j): t=abs(a-i)+abs(b-j)+abs(c-k) if t<x: x=t s,d,f=i,j,k print(x) print(str(s)+' '+str(d)+" "+str(f)) ```
instruction
0
64,983
22
129,966
Yes
output
1
64,983
22
129,967
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys from typing import List """ created by shhuan at 2020/3/14 13:11 """ def sove(A, B, C): ans = A+B xa, xb, xc = A, B, C for a in range(1, C+1): sa = abs(A-a) if sa >= ans: continue k = ans-sa xl, xr = max(max(B-k, 1) // a, 1), (B+k)//a+1 for dx in range(xl, xr+1): b = dx * a sb = sa + abs(b-B) if sb >= ans: continue k = ans - sb yl, yr = max(max(C-k, 1) // b, 1), (C+k)//b+1 for dy in range(yl, yr+1): c = dy * b sc = sb + abs(c-C) if sc < ans: ans = sc xa, xb, xc = a, b, c return ans, xa, xb, xc T = int(input()) for ti in range(T): A, B, C = map(int, input().split()) step, a, b, c = sove(A, B, C) print(step) print('{} {} {}'.format(a, b, c)) ```
instruction
0
64,984
22
129,968
Yes
output
1
64,984
22
129,969
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` def solve(a, b, c): mx = a + b - 2 best = mx bestv = (1, 1, c) for aa in range(1, 2 * a): for bb in range(aa, 2 * b, aa): cc = bb for ccc in (c // bb * bb, (c + bb - 1) // bb * bb): if abs(cc - c) > abs(ccc - c): cc = ccc cur = abs(a - aa) + abs(b - bb) + abs(c - cc) if cur < best: best = cur bestv = (aa, bb, cc) return best, bestv t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) r, x = solve(a, b, c) print(r) print(*x) ```
instruction
0
64,985
22
129,970
Yes
output
1
64,985
22
129,971
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` import sys input = sys.stdin.readline t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) mincost = 10 ** 20 ans = () for i in range(1, 10001): for j in range(i, 20001, i): cur = abs(i - a) + abs(j - b) k1 = (c // j) * j k2 = k1 + j if k1 >= j: cur1 = cur + abs(k1 - c) if k2 >= j: cur2 = cur + abs(k2 - c) if cur1 < mincost: mincost = cur1 ans = (i, j, k1) if cur2 < mincost: mincost = cur2 ans = (i, j, k2) print(mincost) print(*ans) ```
instruction
0
64,986
22
129,972
Yes
output
1
64,986
22
129,973
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` from collections import Counter def dif(tup1, tup2): return sum(abs(t1 - t2) for t1, t2 in zip(tup1, tup2)) def go(): a, b, c = map(int, input().split()) best_v = c-a best = b,b,b abc_tup = (a, b, c) cb = c // b for i in range(max(1, cb - 2), cb + 2): bba = int(c / i) // a for j in range(1, min(bba *10, c)): # 1,j,i*j df = c % (i * j) cc = c - df cnd_tup = (cc // (i * j), cc // i, cc) cnd_v = dif(abc_tup, cnd_tup) if cnd_v<best_v: best_v=cnd_v best = cnd_tup cc = cc + i*j cnd_tup = (cc // (i * j), cc // i, cc) if cnd_tup[0]==0: break cnd_v = dif(abc_tup, cnd_tup) if cnd_v < best_v: best_v = cnd_v best = cnd_tup res = f"{best_v}\n{best[0]} {best[1]} {best[2]}" return res t = int(input()) ans = [] for _ in range(t): ans.append(str(go())) print('\n'.join(ans)) ```
instruction
0
64,987
22
129,974
No
output
1
64,987
22
129,975
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` def f(a, b, c, op): if b > c: return [op+b%c, (a,b,b)] if c%b != 0: minc, maxc = min((c+b)-c%b, c-c%b), max((c+b)-c%b, c-c%b) if abs(c-minc)<=abs(c-maxc): return [op+abs(c-minc), (a,b,minc)] else: return [op+abs(c-maxc), (a,b,maxc)] else: return [op, (a,b,c)] def find_b(a, b, c, op=0): if b % a != 0: minb, maxb = min((a+b)-b%a, b-b%a), max((a+b)-b%a, b-b%a) c1, c2 = f(a, maxb, c, op+abs(b-maxb)), f(a, minb, c, op+abs(b-minb)) if c1[0] <= c2[0]: return c1 else: return c2 else: c1, c2 = f(a, b, c, op), f(a,b+a,c, op+a) if a == b: if c1[0] <= c2[0]: return c1 else: return c2 else: c3 = f(a,b-a,c, op+a) if c1 <= c2 and c1 <= c3: return c1 elif c2 <= c1 and c2 <= c3: return c2 elif c3 <= c1 and c3 <= c2: return c3 n = int(input()) for p in range(n): a,b,c = list(map(int, input().split())) min_solution = find_b(a,b,c) m = min_solution[0] for i in range(a-m, a+m+1): if i<=0: continue if i>a and abs(a-i)>m: break for j in range(i, b+m+1, i): if j>b and abs(b-j)>m: break if j>b and abs(a-i)+abs(b-j)>m: break if j>c and abs(i-a)+abs(j-b)+abs(b-c) < min_solution[0]: min_solution = (abs(i-a)+abs(j-b)+abs(b-c), (i,j,j)) elif c%j == 0 and abs(i-a)+abs(j-b) < min_solution[0]: min_solution = (abs(i-a)+abs(j-b), (i,j,c)) else: minc, maxc = min((c+j)-c%j, c-c%j), max((c+j)-c%j, c-c%j) if abs(c-minc)<=abs(c-maxc) and abs(i-a)+abs(j-b)+abs(c-minc) < min_solution[0]: min_solution = (abs(i-a)+abs(j-b)+abs(c-minc), (i,j,minc)) elif abs(c-minc) > abs(c-maxc) and abs(i-a)+abs(j-b)+abs(c-maxc) < min_solution[0]: min_solution = (abs(i-a)+abs(j-b)+abs(c-maxc), (i,j,maxc)) print(min_solution[0]) print(*min_solution[1]) ```
instruction
0
64,988
22
129,976
No
output
1
64,988
22
129,977
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` import sys input = sys.stdin.readline #import time def main(): #start = time.time() pos = [] for a in range(1, 10001, 1): for b in range(a, 10001, a): for c in range(b, 10001, b): pos.append([a, b, c]) #print(time.time() - start) for _ in range(int(input())): a, b, c = map(int,input().split()) move = 100000000 ans = [] for el in pos: tmove = (abs(a - el[0]) + abs(b - el[1]) + abs(c - el[2])) if tmove < move: move = tmove ans = el print(move) print(*ans) main() ```
instruction
0
64,989
22
129,978
No
output
1
64,989
22
129,979
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given three integers a ≤ b ≤ c. In one move, you can add +1 or -1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations. You have to perform the minimum number of such operations in order to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers a, b and c (1 ≤ a ≤ b ≤ c ≤ 10^4). Output For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers A ≤ B ≤ C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A, B and C. Example Input 8 1 2 3 123 321 456 5 10 15 15 18 21 100 100 101 1 22 29 3 19 38 6 30 46 Output 1 1 1 3 102 114 228 456 4 4 8 16 6 18 18 18 1 100 100 100 7 1 22 22 2 1 19 38 8 6 24 48 Submitted Solution: ``` TC = int(input()) MAX = 10000 def find(n, m) : q = int(n / m) n1 = m * q if((n * m) > 0): n2 = (m * (q + 1)) else: n2 = (m * (q - 1)) if (abs(n - n1) < abs(n - n2)): return n1 return n2 num2divisors = {} for c_cand in range(1, MAX + 1): divisors = [c_cand] i = 1 while i * i < c_cand: if c_cand % i == 0: divisors.append(i) divisors.append(c_cand // i) i += 1 num2divisors[c_cand] = divisors for _ in range(TC): a, b, c = map(int, input().split()) A = B = C = 1 s = a + b + c - 3 for c_cand in range(1, MAX + 1): for b_cand in num2divisors[c_cand]: for a_cand in num2divisors[b_cand]: s_cand = abs(a - a_cand) + abs(b - b_cand) + abs(c - c_cand) if s_cand < s: s = s_cand A = a_cand B = b_cand C = c_cand print(s) print(A, B, C) ```
instruction
0
64,990
22
129,980
No
output
1
64,990
22
129,981
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array a left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by k for each number). The seller can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n. Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). Input The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a. Output In the single line print a single number — the maximum possible beauty of the resulting array. Examples Input 6 1 3 6 10 12 13 16 Output 3 Input 5 3 8 21 52 15 77 Output 7 Note In the first sample we can obtain the array: 3 6 9 12 12 15 In the second sample we can obtain the next array: 7 21 49 14 77
instruction
0
65,148
22
130,296
Tags: brute force, dp, number theory Correct Solution: ``` import sys line = sys.stdin.readline() n, k = [int(i) for i in line.split()] line = sys.stdin.readline() _min = int(1e7) _max = 0 accum = [0] * int(1e6+2) for i in line.split(): j = int(i) accum[j]+=1 if j > _max: _max = j if j < _min: _min = j for i in range(1, _max+1): accum[i] += accum[i-1] # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 if k >= _min-1: print(_min) exit() gcd = 2; for i in range(_min, 1, -1): div = True j = 2*i comp = i-k while div: if j-1 <= _max: div = accum[j-1] == accum[j-comp] elif j-comp <= _max: div = accum[_max] == accum[j-comp] else: break j+=i if div: gcd = i break print(gcd) # 1494020463481 ```
output
1
65,148
22
130,297
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array a left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by k for each number). The seller can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n. Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). Input The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a. Output In the single line print a single number — the maximum possible beauty of the resulting array. Examples Input 6 1 3 6 10 12 13 16 Output 3 Input 5 3 8 21 52 15 77 Output 7 Note In the first sample we can obtain the array: 3 6 9 12 12 15 In the second sample we can obtain the next array: 7 21 49 14 77
instruction
0
65,149
22
130,298
Tags: brute force, dp, number theory Correct Solution: ``` n, k = map(int, input().split()) t = set(map(int, input().split())) y = x = min(t) t = list(t) while True: for i in t: if i % x > k: x = i // (i // x + 1) if y == x: break y = x print(y) # Made By Mostafa_Khaled ```
output
1
65,149
22
130,299
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array a left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by k for each number). The seller can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n. Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). Input The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a. Output In the single line print a single number — the maximum possible beauty of the resulting array. Examples Input 6 1 3 6 10 12 13 16 Output 3 Input 5 3 8 21 52 15 77 Output 7 Note In the first sample we can obtain the array: 3 6 9 12 12 15 In the second sample we can obtain the next array: 7 21 49 14 77
instruction
0
65,150
22
130,300
Tags: brute force, dp, number theory Correct Solution: ``` import sys line = sys.stdin.readline() n, k = [int(i) for i in line.split()] line = sys.stdin.readline() _min = int(1e7) _max = 0 accum = [0] * int(1e6+2) for i in line.split(): j = int(i) accum[j]+=1 if j > _max: _max = j if j < _min: _min = j for i in range(1, _max+1): accum[i] += accum[i-1] # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 if k >= _min-1: print(_min) exit() gcd = 2; for i in range(_min, 1, -1): div = True j = 2*i comp = i-k while div: if j-1 <= _max: div = accum[j-1] == accum[j-comp] elif j-comp <= _max: div = accum[_max] == accum[j-comp] else: break j+=i if div: gcd = i break print(gcd) # 1494021276904 ```
output
1
65,150
22
130,301
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array a left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by k for each number). The seller can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n. Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). Input The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a. Output In the single line print a single number — the maximum possible beauty of the resulting array. Examples Input 6 1 3 6 10 12 13 16 Output 3 Input 5 3 8 21 52 15 77 Output 7 Note In the first sample we can obtain the array: 3 6 9 12 12 15 In the second sample we can obtain the next array: 7 21 49 14 77
instruction
0
65,151
22
130,302
Tags: brute force, dp, number theory Correct Solution: ``` n,k=map(int,input().split()) t=set(map(int,input().split())) y=x=min(t) t=list(t) while True: for i in t: if i%x>k:x=i//(i//x+1) if y==x:break y=x print(y) ```
output
1
65,151
22
130,303
Provide tags and a correct Python 3 solution for this coding contest problem. Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array a left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by k for each number). The seller can obtain array b from array a if the following conditions hold: bi > 0; 0 ≤ ai - bi ≤ k for all 1 ≤ i ≤ n. Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). Input The first line contains two integers n and k (1 ≤ n ≤ 3·105; 1 ≤ k ≤ 106). The second line contains n integers ai (1 ≤ ai ≤ 106) — array a. Output In the single line print a single number — the maximum possible beauty of the resulting array. Examples Input 6 1 3 6 10 12 13 16 Output 3 Input 5 3 8 21 52 15 77 Output 7 Note In the first sample we can obtain the array: 3 6 9 12 12 15 In the second sample we can obtain the next array: 7 21 49 14 77
instruction
0
65,152
22
130,304
Tags: brute force, dp, number theory Correct Solution: ``` import sys line = sys.stdin.readline() n, k = [int(i) for i in line.split()] line = sys.stdin.readline() _min = int(1e7) _max = 0 accum = [0] * int(1e6+2) for i in line.split(): j = int(i) accum[j]+=1 if j > _max: _max = j if j < _min: _min = j for i in range(1, _max+1): accum[i] += accum[i-1] # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 if k >= _min-1: print(_min) exit() gcd = 2; for i in range(_min, 1, -1): div = True j = 2*i comp = i-k while div: if j-1 <= _max: div = accum[j-1] == accum[j-comp] elif j-comp <= _max: div = accum[_max] == accum[j-comp] else: break j+=i if div: gcd = i break print(gcd) # 1494020541233 ```
output
1
65,152
22
130,305
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,265
22
130,530
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` import sys, math input = sys.stdin.readline def getInts(): return [int(s) for s in input().split()] def getInt(): return int(input()) def getStrs(): return [s for s in input().split()] def getStr(): return input().strip() def listStr(): return list(input().strip()) import collections as col import math def solve(): #we need to know whether, amongst the C values, there are two or more pairwise coprime values whose product equals K N, K = getInts() C = getInts() lcm = 1 for c in C: lcm = lcm*c//math.gcd(lcm,c) lcm = math.gcd(lcm,K) return "Yes" if lcm == K else "No" #for _ in range(getInt()): print(solve()) ```
output
1
65,265
22
130,531
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,266
22
130,532
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` import os import sys from io import BytesIO, IOBase def main(): maxn = 10**6 maxn+=5 n,k = list(map(int,input().split())) arr = list(map(int,input().split())) prime = [0 for i in range(maxn+2)] freq = [0 for i in range(maxn+2)] flag = 0 for i in range(2,maxn): if prime[i]==0: for j in range(i,maxn,i): prime[j] = i for i in arr: num = i while num>1: pr = prime[num] cnt = 0 while True: if num%pr==0: cnt+=1 num = num//pr else: break freq[pr] = max(freq[pr],cnt) while k>1: pr = prime[k] if freq[pr]>0: freq[pr]-=1 k = k//pr else: k = k//pr flag = 1 break if flag==0: print("Yes") else: print("No") # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
65,266
22
130,533
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,267
22
130,534
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` import sys ints = (int(x) for x in sys.stdin.read().split()) def sieve(N): n = int((N**.5)+100) is_prime = [1]*n primes = [] div = [i for i in range(n)] for i in (i for i in range(2, n) if is_prime[i]): for j in range(i*i, n, i): is_prime[j] = 0 div[j] = i div[i] = i primes.append(i) return primes, div from collections import Counter from itertools import takewhile def decompose(x, primes, div): divs = [] push = lambda p: divs.append(p) or x//p for p in takewhile(lambda p: x>=len(div), primes): while x%p==0: x = push(p) if x>=len(div): x = push(x) while x>1: x = push(div[x]) return Counter(divs) primes, div = sieve(10**9) n, k = next(ints), next(ints) k = set(a**b for a, b in decompose(k, primes, div).items()) for x in set(next(ints) for i in range(n)): k -= set(y for y in k if x%y==0) print('NO' if k else 'YES') ```
output
1
65,267
22
130,535
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,268
22
130,536
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` #prime factorize the k import math a=input().split(' ') n=int(a[0]) k=int(a[1]) t=True def gcd(a, b): if b==0: return a else: return gcd(b, a%b) C=set(map(int, input().split())) Composite=False a=math.floor(math.sqrt(k+1)) if k%2==0: Composite=True else: for i in range(3, a+1, 2): if k%i==0: Composite=True break if not Composite: if k>max(C):print ('NO') else: A=set() z=True for i in C: if i in A: pass if i%k==0: z=False print ('YES') break else: A.add(i) if z: print('NO') else: A=set() m=1 for i in C: if i in A: pass else: A.add(i) m*=i/gcd(m,i) m%=k if m==0: t=False print('YES') break if t: print('NO') # Made By Mostafa_Khaled ```
output
1
65,268
22
130,537
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,269
22
130,538
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` import sys input = sys.stdin.buffer.readline from math import gcd def prog(): n,k = map(int,input().split()) nums = list(map(int,input().split())) max_powers = 1 for num in nums: max_powers = gcd(k, num*max_powers//gcd(num,max_powers)) if max_powers == k: print('YES') else: print('NO') prog() ```
output
1
65,269
22
130,539
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,270
22
130,540
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` from math import * n,k=map(int,input().split()) arr=list(map(int,input().split())) flag=0 if(k==1): print('Yes') else: arr1=[] temp=k for i in range(2,k+1): if(temp%i==0): cnt=0 while(temp%i==0): cnt+=1 temp=temp//i arr1.append(i**cnt) #print(*arr1) mainflag=0 for j in arr1: flag=0 for i in range(n): if(arr[i]%j==0): flag=1 break if(flag==0): mainflag=1 break if(mainflag==1): print('No') else: print('Yes') ```
output
1
65,270
22
130,541
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,271
22
130,542
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` import sys input=sys.stdin.readline import math n, k = map(int, input().split()) a = 1; ar = list(map(int, input().split())) for c in ar: a *= math.gcd(k,c)//math.gcd(a,c) #print(a,c) if a==k: print("Yes") else: print("No") ```
output
1
65,271
22
130,543
Provide tags and a correct Python 3 solution for this coding contest problem. Today Pari and Arya are playing a game called Remainders. Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value <image>. There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya <image> if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value <image> for any positive integer x? Note, that <image> means the remainder of x after dividing it by y. Input The first line of the input contains two integers n and k (1 ≤ n, k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000). Output Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise. Examples Input 4 5 2 3 5 12 Output Yes Input 2 7 2 3 Output No Note In the first sample, Arya can understand <image> because 5 is one of the ancient numbers. In the second sample, Arya can't be sure what <image> is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.
instruction
0
65,272
22
130,544
Tags: chinese remainder theorem, math, number theory Correct Solution: ``` #prime factorize the k import math a=input().split(' ') n=int(a[0]) k=int(a[1]) t=True def gcd(a, b): if b==0: return a else: return gcd(b, a%b) C=set(map(int, input().split())) Composite=False a=math.floor(math.sqrt(k+1)) if k%2==0: Composite=True else: for i in range(3, a+1, 2): if k%i==0: Composite=True break if not Composite: if k>max(C):print ('NO') else: A=set() z=True for i in C: if i in A: pass if i%k==0: z=False print ('YES') break else: A.add(i) if z: print('NO') else: A=set() m=1 for i in C: if i in A: pass else: A.add(i) m*=i/gcd(m,i) m%=k if m==0: t=False print('YES') break if t: print('NO') ```
output
1
65,272
22
130,545