message
stringlengths
2
57.2k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
61
108k
cluster
float64
22
22
__index_level_0__
int64
122
217k
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,725
22
165,450
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` n,m=map(int,input().split()) a=list(map(int,input().split())) ans=1 if(n>m): print(0) else: for i in range(n): for j in range(i+1,n): ans*=abs(a[i]-a[j]) ans=ans%m print(ans) ```
output
1
82,725
22
165,451
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,726
22
165,452
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` import math n,m=map(int,input().split()) l=list(map(int,input().split())) if n<=m: mul=1 for i in range(n-1): for j in range(i+1,n): t=(l[i]-l[j]) mul=mul*abs(t) mul%=m print(mul%m) else: exit(print(0)) ```
output
1
82,726
22
165,453
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,727
22
165,454
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` R=lambda:map(int,input().split()) n, m = R() a = list(R()) if n > m: print(0) else: #a = [x%m for x in a] ans = 1 for i in range(n): for j in range(i+1, n): ans = (ans * abs(a[i] - a[j])) % m print(ans) ```
output
1
82,727
22
165,455
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,728
22
165,456
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` n , m = map(int, input().split()) a = list(map(int, input().split())) ans = 1 if n > m: exit(print(0)) for i in range(n): for j in range(i+1,n): ans*=abs(a[i]-a[j]) ans = ans%m print(ans) ```
output
1
82,728
22
165,457
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,729
22
165,458
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` from itertools import groupby n, m = map(int, input().split()) a1 = list(map(int, input().split())) a = [el for el, _ in groupby(a1)] if n > m or len(a)!=len(a1): exit(print(0)) ans = 1 for i in range(n): for j in range(i+1, n): ans *= abs(a[i] - a[j]) ans %= m print(ans) ```
output
1
82,729
22
165,459
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,730
22
165,460
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` import sys input = lambda : sys.stdin.readline() n,m = map(int,input().split()) a = list(map(int,input().split())) s = 1 a.sort() if n>m: print(0) exit(0) for i in range(n): for j in range(n-1-i): s = (s*abs(a[i]-a[i+j+1]))%m if s==0: print(0) exit(0) print(s) ```
output
1
82,730
22
165,461
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,731
22
165,462
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` # problem 1305 c N,mod=map(int,input().split()) a=list(map(int,input().split())) if N>mod: print(0) elif N<=mod: ans=1 for i in range(N): for j in range(i+1,N): ans*=abs(a[j]-a[i]) ans%=mod print(ans) ```
output
1
82,731
22
165,463
Provide tags and a correct Python 3 solution for this coding contest problem. To become the king of Codeforces, Kuroni has to solve the following problem. He is given n numbers a_1, a_2, ..., a_n. Help Kuroni to calculate ∏_{1≀ i<j≀ n} |a_i - a_j|. As result can be very big, output it modulo m. If you are not familiar with short notation, ∏_{1≀ i<j≀ n} |a_i - a_j| is equal to |a_1 - a_2|β‹…|a_1 - a_3|β‹… ... β‹…|a_1 - a_n|β‹…|a_2 - a_3|β‹…|a_2 - a_4|β‹… ... β‹…|a_2 - a_n| β‹… ... β‹… |a_{n-1} - a_n|. In other words, this is the product of |a_i - a_j| for all 1≀ i < j ≀ n. Input The first line contains two integers n, m (2≀ n ≀ 2β‹… 10^5, 1≀ m ≀ 1000) β€” number of numbers and modulo. The second line contains n integers a_1, a_2, ..., a_n (0 ≀ a_i ≀ 10^9). Output Output the single number β€” ∏_{1≀ i<j≀ n} |a_i - a_j| mod m. Examples Input 2 10 8 5 Output 3 Input 3 12 1 4 5 Output 0 Input 3 7 1 4 9 Output 1 Note In the first sample, |8 - 5| = 3 ≑ 3 mod 10. In the second sample, |1 - 4|β‹…|1 - 5|β‹…|4 - 5| = 3β‹… 4 β‹… 1 = 12 ≑ 0 mod 12. In the third sample, |1 - 4|β‹…|1 - 9|β‹…|4 - 9| = 3 β‹… 8 β‹… 5 = 120 ≑ 1 mod 7.
instruction
0
82,732
22
165,464
Tags: brute force, combinatorics, math, number theory Correct Solution: ``` n, m = map(int, input().split()) li = list(map(int, input().split())) res = 1 if n > 10000: print(0) exit() for i in range(n): for j in range(i+1, n): res = (res * abs(li[i]-li[j])) % m print(res) ```
output
1
82,732
22
165,465
Provide a correct Python 3 solution for this coding contest problem. We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`. Constraints * 1 ≀ A ≀ 100 * 1 ≀ B ≀ 100 * 0 ≀ C < B Input Input is given from Standard Input in the following format: A B C Output Print `YES` or `NO`. Examples Input 7 5 1 Output YES Input 2 2 1 Output NO Input 1 100 97 Output YES Input 40 98 58 Output YES Input 77 42 36 Output NO
instruction
0
83,252
22
166,504
"Correct Solution: ``` from fractions import gcd a,b,c=map(int,input().split()) print("NO"if c%gcd(a,b)!=0else"YES") ```
output
1
83,252
22
166,505
Provide a correct Python 3 solution for this coding contest problem. We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`. Constraints * 1 ≀ A ≀ 100 * 1 ≀ B ≀ 100 * 0 ≀ C < B Input Input is given from Standard Input in the following format: A B C Output Print `YES` or `NO`. Examples Input 7 5 1 Output YES Input 2 2 1 Output NO Input 1 100 97 Output YES Input 40 98 58 Output YES Input 77 42 36 Output NO
instruction
0
83,253
22
166,506
"Correct Solution: ``` import fractions a,b,c=map(int,input().split()) if c%fractions.gcd(a,b)==0: print("YES") else: print("NO") ```
output
1
83,253
22
166,507
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective is to make the sum congruent to C modulo B. Determine whether this is possible. If the objective is achievable, print `YES`. Otherwise, print `NO`. Constraints * 1 ≀ A ≀ 100 * 1 ≀ B ≀ 100 * 0 ≀ C < B Input Input is given from Standard Input in the following format: A B C Output Print `YES` or `NO`. Examples Input 7 5 1 Output YES Input 2 2 1 Output NO Input 1 100 97 Output YES Input 40 98 58 Output YES Input 77 42 36 Output NO Submitted Solution: ``` import fraction a, b, c = map(int, input().split()) print("YES" if c%(fraction.gcd(a,b)) == 0 else "NO") ```
instruction
0
83,265
22
166,530
No
output
1
83,265
22
166,531
Provide a correct Python 3 solution for this coding contest problem. Give you N cards. Only one natural number is written on each card. However, the same number is never written. From now on, as a question, I will say an appropriate natural number. Please answer the largest remainder you get when you divide the number on the card you have by the number I said. For example, suppose you have three cards with 9, 3, and 8, respectively. If I say "4", find the remainder of 9 and 3 and 8 divided by 4, respectively. The remainders are 1, 3, and 0, respectively, but the largest remainder is 3, so 3 is the correct answer. Let's get started. e? Is it hard to have a lot of cards? It can not be helped. Now let's use the computer to find the largest remainder. Create a program that finds the largest of the remainders of the number on the card divided by the number asked. Ask the question many times, not just once, but never ask the same number more than once. input The input consists of one dataset. Input data is given in the following format. N Q c1 c2 ... cN q1 q2 :: qQ The number of cards N (2 ≀ N ≀ 300000) and the number of questions Q (2 ≀ Q ≀ 100000) are given in the first line, separated by one space, and the number ci (1 ≀ 100000) written on the card in the second line. ci ≀ 300000) is given with one space delimiter. The following Q line is given the number qi (1 ≀ qi ≀ 300000) given as a question. output Output the maximum remainder on one line for each question. Example Input 3 3 9 3 8 4 6 5 Output 3 3 4
instruction
0
83,295
22
166,590
"Correct Solution: ``` # AOJ 0270: Modular Query # Python3 2018.6.26 bal4u N, Q = map(int, input().split()) tbl = [0]*300005 nmax, tbl[0] = 0, 1 c = list(map(int, input().split())) for k in c: tbl[k] = 1 if k > nmax: nmax = k tbl[k & 1] = 1 tbl[k & 3] = 1 tbl[k & 7] = 1 for i in range(Q): q = int(input()) if q > nmax: print(nmax) else: f = 0 for k in range(q-1, -1, -1): for i in range(k, nmax+1, q): if tbl[i]: print(k) f = 1 break if f: break ```
output
1
83,295
22
166,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tuple generator f^{(k)} = (f_1^{(k)}, f_2^{(k)}, ..., f_n^{(k)}), where f_i^{(k)} = (a_i β‹… f_i^{(k - 1)} + b_i) mod p_i and f^{(0)} = (x_1, x_2, ..., x_n). Here x mod y denotes the remainder of x when divided by y. All p_i are primes. One can see that with fixed sequences x_i, y_i, a_i the tuples f^{(k)} starting from some index will repeat tuples with smaller indices. Calculate the maximum number of different tuples (from all f^{(k)} for k β‰₯ 0) that can be produced by this generator, if x_i, a_i, b_i are integers in the range [0, p_i - 1] and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by 10^9 + 7 Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of elements in the tuple. The second line contains n space separated prime numbers β€” the modules p_1, p_2, …, p_n (2 ≀ p_i ≀ 2 β‹… 10^6). Output Print one integer β€” the maximum number of different tuples modulo 10^9 + 7. Examples Input 4 2 3 5 7 Output 210 Input 3 5 3 3 Output 30 Note In the first example we can choose next parameters: a = [1, 1, 1, 1], b = [1, 1, 1, 1], x = [0, 0, 0, 0], then f_i^{(k)} = k mod p_i. In the second example we can choose next parameters: a = [1, 1, 2], b = [1, 1, 0], x = [0, 0, 1]. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Sep 23 10:17:51 2018 @author: yanni """ import math def factor(N, d=1): if N == 1: return 1 for D in range(d+1, int(math.sqrt(N) + 2)): if (N % D == 0): count= 0 while (N%D == 0): N = N//D count += 1 return (D, count, N) return (N,1,1) n = int(input()) p = [int(x) for x in input().split()] add_one = False powers = {} values = {} for prime in p: if prime in values: values[prime] += 1 else: values[prime] = 1 to_look = sorted(values.keys(), reverse = True) for pm in values: if (values[pm]>2): add_one = True for pm in values: unused = values[pm] if pm not in powers: powers[pm] = 1 unused -= 1 if (unused > 0): N = pm-1 d = 1 useful = False while (N > 1): d, exp, N = factor(N, d) if d in powers: if (exp > powers[d]): powers[d] = max(exp, powers[d]) useful = True else: powers[d] = exp useful = True if (useful): unused -= 1 if (unused > 0): add_one = True ans = 1 big_prime = 10**9+7 for pm in powers: ans *= ((pm**powers[pm]) % big_prime) ans = ans % big_prime if (add_one): ans = (ans+1) % big_prime print(ans) ```
instruction
0
83,388
22
166,776
No
output
1
83,388
22
166,777
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tuple generator f^{(k)} = (f_1^{(k)}, f_2^{(k)}, ..., f_n^{(k)}), where f_i^{(k)} = (a_i β‹… f_i^{(k - 1)} + b_i) mod p_i and f^{(0)} = (x_1, x_2, ..., x_n). Here x mod y denotes the remainder of x when divided by y. All p_i are primes. One can see that with fixed sequences x_i, y_i, a_i the tuples f^{(k)} starting from some index will repeat tuples with smaller indices. Calculate the maximum number of different tuples (from all f^{(k)} for k β‰₯ 0) that can be produced by this generator, if x_i, a_i, b_i are integers in the range [0, p_i - 1] and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by 10^9 + 7 Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of elements in the tuple. The second line contains n space separated prime numbers β€” the modules p_1, p_2, …, p_n (2 ≀ p_i ≀ 2 β‹… 10^6). Output Print one integer β€” the maximum number of different tuples modulo 10^9 + 7. Examples Input 4 2 3 5 7 Output 210 Input 3 5 3 3 Output 30 Note In the first example we can choose next parameters: a = [1, 1, 1, 1], b = [1, 1, 1, 1], x = [0, 0, 0, 0], then f_i^{(k)} = k mod p_i. In the second example we can choose next parameters: a = [1, 1, 2], b = [1, 1, 0], x = [0, 0, 1]. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Sun Sep 23 10:17:51 2018 @author: yanni """ import math def factor(N, d=1): if N == 1: return 1 for D in range(d+1, int(math.sqrt(N) + 2)): if (N % D == 0): count= 0 while (N%D == 0): N = N//D count += 1 return (D, count, N) return (N,1,1) n = int(input()) p = [int(x) for x in input().split()] add_one = False powers = {} values = {} for prime in p: if prime in values: values[prime] += 1 else: values[prime] = 1 #print(values) for pm in values: if pm not in powers: powers[pm] = 1 if (values[pm] > 1): N = pm-1 d = 1 while (N > 1): #print(factor(N, d)) d, exp, N = factor(N, d) if d in powers: #print(d, exp) powers[d] = max(exp, powers[d]) else: powers[d] = exp #print(powers) #print(powers) if (values[pm] > 2): add_one = True ans = 1 big_prime = 10**9+7 for pm in powers: ans *= (pm**powers[pm]) ans = ans % big_prime if (add_one): ans = (ans+1) % big_prime print(ans) ```
instruction
0
83,389
22
166,778
No
output
1
83,389
22
166,779
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tuple generator f^{(k)} = (f_1^{(k)}, f_2^{(k)}, ..., f_n^{(k)}), where f_i^{(k)} = (a_i β‹… f_i^{(k - 1)} + b_i) mod p_i and f^{(0)} = (x_1, x_2, ..., x_n). Here x mod y denotes the remainder of x when divided by y. All p_i are primes. One can see that with fixed sequences x_i, y_i, a_i the tuples f^{(k)} starting from some index will repeat tuples with smaller indices. Calculate the maximum number of different tuples (from all f^{(k)} for k β‰₯ 0) that can be produced by this generator, if x_i, a_i, b_i are integers in the range [0, p_i - 1] and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by 10^9 + 7 Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of elements in the tuple. The second line contains n space separated prime numbers β€” the modules p_1, p_2, …, p_n (2 ≀ p_i ≀ 2 β‹… 10^6). Output Print one integer β€” the maximum number of different tuples modulo 10^9 + 7. Examples Input 4 2 3 5 7 Output 210 Input 3 5 3 3 Output 30 Note In the first example we can choose next parameters: a = [1, 1, 1, 1], b = [1, 1, 1, 1], x = [0, 0, 0, 0], then f_i^{(k)} = k mod p_i. In the second example we can choose next parameters: a = [1, 1, 2], b = [1, 1, 0], x = [0, 0, 1]. Submitted Solution: ``` mod = 10**9 + 7 _ = input() l = input().split() l = list(map(lambda x : int(x), l)) d = {x:x for x in l} s = set() for i in l: if d[i] <= 1: continue while d[i] in s and d[i] > 1: d[i] -= 1 if d[i] > 1: s.add(d[i]) res = 1 for i in s: res = (res * i) % mod print(res) ```
instruction
0
83,390
22
166,780
No
output
1
83,390
22
166,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given a tuple generator f^{(k)} = (f_1^{(k)}, f_2^{(k)}, ..., f_n^{(k)}), where f_i^{(k)} = (a_i β‹… f_i^{(k - 1)} + b_i) mod p_i and f^{(0)} = (x_1, x_2, ..., x_n). Here x mod y denotes the remainder of x when divided by y. All p_i are primes. One can see that with fixed sequences x_i, y_i, a_i the tuples f^{(k)} starting from some index will repeat tuples with smaller indices. Calculate the maximum number of different tuples (from all f^{(k)} for k β‰₯ 0) that can be produced by this generator, if x_i, a_i, b_i are integers in the range [0, p_i - 1] and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by 10^9 + 7 Input The first line contains one integer n (1 ≀ n ≀ 2 β‹… 10^5) β€” the number of elements in the tuple. The second line contains n space separated prime numbers β€” the modules p_1, p_2, …, p_n (2 ≀ p_i ≀ 2 β‹… 10^6). Output Print one integer β€” the maximum number of different tuples modulo 10^9 + 7. Examples Input 4 2 3 5 7 Output 210 Input 3 5 3 3 Output 30 Note In the first example we can choose next parameters: a = [1, 1, 1, 1], b = [1, 1, 1, 1], x = [0, 0, 0, 0], then f_i^{(k)} = k mod p_i. In the second example we can choose next parameters: a = [1, 1, 2], b = [1, 1, 0], x = [0, 0, 1]. Submitted Solution: ``` from math import gcd n = int(input()) primeList = [int(e) for e in input().split(' ')] uniqueSet = set() duplicateList = [] pile = 1 for e in primeList: if e in uniqueSet: duplicateList.append(e) else: uniqueSet.add(e) pile *= e fallingEdge = 0 for e in duplicateList: maxv = 1; original = e while e>maxv: e -= 1; thegcd = gcd(e,pile); t = e//thegcd; if(t>maxv): maxv = t; pile *= maxv if maxv==1 and fallingEdge<original-1: fallingEdge = original-1 print(pile+fallingEdge) """ 4 2 3 5 7 ------------------- 210 ------------------- 3 5 3 3 ------------------- 30 """ ```
instruction
0
83,391
22
166,782
No
output
1
83,391
22
166,783
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,541
22
167,082
Tags: data structures, math, number theory Correct Solution: ``` import math def pf(n): l=[] while n % 2 == 0: l.append(2) n = n // 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: l.append(i) n = n // i if n > 2: l.append(n) return l n=int(input()) p=[[] for i in range(200005)] a=list(map(int,input().split())) ans=1 for i in range(n): l=pf(a[i]) for j in range(len(l)): if j==0: p[l[j]].append(1) else: if l[j]==l[j-1]: p[l[j]][-1]+=1 continue else: p[l[j]].append(1) for i in range(len(p)): if len(p[i])==(n-1): for j in range(min(p[i])): ans*=i if len(p[i])==n: p[i].sort() for j in range(p[i][1]): ans*=i print(ans) ```
output
1
83,541
22
167,083
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,542
22
167,084
Tags: data structures, math, number theory Correct Solution: ``` x=int(input()) s=list(map(int,input().split())) from math import gcd def lc(x,y): return x*y//gcd(x,y) gc=[0]*x gc[-1]=s[-1] for n in range(x-2,-1,-1): gc[n]=gcd(s[n],gc[n+1]) res=lc(s[0],gc[1]) for n in range(1,x-1): res=gcd(res,lc(s[n],gc[n+1])) print(res) ```
output
1
83,542
22
167,085
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,543
22
167,086
Tags: data structures, math, number theory Correct Solution: ``` import math n = int(input()) arr = list(map(int, input().split())) assert len(arr) == n ans = arr[0]*arr[1]//math.gcd(arr[0],arr[1]) # gcd(t) so far g = math.gcd(*arr[:2]) # gcd(arr) so far for i in range(2, n): g2 = math.gcd(arr[i], g) ans = math.gcd(ans, arr[i]*g//g2) g = g2 print(ans) # import math # n=int(input()) # a=list(map(int,input().strip().split(' '))) # ans=(a[0]*a[1])//math.gcd(a[0],a[1]) # g=math.gcd(a[0],a[1]) # for i in a[2:]: # newg=math.gcd(i,g) # ans=math.gcd(ans,i*g//newg) # g=newg # print(int(ans)) ```
output
1
83,543
22
167,087
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,544
22
167,088
Tags: data structures, math, number theory Correct Solution: ``` def gcd(a,b): if a==0: return b if b==0: return a if a>b: return gcd(a%b,b) else: return gcd(a,b%a) n=int(input()) li=[int(x) for x in input().split()] gcd_suffix=[0]*(n) gcd_suffix[n-1]=li[n-1] iterator=li[n-1] for i in range(n-2,-1,-1): iterator=gcd(iterator,li[i]) gcd_suffix[i]=iterator for i in range(n-1): val=int((li[i]*gcd_suffix[i+1])/gcd_suffix[i]) if i==0: final_gcd=val else: final_gcd=gcd(final_gcd,val) print(final_gcd) ```
output
1
83,544
22
167,089
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,545
22
167,090
Tags: data structures, math, number theory Correct Solution: ``` from collections import defaultdict N = 2*(10**5) + 1 def fast_power(a, b): power = 1 while b: if b&1: power *= a a *= a b >>= 1 return power def pp(): spf = [i for i in range(N)] i = 2 while i*i < N: if spf[i] == i: j = 2 while i*j < N: spf[i*j] = min(i, spf[i*j]) j += 1 i += 1 return spf def f(num, ma, spf): cnt = {} while num > 1: cnt[spf[num]] = cnt.get(spf[num], 0) + 1 num //= spf[num] for key in cnt: ma[key].append(cnt[key]) def main(): spf = pp() n = int(input()) arr = list(map(int, input().strip().split())) if n == 1: print(arr[0]) return ma = defaultdict(list) for num in arr: f(num, ma, spf) ret = 1 for key in ma: if len(ma[key]) < (n-1): continue ma[key].sort() if len(ma[key]) == n-1: ret *= fast_power(key, ma[key][0]) else: ret *= fast_power(key, ma[key][1]) print(ret) if __name__ == "__main__": main() ```
output
1
83,545
22
167,091
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,546
22
167,092
Tags: data structures, math, number theory Correct Solution: ``` def main(): from array import array from collections import Counter from itertools import chain from math import gcd from sys import stdin, stdout n = int(stdin.readline()) if n == 2: a, b = map(int, stdin.readline().split()) print(a // gcd(a, b) * b) return a = array('i', map(int, stdin.readline().split())) ans = 1 for p in range(2, 444): pows = [0] * n for i in range(n): while not a[i] % p: a[i] //= p pows[i] += 1 pows.sort() ans *= p ** pows[1] cnt = Counter(a) nm1 = n - 1 print(ans * next(chain((k for k in cnt.keys() if cnt[k] >= nm1), (1,)))) main() ```
output
1
83,546
22
167,093
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,547
22
167,094
Tags: data structures, math, number theory Correct Solution: ``` from math import * a=int(input()) b=list(map(int,input().split())) l=(b[0]*b[1])//gcd(b[0],b[1]) g=gcd(b[0],b[1]) for i in b[2:]: l=gcd(l,(i*g)//gcd(i,g)) g=gcd(i,g) print(l) ```
output
1
83,547
22
167,095
Provide tags and a correct Python 3 solution for this coding contest problem. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40.
instruction
0
83,548
22
167,096
Tags: data structures, math, number theory Correct Solution: ``` from math import gcd def fun(): n=int(input()) arr=list(map(int,input().split())) whole=gcd(arr[0],arr[1]) for i in range(2,n): whole=gcd(whole,arr[i]) for i in range(n): arr[i]=arr[i]//whole prefix=[0]*n suffix=[0]*n prefix[0]=arr[0] suffix[-1]=arr[-1] for i in range(1,n): prefix[i]=gcd(prefix[i-1],arr[i]) for i in range(n-2,-1,-1): suffix[i]=gcd(suffix[i+1],arr[i]) ans=whole for i in range(1,n-1): ans*=gcd(prefix[i-1],suffix[i+1]) ans*=prefix[n-2] ans*=suffix[1] return ans print(fun()) ```
output
1
83,548
22
167,097
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` from math import gcd def lcm(a,b): return a*b//gcd(a,b) input() a=list(map(int,input().split())) t=gcd(a[0],a[1]) q=lcm(a[0],a[1]) for i in range(2,len(a)): q=gcd(q,lcm(a[i],t)) t=gcd(t,a[i]) print(q) ```
instruction
0
83,549
22
167,098
Yes
output
1
83,549
22
167,099
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` import math #t=int(input()) n=int(input()) suff_gcd=[0]*n ar=list(map(int,input().split())) suff_gcd[-1]=ar[-1] for i in range (n-2,-1,-1): suff_gcd[i]=math.gcd(suff_gcd[i+1],ar[i]) temp=[] for i in range (0,n-1): res=(ar[i]*suff_gcd[i+1])//suff_gcd[i] temp.append(res) sol=temp[0] for i in range (1,len(temp)): sol=math.gcd(sol,temp[i]) print(sol) ```
instruction
0
83,550
22
167,100
Yes
output
1
83,550
22
167,101
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` n = int(input()) a = list(map(int, input().split())) d1 = dict() prost = [2] for i in range(3, int((10**6+2)**(1/2))+2): flag = True for k in prost: if i % k == 0: flag = False break if flag: prost.append(i) for i in a: d = dict() x = 0 ind = 0 while prost[ind] <= i**(1/2)+1: if i % prost[ind] == 0: if prost[ind] not in d: d[prost[ind]] = 0 d[prost[ind]] += 1 i //= prost[ind] else: ind += 1 if i != 1: if i in d: d[i] += 1 else: d[i] = 1 for c in d: if c in d1: d1[c].append(d[c]) else: d1[c] = [] d1[c].append(d[c]) ans = 1 for i in d1: if len(d1[i]) <= n-2: continue if len(d1[i]) == n-1: ans *= i**min(d1[i]) continue if len(d1[i]) == n: first = 1000000 second = 1000000 for kek in d1[i]: if kek <= second: if kek <= first: second = first first = kek else: second = kek ans *= i**second print(ans) ```
instruction
0
83,551
22
167,102
Yes
output
1
83,551
22
167,103
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` MOD = 10 ** 9 + 7 RLIMIT = 1000 DEBUG = 1 def main(): for _ in inputt(1): n, = inputi() A = inputl() if n == 1: print(A[0]) elif n == 2: print(A[0] * A[1] // gcd(*A)) else: D = {d: [-inf, -inf] for d in factordict(A[0]) + factordict(A[1])} for a in A: p = factordict(a) for d in D: heappushpop(D[d], -p[d]) debug(D) t = 1 for d, c in D.items(): t *= d ** (-c[0]) print(t) # region M # region import from math import * from heapq import * from itertools import * from functools import reduce, lru_cache, partial from collections import Counter, defaultdict, deque import re, copy, operator, cmath import sys, io, os, builtins sys.setrecursionlimit(RLIMIT) # endregion # region fastio BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = io.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(io.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") def print(*args, **kwargs): if args: sys.stdout.write(str(args[0])) split = kwargs.pop("split", " ") for arg in args[1:]: sys.stdout.write(split) sys.stdout.write(str(arg)) sys.stdout.write(kwargs.pop("end", "\n")) def debug(*args, **kwargs): if DEBUG and not __debug__: print("debug", *args, **kwargs) sys.stdout.flush() sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip() inputt = lambda t = 0: range(t) if t else range(int(input())) inputs = lambda: input().split() inputi = lambda k = int: map(k, inputs()) inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k()) # endregion # region bisect def len(a): if isinstance(a, range): return -((a.start - a.stop) // a.step) return builtins.len(a) def bisect_left(a, x, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) if key == None: key = do_nothing while lo < hi: mid = (lo + hi) // 2 if key(a[mid]) < x: lo = mid + 1 else: hi = mid return lo def bisect_right(a, x, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) if key == None: key = do_nothing while lo < hi: mid = (lo + hi) // 2 if x < key(a[mid]): hi = mid else: lo = mid + 1 return lo def insort_left(a, x, key = None, lo = 0, hi = None): lo = bisect_left(a, x, key, lo, hi) a.insert(lo, x) def insort_right(a, x, key = None, lo = 0, hi = None): lo = bisect_right(a, x, key, lo, hi) a.insert(lo, x) do_nothing = lambda x: x bisect = bisect_right insort = insort_right def index(a, x, default = None, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) if key == None: key = do_nothing i = bisect_left(a, x, key, lo, hi) if lo <= i < hi and key(a[i]) == x: return a[i] if default != None: return default raise ValueError def find_lt(a, x, default = None, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) i = bisect_left(a, x, key, lo, hi) if lo < i <= hi: return a[i - 1] if default != None: return default raise ValueError def find_le(a, x, default = None, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) i = bisect_right(a, x, key, lo, hi) if lo < i <= hi: return a[i - 1] if default != None: return default raise ValueError def find_gt(a, x, default = None, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) i = bisect_right(a, x, key, lo, hi) if lo <= i < hi: return a[i] if default != None: return default raise ValueError def find_ge(a, x, default = None, key = None, lo = 0, hi = None): if lo < 0: lo = 0 if hi == None: hi = len(a) i = bisect_left(a, x, key, lo, hi) if lo <= i < hi: return a[i] if default != None: return default raise ValueError # endregion # region csgraph # TODO class Tree: def __init__(n): self._n = n self._conn = [[] for _ in range(n)] self._list = [0] * n def connect(a, b): pass # endregion # region ntheory class Sieve: def __init__(self): self._n = 6 self._list = [2, 3, 5, 7, 11, 13] def extend(self, n): if n <= self._list[-1]: return maxbase = int(n ** 0.5) + 1 self.extend(maxbase) begin = self._list[-1] + 1 newsieve = [i for i in range(begin, n + 1)] for p in self.primerange(2, maxbase): for i in range(-begin % p, len(newsieve), p): newsieve[i] = 0 self._list.extend([x for x in newsieve if x]) def extend_to_no(self, i): while len(self._list) < i: self.extend(int(self._list[-1] * 1.5)) def primerange(self, a, b): a = max(2, a) if a >= b: return self.extend(b) i = self.search(a)[1] maxi = len(self._list) + 1 while i < maxi: p = self._list[i - 1] if p < b: yield p i += 1 else: return def search(self, n): if n < 2: raise ValueError if n > self._list[-1]: self.extend(n) b = bisect(self._list, n) if self._list[b - 1] == n: return b, b else: return b, b + 1 def __contains__(self, n): if n < 2: raise ValueError if not n % 2: return n == 2 a, b = self.search(n) return a == b def __getitem__(self, n): if isinstance(n, slice): self.extend_to_no(n.stop + 1) return self._list[n.start: n.stop: n.step] else: self.extend_to_no(n + 1) return self._list[n] sieve = Sieve() def isprime(n): if n <= sieve._list[-1]: return n in sieve for i in sieve: if not n % i: return False if n < i * i: return True prime = sieve.__getitem__ primerange = lambda a, b = 0: sieve.primerange(a, b) if b else sieve.primerange(2, a) def factorint(n): factors = [] for i in sieve: if n < i * i: break while not n % i: factors.append(i) n //= i if n != 1: factors.append(n) return factors factordict = lambda n: Counter(factorint(n)) # endregion # region main if __name__ == "__main__": main() # endregion # endregion ```
instruction
0
83,552
22
167,104
Yes
output
1
83,552
22
167,105
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` # Contest No.: 641 # Problem No.: C # Solver: JEMINI # Date: 20200512 ##### FAST INPUT ##### import os import sys from io import BytesIO, IOBase 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") ##### END OF FAST INPUT ##### #import sys def main(): n = int(input()) nums = list(map(int, input().split())) primeList = [True] * (10 ** 5 + 1) primeList[0] = False primeList[1] = False prime = [] for i in range(2, 10 ** 5 + 1): if primeList[i]: cnt = 2 * i prime.append(i) while cnt <= 10 ** 5: primeList[cnt] = False cnt += i ans = 1 for i in prime: noCnt = 0 bigCnt = 0 tempList = [] for j in nums: if j < i: bigCnt += 1 if j % i or j < i: noCnt += 1 else: tempj = j cnt = 0 while not tempj % i: temp = 1 while not tempj % (i ** (temp * 2)): temp <<= 1 cnt += temp tempj = tempj // (i ** temp) if len(tempList) < 2: tempList.append(cnt) tempList.sort() else: if tempList[0] <= cnt <= tempList[1]: tempList[1] = cnt elif cnt < tempList[0]: tempList[1] = tempList[0] tempList[0] = cnt if noCnt >= 2: break if bigCnt == n: break if noCnt == 0: ans *= i ** tempList[1] elif noCnt == 1: ans *= i ** tempList[0] print(ans) return if __name__ == "__main__": main() ```
instruction
0
83,553
22
167,106
No
output
1
83,553
22
167,107
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` from itertools import combinations def gcd(a,b): if b == 0: return a return gcd(b,a%b) n = int(input()) lis = list(map(int, input().split())) temp = lis[0] for x in range(1,len(lis)): if temp != lis[x]: arr = list(set(lis)) z = list(combinations(arr,2)) lcm = [] count = 0 gcdes = 0 if len(z) >= 2: for x in z: a = x[0] b = x[1] lcm.append(a*b//(gcd(a,b))) if count == 1: gcdes = gcd(lcm[count-1],lcm[count]) #print(g ) elif count > 1: gcdes = gcd(gcdes,lcm[count]) count += 1 print(gcdes) else: print(gcd(z[0][0],z[0][1])) break elif x == len(lis)-1: print(temp) ```
instruction
0
83,554
22
167,108
No
output
1
83,554
22
167,109
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` from collections import defaultdict, Counter n = int(input()) a = [int(x) for x in input().split()] def fact(n): gaps = [1,2,2,4,2,4,2,4,6,2,6] length, cycle = 11, 3 f, fs, nxt = 2, [], 0 while f * f <= n: while n % f == 0: fs.append(f) n //= f f += gaps[nxt] nxt += 1 if nxt == length: nxt = cycle if n > 1: fs.append(n) return Counter(fs) # ~ print(fact(24)) min_p = defaultdict(list) cnt = defaultdict(int) for i in range(n): fa = fact(a[i]) for p in fa: cnt[p]+=1 act = fa[p] l = min_p[p] l.append(act) l.sort() min_p[p] = l[:2] ans = 1 # ~ print(min_p) for p in min_p: l = min_p[p] l.sort() if cnt[p] <= n-2: exp = 0 if cnt[p] == n-1: exp = l[0] else: exp = l[-1] ans *= p**exp print(ans) ```
instruction
0
83,555
22
167,110
No
output
1
83,555
22
167,111
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. For the multiset of positive integers s=\\{s_1,s_2,...,s_k\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow: * \gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x. * lcm(s) is the minimum positive integer x, that divisible on all integers from s. For example, \gcd(\{8,12\})=4,\gcd(\{12,18,6\})=6 and lcm(\{4,6\})=12. Note that for any positive integer x, \gcd(\\{x\})=lcm(\\{x\})=x. Orac has a sequence a with length n. He come up with the multiset t=\{lcm(\\{a_i,a_j\})\ |\ i<j\}, and asked you to find the value of \gcd(t) for him. In other words, you need to calculate the GCD of LCMs of all pairs of elements in the given sequence. Input The first line contains one integer n\ (2≀ n≀ 100 000). The second line contains n integers, a_1, a_2, …, a_n (1 ≀ a_i ≀ 200 000). Output Print one integer: \gcd(\{lcm(\\{a_i,a_j\})\ |\ i<j\}). Examples Input 2 1 1 Output 1 Input 4 10 24 40 80 Output 40 Input 10 540 648 810 648 720 540 594 864 972 648 Output 54 Note For the first example, t=\{lcm(\{1,1\})\}=\{1\}, so \gcd(t)=1. For the second example, t=\{120,40,80,120,240,80\}, and it's not hard to see that \gcd(t)=40. Submitted Solution: ``` import io import os from collections import Counter, defaultdict, deque from math import gcd import heapq def primeFactors(n): # Returns a counter of prime factors of n # e.g., 12 returns {2: 2, 3: 1} assert n >= 1 factors = Counter() while n % 2 == 0: factors[2] += 1 n //= 2 x = 3 while x * x <= n: while n % x == 0: factors[x] += 1 n //= x x += 2 if n != 1: factors[n] += 1 return factors def lcm(a, b): return (a * b) // gcd(a, b) def solve(N, A): A = list(set(A)) N = len(A) if len(A) == 1: return A[0] if len(A) <= 2: l = [] for i in range(N): for j in range(i + 1, N): l.append(lcm(A[i], A[j])) g = 0 for x in l: g = gcd(g, x) return g pToCount = defaultdict(list) for x in A: for p, count in primeFactors(x).items(): pToCount[p].append(count) g = 1 for p, counts in pToCount.items(): if N - len(counts) >= 2: continue g *= p ** max(heapq.nsmallest(2, counts)) return g if __name__ == "__main__": input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline (N,) = [int(x) for x in input().split()] A = [int(x) for x in input().split()] ans = solve(N, A) print(ans) ```
instruction
0
83,556
22
167,112
No
output
1
83,556
22
167,113
Provide tags and a correct Python 3 solution for this coding contest problem. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k - 1 and yet are divisible by k. Input The first and only line contains three positive integers a, b, k (1 ≀ a ≀ b ≀ 2Β·109, 2 ≀ k ≀ 2Β·109). Output Print on a single line the answer to the given problem. Examples Input 1 10 2 Output 5 Input 12 23 3 Output 2 Input 6 19 5 Output 0 Note Comments to the samples from the statement: In the first sample the answer is numbers 2, 4, 6, 8, 10. In the second one β€” 15, 21 In the third one there are no such numbers.
instruction
0
83,902
22
167,804
Tags: dp, math, number theory Correct Solution: ``` import math def prime(x): for i in range(2, int(math.sqrt(x))+1): if x % i == 0: return 0 return 1 def cal(n, k): if not prime(k): return 0 elif k >= n: return k == n res = n // k for i in range(2, min(k, n // k +1)): res -= cal(n // k, i) return res a, b, k = input().split() a = int(a) b = int(b) k = int(k) print(cal(b, k) - cal(a - 1, k)) ```
output
1
83,902
22
167,805
Provide tags and a correct Python 3 solution for this coding contest problem. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k - 1 and yet are divisible by k. Input The first and only line contains three positive integers a, b, k (1 ≀ a ≀ b ≀ 2Β·109, 2 ≀ k ≀ 2Β·109). Output Print on a single line the answer to the given problem. Examples Input 1 10 2 Output 5 Input 12 23 3 Output 2 Input 6 19 5 Output 0 Note Comments to the samples from the statement: In the first sample the answer is numbers 2, 4, 6, 8, 10. In the second one β€” 15, 21 In the third one there are no such numbers.
instruction
0
83,903
22
167,806
Tags: dp, math, number theory Correct Solution: ``` def pr(x): d = 2 while d * d <= x: if x % d == 0: return 0 d += 1 return 1 def cnt(n, k): if not pr(k) or n < k: return 0 n1 = n // k return n1 - sum(cnt(n1, i) for i in range(2, min(k, n1 + 1))) a, b, k = map(int, input().split()) ans = cnt(b, k) - cnt(a - 1, k) print(ans) ```
output
1
83,903
22
167,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k - 1 and yet are divisible by k. Input The first and only line contains three positive integers a, b, k (1 ≀ a ≀ b ≀ 2Β·109, 2 ≀ k ≀ 2Β·109). Output Print on a single line the answer to the given problem. Examples Input 1 10 2 Output 5 Input 12 23 3 Output 2 Input 6 19 5 Output 0 Note Comments to the samples from the statement: In the first sample the answer is numbers 2, 4, 6, 8, 10. In the second one β€” 15, 21 In the third one there are no such numbers. Submitted Solution: ``` import math def P(n): if n <= 1: return 0 for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return 0 return 1 def q(x,y,w): return x//w-y//w+1 x=[int(i) for i in input().split()] k=x[2] c=int((x[0]-0.5)//k+1) d=x[1]//k if P(k)==0: print(0) raise SystemExit if k==2: print(d-c+1) raise SystemExit if k==3: print(d-c+1-q(c,d,2)) raise SystemExit if k==5: print(d-c+1-q(c,d,2)-q(c,d,3)+q(c,d,6)) raise SystemExit kp=[] j=3 while j<k: if P(j)==1: kp.append(j) j=j+2 s=0 i=c+int(c%2==0) while i <=d: t=1 for j in kp: if i%j==0: t=0 break s=s+t i=i+2 print(s) ```
instruction
0
83,904
22
167,808
No
output
1
83,904
22
167,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k - 1 and yet are divisible by k. Input The first and only line contains three positive integers a, b, k (1 ≀ a ≀ b ≀ 2Β·109, 2 ≀ k ≀ 2Β·109). Output Print on a single line the answer to the given problem. Examples Input 1 10 2 Output 5 Input 12 23 3 Output 2 Input 6 19 5 Output 0 Note Comments to the samples from the statement: In the first sample the answer is numbers 2, 4, 6, 8, 10. In the second one β€” 15, 21 In the third one there are no such numbers. Submitted Solution: ``` import math def P(n): if n <= 1: return 0 for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return 0 return 1 def q(x,y,w): return x//w-y//w+1 x=[int(i) for i in input().split()] k=x[2] c=int((x[0]-0.5)//k+1) d=x[1]//k if P(k)==0: print(0) raise SystemExit if k==2: print(d-c+1) raise SystemExit if k==3: print(q(c,d,3)-q(c,d,2)) raise SystemExit if k==5: print(q(c,d,5)-q(c,d,2)-q(c,d,3)+q(c,d,6)) raise SystemExit kp=[] j=3 while j<k: if P(j)==1: kp.append(j) j=j+2 s=0 i=c+int(c%2==0) while i <=d: t=1 for j in kp: if i%j==0: t=0 break s=s+t i=i+2 print(s) ```
instruction
0
83,905
22
167,810
No
output
1
83,905
22
167,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k - 1 and yet are divisible by k. Input The first and only line contains three positive integers a, b, k (1 ≀ a ≀ b ≀ 2Β·109, 2 ≀ k ≀ 2Β·109). Output Print on a single line the answer to the given problem. Examples Input 1 10 2 Output 5 Input 12 23 3 Output 2 Input 6 19 5 Output 0 Note Comments to the samples from the statement: In the first sample the answer is numbers 2, 4, 6, 8, 10. In the second one β€” 15, 21 In the third one there are no such numbers. Submitted Solution: ``` import math def P(n): if n <= 1: return 0 for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: return 0 return 1 def q(x,y,w): return y//w-x//w+1 x=[int(i) for i in input().split()] k=x[2] c=int((x[0]-0.5)//k+1) d=x[1]//k if P(k)==0: print(0) raise SystemExit if k==2: print(d-c+1) raise SystemExit if k==3: print(d-c+1-q(c,d,2)) raise SystemExit if k==5: print(d-c+1-q(c,d,2)-q(c,d,3)+q(c,d,6)) raise SystemExit kp=[] j=3 while j<k: if P(j)==1: kp.append(j) j=j+2 s=0 i=c+int(c%2==0) while i <=d: t=1 for j in kp: if i%j==0: t=0 break s=s+t i=i+2 print(s) ```
instruction
0
83,906
22
167,812
No
output
1
83,906
22
167,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One quite ordinary day Valera went to school (there's nowhere else he should go on a week day). In a maths lesson his favorite teacher Ms. Evans told students about divisors. Despite the fact that Valera loved math, he didn't find this particular topic interesting. Even more, it seemed so boring that he fell asleep in the middle of a lesson. And only a loud ringing of a school bell could interrupt his sweet dream. Of course, the valuable material and the teacher's explanations were lost. However, Valera will one way or another have to do the homework. As he does not know the new material absolutely, he cannot do the job himself. That's why he asked you to help. You're his best friend after all, you just cannot refuse to help. Valera's home task has only one problem, which, though formulated in a very simple way, has not a trivial solution. Its statement looks as follows: if we consider all positive integers in the interval [a;b] then it is required to count the amount of such numbers in this interval that their smallest divisor will be a certain integer k (you do not have to consider divisor equal to one). In other words, you should count the amount of such numbers from the interval [a;b], that are not divisible by any number between 2 and k - 1 and yet are divisible by k. Input The first and only line contains three positive integers a, b, k (1 ≀ a ≀ b ≀ 2Β·109, 2 ≀ k ≀ 2Β·109). Output Print on a single line the answer to the given problem. Examples Input 1 10 2 Output 5 Input 12 23 3 Output 2 Input 6 19 5 Output 0 Note Comments to the samples from the statement: In the first sample the answer is numbers 2, 4, 6, 8, 10. In the second one β€” 15, 21 In the third one there are no such numbers. Submitted Solution: ``` def pr(x): d = 2 while d * d <= x: if x % d == 0: return 0 d += 1 return 1 def cnt(n, k): if not pr(n) or n < k: return 0 n1 = n // k return n1 - sum(cnt(n1, i) for i in range(2, min(k, n1 + 1))) a, b, k = map(int, input().split()) ans = cnt(b, k) - cnt(a - 1, k) print(ans) ```
instruction
0
83,907
22
167,814
No
output
1
83,907
22
167,815
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,158
22
168,316
"Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- n = int(input()) i = 1 num = [0] * 13 while True: cnt = 0 for j in range(1, i+1): if i % j == 0: cnt += 1 if cnt > 12: i += 1 continue if num[cnt] == 0: num[cnt] = i if num[n] > 0: ans = num[n] break i += 1 print(ans) ```
output
1
84,158
22
168,317
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,159
22
168,318
"Correct Solution: ``` print([0,1,2,4,6,16,12,64,24,36,48,1024,60][int(input())]) ```
output
1
84,159
22
168,319
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,160
22
168,320
"Correct Solution: ``` # AOJ 1562: Divisor # Python3 2018.7.13 bal4u ans = [0, 1, 2, 4, 6, 16, 12, 64, 24, 36, 48, 1024, 60] print(ans[int(input())]) ```
output
1
84,160
22
168,321
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,161
22
168,322
"Correct Solution: ``` def solve(n): for i in range(1,10000): cnt=0 for j in range(1,i+1): if i%j==0: cnt+=1 if cnt==n: return(i) while True: try: n=int(input()) print(solve(n)) except EOFError: break ```
output
1
84,161
22
168,323
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,162
22
168,324
"Correct Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- def f(n): ret = 0 for a in range(1, n+1): if n % a == 0: ret += 1 return ret N = int(input()) n = 1 while True: if f(n) == N: print(n) break n += 1 ```
output
1
84,162
22
168,325
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,163
22
168,326
"Correct Solution: ``` print([1,2,4,6,16,12,64,24,36,48,1024,60][int(input())-1]) ```
output
1
84,163
22
168,327
Provide a correct Python 3 solution for this coding contest problem. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4
instruction
0
84,164
22
168,328
"Correct Solution: ``` N = int(input()) target = 1 while True: count = 0 for i in range(1, target+1): if target % i == 0: count += 1 if count == N: print(target) break target += 1 ```
output
1
84,164
22
168,329
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4 Submitted Solution: ``` def solve(n): for i in range(1,100): cnt=0 for j in range(1,i+1): if i%j==0: cnt+=1 if cnt==n: return(i) n=int(input()) print(solve(n)) ```
instruction
0
84,165
22
168,330
No
output
1
84,165
22
168,331
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4 Submitted Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- n = int(input()) i = 1 num = [0] * 13 #num[i] -> ?Β΄???Β°???i???????????Β°??Β§????Β°??????Β° while True: cnt = 0 for j in range(1, i+1): if i % j == 0: cnt += 1 if num[cnt] == 0: num[cnt] = i if num[n] > 0: ans = num[n] break i += 1 print(ans) ```
instruction
0
84,166
22
168,332
No
output
1
84,166
22
168,333
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4 Submitted Solution: ``` def solve(n): for i in range(1,100): cnt=0 for j in range(1,i+1): if i%j==0: cnt+=1 if cnt==n: return(i) while True: try: n=int(input()) print(solve(n)) except EOFError: break ```
instruction
0
84,167
22
168,334
No
output
1
84,167
22
168,335
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural number on a line so that the number of divisors is exactly N. Examples Input 1 Output 1 Input 2 Output 2 Input 3 Output 4 Submitted Solution: ``` #!/usr/bin/env python3 # -*- coding: utf-8 -*- n = int(input()) i = 1 num = [0] * 13 while True: cnt = 0 for j in range(1, i+1): if i % j == 0: cnt += 1 if cnt >= 12: i += 1 continue if num[cnt] == 0: num[cnt] = i if num[n] > 0: ans = num[n] break i += 1 print(ans) ```
instruction
0
84,168
22
168,336
No
output
1
84,168
22
168,337
Provide tags and a correct Python 2 solution for this coding contest problem. You are given a positive integer n. Find a sequence of fractions (a_i)/(b_i), i = 1 … k (where a_i and b_i are positive integers) for some k such that: $$$ \begin{cases} $b_i$ divides $n$, $1 < b_i < n$ for $i = 1 … k$ \\\ $1 ≀ a_i < b_i$ for $i = 1 … k$ \\\ \text{$βˆ‘_{i=1}^k (a_i)/(b_i) = 1 - 1/n$} \end{cases} $$$ Input The input consists of a single integer n (2 ≀ n ≀ 10^9). Output In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise. If there exists such a sequence, next lines should contain a description of the sequence in the following format. The second line should contain integer k (1 ≀ k ≀ 100 000) β€” the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most 100 000. Next k lines should contain fractions of the sequence with two integers a_i and b_i on each line. Examples Input 2 Output NO Input 6 Output YES 2 1 2 1 3 Note In the second example there is a sequence 1/2, 1/3 such that 1/2 + 1/3 = 1 - 1/6.
instruction
0
84,259
22
168,518
Tags: math Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline from fractions import Fraction pr = stdout.write def in_num(): return int(raw_input()) def in_arr(): return map(int,raw_input().split()) def pr_num(n): stdout.write(str(n)+'\n') def pr_arr(arr): pr(' '.join(map(str,arr))+'\n') # fast read function for total integer input def inp(): # this function returns whole input of # space/line seperated integers # Use Ctrl+D to flush stdin. return map(int,stdin.read().split()) range = xrange # not for python 3.0+ # main code n=input() arr=[] i=2 N=n while i*i<=n: if n%i==0: #print i,n n/=i arr.append(i) while n%i==0: n/=i arr[-1]*=i i+=1 if n>1: arr.append(n) if len(arr)>1: for i in range(1,arr[0]): f=Fraction(N-1,N)-Fraction(i,arr[0]) if f.denominator<N: pr('YES\n') pr_num(2) pr_arr([i,arr[0]]) pr_arr([f.numerator,f.denominator]) exit() pr('NO') ```
output
1
84,259
22
168,519