message stringlengths 2 57.2k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 61 108k | cluster float64 22 22 | __index_level_0__ int64 122 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is known that even numbers greater than or equal to 4 can be represented by the sum of two prime numbers. This is called the Goldbach's conjecture, and computer calculations have confirmed that it is correct up to a fairly large number. For example, 10 can be represented by the sum of two prime numbers, 7 + 3 and 5 + 5.
Write a program that inputs the integer n and outputs how many combinations of n are the sum of two prime numbers. However, n must be 4 or more and 50,000 or less. Also, the n entered is not always even.
Input
Given multiple datasets. Each dataset is given n on one row. When n is 0, it is the last input. The number of datasets does not exceed 10,000.
Output
For each dataset, output the number of combinations in which n is the sum of two prime numbers on one line.
Example
Input
10
11
0
Output
2
0
Submitted Solution:
```
MAX = 50001
is_prime = [True for _ in range(MAX)]
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX ** (1 / 2)) + 1):
if is_prime[i]:
for j in range(i ** 2, MAX, i):
is_prime[j] = False
primes = [i for i in range(MAX) if is_prime[i]]
def main():
while True:
n = int(input())
if not n:
break
primes_less_than_n = [i for i in primes if i <= n // 2]
ans = 0
for i in primes_less_than_n:
if i > n // 2:
break
if is_prime[n - i]:
ans += 1
print(ans)
main()
``` | instruction | 0 | 51,223 | 22 | 102,446 |
No | output | 1 | 51,223 | 22 | 102,447 |
Provide tags and a correct Python 2 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 | 51,497 | 22 | 102,994 |
Tags: data structures, math, number theory
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
from fractions import gcd
raw_input = stdin.readline
pr = stdout.write
mod=10**9+7
def ni():
return int(raw_input())
def li():
return map(int,raw_input().split())
def pn(n):
stdout.write(str(n)+'\n')
def pl(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+
n=ni()
l=li()
g=l[0]
arr=[]
for i in range(1,n):
arr.append((l[i]*g)/gcd(l[i],g))
g=gcd(g,l[i])
n=len(arr)
ans=arr[0]
for i in range(1,n):
ans=gcd(ans,arr[i])
pn(ans)
``` | output | 1 | 51,497 | 22 | 102,995 |
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 | 51,498 | 22 | 102,996 |
Tags: data structures, math, number theory
Correct Solution:
```
import math
def lcm(a,b):
return a*b//(math.gcd(a,b))
n=int(input())
a=list(map(int,input().split()))
b=a[:]
for i in range(n-2,-1,-1):
b[i]=math.gcd(b[i+1],b[i])
for i in range(n-1):
b[i+1]=lcm(a[i],b[i+1])
ans=0
for i in range(1,n):
ans=math.gcd(ans,b[i])
print(ans)
``` | output | 1 | 51,498 | 22 | 102,997 |
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 | 51,499 | 22 | 102,998 |
Tags: data structures, math, number theory
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
arr.insert(0, 0)
pre = [0] * (n+1)
suf = [0] * (n+1)
pre[1] = arr[1]
suf[n] = arr[n]
for i in range(2, n + 1):
pre[i] = gcd(pre[i-1], arr[i])
for i in range(n-1, 0, -1):
suf[i] = gcd(suf[i+1], arr[i])
ans = None
for i in range(0, n):
if i == 0:
ans = suf[2]
elif i == n - 1:
ans = ans * pre[n-1]//gcd(pre[n-1], ans)
else:
ans = ans * gcd(pre[i], suf[i+2]) // gcd(gcd(pre[i], suf[i+2]), ans)
print(ans)
``` | output | 1 | 51,499 | 22 | 102,999 |
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 | 51,500 | 22 | 103,000 |
Tags: data structures, math, number theory
Correct Solution:
```
import math
def LCM(a, b):
return (a * b)//math.gcd(a, b)
n = int(input())
arr = list(map(int, input().split()))
suffix_arr = [1] * n
suffix_arr[-1] = arr[n-1]
for i in range(n-2, -1, -1):
suffix_arr[i] = math.gcd(arr[i], suffix_arr[i+1])
ans = LCM(arr[0], suffix_arr[1])
for i in range(1, n-1):
ans = math.gcd(ans, LCM(arr[i], suffix_arr[i+1]))
print(ans)
``` | output | 1 | 51,500 | 22 | 103,001 |
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 | 51,501 | 22 | 103,002 |
Tags: data structures, math, number theory
Correct Solution:
```
from collections import Counter,defaultdict,deque
from math import gcd
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(2**30)
def lcm(a,b):
return a*b//gcd(a,b)
def solve():
n = int(input())
arr = [int(x) for x in input().split()]
a = arr[0]
b = arr[1]
best = lcm(a,b)
second = gcd(a,b)
for i in range(2,n):
el = arr[i]
best = gcd(best,el)*gcd(second,best)//gcd(second,el)
second = gcd(second,el)
print(best)
solve()
``` | output | 1 | 51,501 | 22 | 103,003 |
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 | 51,502 | 22 | 103,004 |
Tags: data structures, math, number theory
Correct Solution:
```
from math import gcd
n=int(input())
l=list(map(int,input().split()))
g=[1]*(n+1)
g[n]=l[n-1]
for i in range(n-1,-1,-1):
g[i]=gcd(g[i+1],l[i])
# print(g)
ans=(g[1]*l[0])//gcd(l[0],g[1])
for i in range(n-1):
ans=gcd(ans,(l[i]*g[i+1])//(gcd(l[i],g[i+1])))
print(ans)
``` | output | 1 | 51,502 | 22 | 103,005 |
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 | 51,503 | 22 | 103,006 |
Tags: data structures, math, number theory
Correct Solution:
```
n = int(input())
arr = [int(x) for x in input().split()]
import math
if n==2:
arr.sort()
if (arr[1]%arr[0]!=0):
x = (arr[1]*arr[0])//math.gcd(arr[1],arr[0])
print(x)
exit()
gcc = []
gcc.append(arr[n-1])
gcc.append(math.gcd(arr[n-1],arr[n-2]))
for i in range(n-3,0,-1):
gcc.append(math.gcd(gcc[-1],arr[i]))
#print(gcc)
for i in range(len(gcc)):
gcc[i] = (gcc[i]*(arr[n-i-2]))//(math.gcd(gcc[i],arr[n-i-2]))
#print(gcc)
ans = math.gcd(gcc[0],gcc[1])
for i in range(2,len(gcc)):
ans=math.gcd(ans,gcc[i])
print(ans)
``` | output | 1 | 51,503 | 22 | 103,007 |
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 | 51,504 | 22 | 103,008 |
Tags: data structures, math, number theory
Correct Solution:
```
# HEY STALKER
import math
n = int(input())
l = list(map(int, input().split()))
dp = [0 for ti in range(n+1)]
ans = 0
dp[n] = l[n-1]
for i in range(n-1, 0, -1):
dp[i] = math.gcd(l[i-1], dp[i+1])
ans = math.gcd(ans, l[i-1]*dp[i+1]//dp[i])
print(ans)
``` | output | 1 | 51,504 | 22 | 103,009 |
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 | 51,505 | 22 | 103,010 |
Tags: data structures, math, number theory
Correct Solution:
```
import math
from collections import defaultdict,Counter
# Function to calculate all the prime
# factors and count of every prime factor
def f(n):
count = 0;
d=defaultdict(int)
# count the number of
# times 2 divides
while ((n % 2 > 0) == False):
# equivalent to n = n / 2;
n >>= 1;
count += 1;
# if 2 divides it
if (count > 0):
d[2]=count;
# check for all the possible
# numbers that can divide it
for i in range(3, int(math.sqrt(n)) + 1):
count = 0;
while (n % i == 0):
count += 1;
n = int(n / i);
if (count > 0):
d[i]=count;
i += 2;
# if n at the end is a prime number.
if (n > 2):
d[n]=1;
return d
n=int(input())
l=list(map(int,input().split()))
d1=defaultdict(int)
d2=defaultdict(list)
for i in l:
d=f(i)
for j in d:
d1[j]+=1
d2[j].append(d[j])
ans=1
for j in d1:
if d1[j]==n:
d2[j].sort()
ans*=j**d2[j][1]
elif d1[j]==n-1:
ans*=j**min(d2[j])
print(ans)
``` | output | 1 | 51,505 | 22 | 103,011 |
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 sys,math
input = sys.stdin.buffer.readline
def primes(n):
ass = []
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
for i in range(len(is_prime)):
if is_prime[i]:
ass.append(i)
return ass
n = int(input())
a = list(map(int,input().split()))
def lcm(a, b):
return a * b // math.gcd (a, b)
if n == 2:
print(lcm(a[0],a[1]))
exit()
pr = primes(2500)
res = 1
for e in pr:
mi = 10**6
nx = 10**6
for i in range(n):
c = 0
while a[i] % e == 0:
c += 1
a[i] = a[i]//e
if c < mi:
mi,nx = c,mi
elif c < nx:
nx = c
if nx != 10**6:
res = res*(e**nx)
a.sort()
if a[1] == a[-1]:
res *= a[1]
elif a[0] == a[-2]:
res *= a[0]
print(res)
``` | instruction | 0 | 51,506 | 22 | 103,012 |
Yes | output | 1 | 51,506 | 22 | 103,013 |
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 sys, math
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
factor = dict()
for i in arr:
temp = dict()
idx = 2
for j in range(2, int(i ** 0.5) + 1):
while i % j == 0:
if j not in temp:
temp[j] = 0
temp[j] += 1
i //= j
if i > 1:
temp[i] = 1
for j in temp:
if j not in factor:
factor[j] = []
factor[j].append(temp[j])
ans = 1
for i in factor:
size = len(factor[i])
if size < n - 1:
continue
elif size == n - 1:
factor[i].append(0)
factor[i].sort()
ans *= pow(i, factor[i][1])
print(ans)
``` | instruction | 0 | 51,507 | 22 | 103,014 |
Yes | output | 1 | 51,507 | 22 | 103,015 |
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 sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n=int(input())
l=[int(i) for i in input().split()]
pref=[l[0]]
for i in range(1,n):
pref.append(math.gcd(pref[i-1],l[i]))
suff=[0 for i in range(n)]
suff[n-1]=l[n-1]
for i in range(n-2,-1,-1):
suff[i]=math.gcd(suff[i+1],l[i])
gcd=[suff[1]]
for i in range(1,n-1):
gcd.append(math.gcd(pref[i-1],suff[i+1]))
gcd.append(pref[n-2])
lcm=gcd[0]
for i in range(1,n):
lcm=(lcm*gcd[i])//math.gcd(lcm,gcd[i])
print(lcm)
``` | instruction | 0 | 51,508 | 22 | 103,016 |
Yes | output | 1 | 51,508 | 22 | 103,017 |
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 sys import stdin
from math import gcd
n = int(stdin.readline())
arr = list(map(int,stdin.readline().split()))
gc = [arr[-1]]
for i in range(n-2,0,-1):
gc.append(gcd(gc[-1],arr[i]))
ans = (arr[0]*gc[-1])//gcd(arr[0],gc[-1])
for i in range(1,n-1):
ans = gcd(ans,(arr[i]*gc[-1-i])//gcd(arr[i],gc[-1-i]))
print(ans)
``` | instruction | 0 | 51,509 | 22 | 103,018 |
Yes | output | 1 | 51,509 | 22 | 103,019 |
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 functools import lru_cache
from fractions import gcd
from functools import reduce
def find_gcd(list):
x = reduce(gcd, list)
return x
n = int(input())
nums = list(map(int,input().split()))
def tgcd(N,nums):
l = min(nums)
print(list(reversed(range(l+1))))
for i in reversed(range(2,l+1)):
cd = True
for j in range(N):
if nums[j] % i != 0:
cd = False
break
if cd:
return i
return 1
def ez_gcd(x, y):
while(y):
x, y = y, x % y
return x
def find_lcm(n1, n2):
if(n1>n2):
num = n1
d2 = n2
else:
num = n2
d2 = n1
rem = num % d2
while(rem != 0):
num = d2
d2 = rem
rem = num % d2
gcd = d2
lcm = int(int(n1 * n2)/int(gcd))
return lcm
# Python program to find the L.C.M. of two input number
# This function computes GCD
def compute_gcd(x, y):
while(y):
x, y = y, x % y
return x
# This function computes LCM
def compute_lcm(x, y):
lcm = (x*y)//compute_gcd(x,y)
return lcm
final_lcm = []
seen = []
repeated = 0
def find_array():
prev_seen = []
total = 0
for i in range(len(nums)):
curr_seen = []
for j in range(i+1,len(nums)):
num1 = nums[i]
num2 = nums[j]
lcm = compute_lcm(num1, num2)
if lcm in final_lcm:
pass
else:
final_lcm.append(lcm)
curr_seen.append(lcm)
if prev_seen == curr_seen:
total += 1
if total > 500:
break
break
prev_seen = curr_seen
find_array()
# print(final_lcm)
lcm = sorted(final_lcm)
# print(lcm)
# if len(lcm) == 1:
# print(lcm[0])
# else:
# n1=lcm[0]
# n2=lcm[1]
# gcd=ez_gcd(n1,n2)
# # print(lcm)
# for i in range(2,len(lcm)):
# gcd=ez_gcd(gcd,lcm[i])
# ans = tgcd(len(final_lcm),final_lcm)
# print(ans)
ans = find_gcd(final_lcm)
print(ans)
# print(ans)
``` | instruction | 0 | 51,510 | 22 | 103,020 |
No | output | 1 | 51,510 | 22 | 103,021 |
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
q=int(input())
w=list(map(int,input().split()))
l=[w[-1]]
g=w[-1]
for i in range(q-2,-1,-1):
k=math.gcd(w[i],g)
l.append(w[i]*(g//k))
g=k
g=l[0]
for i in l[1::]:
g=math.gcd(i,g)
print(g)
``` | instruction | 0 | 51,511 | 22 | 103,022 |
No | output | 1 | 51,511 | 22 | 103,023 |
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 as mt
from collections import Counter
MAXN = 200001
# stores smallest prime factor for
# every number
spf = [0 for i in range(MAXN)]
# Calculating SPF (Smallest Prime Factor)
# for every number till MAXN.
# Time Complexity : O(nloglogn)
def sieve():
spf[1] = 1
for i in range(2, MAXN):
# marking smallest prime factor
# for every number to be itself.
spf[i] = i
# separately marking spf for
# every even number as 2
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, mt.ceil(mt.sqrt(MAXN))):
# checking if i is prime
if (spf[i] == i):
# marking SPF for all numbers
# divisible by i
for j in range(i * i, MAXN, i):
# marking spf[j] if it is
# not previously marked
if (spf[j] == j):
spf[j] = i
# A O(log n) function returning prime
# factorization by dividing by smallest
# prime factor at every step
def getFactorization(x):
ret = list()
while (x != 1):
ret.append(spf[x])
x = x // spf[x]
return ret
sieve()
n=int(input())
a=[int(o) for o in input().split()]
d=dict()
for i in a:
dd=dict(Counter(getFactorization(i)))
# print(dd)
for j in dd:
try:
d[j].append(dd[j])
except:
d[j]=[dd[j]]
ans=1
for i in d:
d[i]=sorted(d[i])
if len(d[i])>=n-1:
try:
ans*=pow(i,d[i][1])
except:
ans*=pow(i,d[i][0])
print(ans)
``` | instruction | 0 | 51,512 | 22 | 103,024 |
No | output | 1 | 51,512 | 22 | 103,025 |
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 sys
input = sys.stdin.buffer.readline
def primes(n):
ass = []
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
for i in range(len(is_prime)):
if is_prime[i]:
ass.append(i)
return ass
pr = primes(200001)
n = int(input())
a = list(map(int,input().split()))
pr = primes(200001)
res = 1
for e in pr:
if e > 500:
break
mi = 10**6
nx = 10**6
for i in range(n):
c = 0
if a[i] >= e:
while a[i] % e == 0:
c += 1
a[i] = a[i]//e
if c < mi:
mi = c
elif c < nx:
nx = c
if nx == 10**6:
nx = 0
res *= e**(nx)
used = dict()
fin = dict()
for e in a:
if e != 1:
if e in used:
if not e in fin:
res *= e
fin[e] = 1
else:
used[e] = 1
print(res)
``` | instruction | 0 | 51,513 | 22 | 103,026 |
No | output | 1 | 51,513 | 22 | 103,027 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,590 | 22 | 103,180 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
def t_prime(lst):
primes, st = [0] * int(1e6), set()
for i in range(2, int(1e6)):
if not primes[i]:
st.add(i * i)
primes[i * i::i] = [1] * len(primes[i * i::i])
a = list()
for elem in lst:
if elem in st:
a.append("YES")
else:
a.append("NO")
return a
n = int(input())
b = [int(j) for j in input().split()]
print(*t_prime(b), sep='\n')
``` | output | 1 | 51,590 | 22 | 103,181 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,591 | 22 | 103,182 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
input()
l=1000002
c=[1,1]+[0]*l
for i in range(2,l):
if 1-c[i]:
for j in range(i*i,l,i):c[j]=1
for i in input().split():
i=int(i)
r=int(i**0.5)
print("YNEOS"[c[r]or r*r!=i::2])
``` | output | 1 | 51,591 | 22 | 103,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,592 | 22 | 103,184 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
import math
n=int(input())
X=input()
X=X.split(" ")
N=[]
for i in range(1000001):
N.append("NO")
N[1]="YES"
for i in range(2,1000001):
if N[i]=="NO":
for j in range(2*i,1000001,i):
N[j]="YES"
for i in range(0,n):
x=int(X[i])
y=int(math.sqrt(x))
if y*y==x and N[y]=="NO":
print("YES")
else:
print("NO")
``` | output | 1 | 51,592 | 22 | 103,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,593 | 22 | 103,186 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
import math
input()
L = list(map(int, input().split(" ")))
def is_prime(n):
if n == 1: return False
if n == 2: return True
k = 2
while k * k <= n:
if n % k == 0:
return False
k += 1
return True
def helper(n):
if n < 10:
return n == 4 or n == 9
k = int(math.sqrt(n))
return k * k == n and is_prime(k)
for e in L:
if helper(e):
print("YES")
else:
print("NO")
``` | output | 1 | 51,593 | 22 | 103,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,594 | 22 | 103,188 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
# https://blog.dotcpp.com/a/69737
def oula(r):
prime = [0 for i in range(r+1)]
common = []
for i in range(2, r+1):
if prime[i] == 0:
common.append(i)
for j in common:
if i*j > r:
break
prime[i*j] = 1
if i % j == 0:
break
return prime
s = oula(1000000)
#print(s)
input()
for i in map(int,input().split()):
if i<4:
print('NO')
continue
elif int(i**0.5)**2 != i:
print('NO')
continue
if s[int(i**0.5)]==0:
print('YES')
else:
print('NO')
``` | output | 1 | 51,594 | 22 | 103,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,595 | 22 | 103,190 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
def is_prime(x):
l = [True] * (int(x)+1)
l[0] = l[1] = False
for p in range(2,int(x)):
if l[p] == True:
for _ in range(p*2, int(x),p):
l[_] = False
return l[1:]
tkpl = is_prime(1000000)
n = int(input())
l_new = input().split()
for m in l_new:
if int(m) == 4:
print('YES')
elif int(m) < 4 or int(m) % 2 == 0:
print('NO')
else:
m_sqrt = int(m) ** 0.5
if m_sqrt % 1 == 0 and tkpl[int(m_sqrt)-1] == True:
print('YES')
else:
print('NO')
``` | output | 1 | 51,595 | 22 | 103,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,596 | 22 | 103,192 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
def cal_primeflag():
primeflag=[0]*1000000
primeflag[0]=primeflag[1]=1;
for i in range(1000000):
if (primeflag[i]==0):
for j in range(i*i,1000000,i):
primeflag[j]=1
return primeflag
n=int(input())
l=input().split()
primeflag=cal_primeflag()
for i in range(n):
l[i]=int(l[i])
if l[i]==4:
print("YES")
elif l[i]%2==0:
print("NO")
elif pow(l[i],0.5)==int(pow(l[i],0.5)):
if primeflag[int(pow(l[i],0.5))]==0:
print("YES")
else:
print("NO")
else:
print("NO")
``` | output | 1 | 51,596 | 22 | 103,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | instruction | 0 | 51,597 | 22 | 103,194 |
Tags: binary search, implementation, math, number theory
Correct Solution:
```
#!/usr/bin/env python
# coding=utf-8
import math
t_list = [1]*1000001
t_list[0] = 0
t_list[1] = 0
for i in range(2, 1000):
if t_list[i] == 0:
continue
j = i*i
while j <= 1000000:
t_list[j] = 0
j += i
input_s = input()
input_l = map(int, input().split())
for i in input_l:
m = int(math.sqrt(i))
print('YES' if m*m == i and t_list[m] == 1 else 'NO')
``` | output | 1 | 51,597 | 22 | 103,195 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
# _____ _ _ _ _ _ __ _ _ _ _
# / ___|| | (_)| | (_) | | / / (_) | | (_)| |
# \ `--. | |__ _ | |_ ___ _ _ _ __ ___ _ | |/ / __ _ _ __ ___ _ _ __ ___ __ _ ___ | |__ _ | |_ __ _
# `--. \| '_ \ | || __|/ __|| | | || '__|/ _ \| | | \ / _` || '_ ` _ \ | || '_ ` _ \ / _` |/ __|| '_ \ | || __|/ _` |
# /\__/ /| | | || || |_ \__ \| |_| || | | __/| | _ | |\ \| (_| || | | | | || || | | | | || (_| |\__ \| | | || || |_| (_| |
# \____/ |_| |_||_| \__||___/ \__,_||_| \___||_|( ) \_| \_/ \__,_||_| |_| |_||_||_| |_| |_| \__,_||___/|_| |_||_| \__|\__,_|
# |/
import math
# file = open("input", "r")
def getIn():
# return file.readline().strip()
return input().strip()
def SieveOfEratosthenes(n):
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 1
prime[0]= False
prime[1]= False
return prime
n = int(getIn())
b = list(map(int, getIn().split(" ")))
prime = SieveOfEratosthenes(int(1e6))
for num in b:
sr = math.sqrt(num)
fl = math.floor(sr)
if (sr - fl) == 0:
if prime[int(sr)]:
print("YES")
else:
print("NO")
else:
print("NO")
``` | instruction | 0 | 51,598 | 22 | 103,196 |
Yes | output | 1 | 51,598 | 22 | 103,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
import math
from sys import stdin,stdout
n=int(stdin.readline())
l=list(map(int,stdin.readline().split()))
m=max(l)
N=int(math.sqrt(m))+2
primes=[1]*N
primes[1]=0
p=2
while p*p<=N:
if primes[p]:
for mul in range(p*p,N,p):
primes[mul]=0
p+=1
for v in l:
sq=int(math.sqrt(v))
if sq*sq==v:
if primes[sq]:print('YES')
else:print('NO')
else:print('NO')
``` | instruction | 0 | 51,599 | 22 | 103,198 |
Yes | output | 1 | 51,599 | 22 | 103,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
n = int(input())
l = 1000002
c = [1,1] + [0]*l
for i in range(2,l):
if 1-c[i]:
for j in range(i*i, l, i):
c[j] = 1
for i in input().rstrip().split():
i = int(i)
r = int(i**0.5)
print('YNEOS'[c[r] or r*r != i::2])
``` | instruction | 0 | 51,600 | 22 | 103,200 |
Yes | output | 1 | 51,600 | 22 | 103,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
def sieve(n):
is_prime = [True for i in range(n)]
is_prime[0] = is_prime[1] = False
primes = []
for i in range(2, n):
if not is_prime[i]:
continue
primes.append(i)
j = i ** 2
while j < n:
is_prime[j] = False
j += i
return primes
primes = sieve(10 ** 6)
e_nums = {i**2 for i in primes}
n = int(input())
tests = input().split()
for i in range(len(tests)):
tests[i] = int(tests[i])
for test in tests:
if test in e_nums:
print("YES")
else:
print("NO")
``` | instruction | 0 | 51,601 | 22 | 103,202 |
Yes | output | 1 | 51,601 | 22 | 103,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
import math
n = int(input())
nums = list(map(int, input().split()))
for i in range(n):
if ((math.floor(math.sqrt(nums[i])))**2==nums[i] and nums[i]!=1):
print("YES")
else:
print("NO")
``` | instruction | 0 | 51,602 | 22 | 103,204 |
No | output | 1 | 51,602 | 22 | 103,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
n=int(input())
array=[int(x) for x in input().split()]
ncount=2
for j in array:
for k in range(j//2-1):
if j%(k+2)==0:
ncount+=1
j=j//(k+1)
if ncount==3:
print('YES')
else:
print('NO')
ncount=2
``` | instruction | 0 | 51,603 | 22 | 103,206 |
No | output | 1 | 51,603 | 22 | 103,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
from math import floor,ceil
def isPrime(N):
if N<2:
return 0
if N<4:
return 1
c=5
while True:
if c**0.5<N:
break
if N%c==0:
return 0
c+=2
if N%c==0:
return 0
c+=4
return 1
def isSqr(N):
x=N**0.5
t=floor(x)
c=ceil(x)
if t*t==N and isPrime(t) or c*c==N and isPrime(c):
print("YES")
else:
print("NO")
N=int(input())
a=list(map(int,input().split()))
for i in a:
isSqr(i)
``` | instruction | 0 | 51,604 | 22 | 103,208 |
No | output | 1 | 51,604 | 22 | 103,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer t Π’-prime, if t has exactly three distinct positive divisors.
You are given an array of n positive integers. For each of them determine whether it is Π’-prime or not.
Input
The first line contains a single positive integer, n (1 β€ n β€ 105), showing how many numbers are in the array. The next line contains n space-separated integers xi (1 β€ xi β€ 1012).
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is advised to use the cin, cout streams or the %I64d specifier.
Output
Print n lines: the i-th line should contain "YES" (without the quotes), if number xi is Π’-prime, and "NO" (without the quotes), if it isn't.
Examples
Input
3
4 5 6
Output
YES
NO
NO
Note
The given test has three numbers. The first number 4 has exactly three divisors β 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO".
Submitted Solution:
```
import math
n = int(input())
lis = list(map(int,input().split()))
for i in lis:
if(math.ceil(math.sqrt(i)) == math.floor(math.sqrt(i)) and i!=1):
print("YES")
else:
print("NO")
``` | instruction | 0 | 51,605 | 22 | 103,210 |
No | output | 1 | 51,605 | 22 | 103,211 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first line contains integer t (1 β€ t β€ 500) β the number of testscases.
Each of the following t lines of the input contains integer n (2 β€ n β€ 109).
Output
Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.
Examples
Input
2
2
3
Output
1/6
7/30 | instruction | 0 | 51,671 | 22 | 103,342 |
Tags: math, number theory
Correct Solution:
```
T = int( input() )
MAX = 33000
bePrime = [0] * MAX;
primNum = []
for j in range(2, MAX):
if bePrime[j] == 0:
primNum.append( j )
i = j
while i < MAX:
bePrime[i] = 1
i = i + j
def isPrime( a ):
for j in primNum:
if j >= a:
return True
if a % j == 0:
return False
return True
def gcd( a, b ):
if b == 0:
return a
return gcd( b, a % b );
while T > 0:
num = 0;
n = int( input() )
m = n
while isPrime(m) == False:
m -= 1
while isPrime(n + 1) == False:
n += 1
num += 1
a = n - 1
b = 2 * ( n+1 )
a = a * (n+1) * m - num * b
b = b * (n+1) * m
g = gcd( a, b)
a //= g
b //= g
print( '{0}/{1}'.format( a, b ) )
T -= 1;
``` | output | 1 | 51,671 | 22 | 103,343 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first line contains integer t (1 β€ t β€ 500) β the number of testscases.
Each of the following t lines of the input contains integer n (2 β€ n β€ 109).
Output
Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.
Examples
Input
2
2
3
Output
1/6
7/30 | instruction | 0 | 51,672 | 22 | 103,344 |
Tags: math, number theory
Correct Solution:
```
def prime(n):
m = int(n ** 0.5) + 1
t = [1] * (n + 1)
for i in range(3, m):
if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)
return [2] + [i for i in range(3, n + 1, 2) if t[i]]
def gcd(a, b):
c = a % b
return gcd(b, c) if c else b
p = prime(31650)
def g(n):
m = int(n ** 0.5)
for j in p:
if n % j == 0: return True
if j > m: return False
def f(n):
a, b = n, n + 1
while g(a): a -= 1
while g(b): b += 1
p, q = (b - 2) * a + 2 * (n - b + 1), 2 * a * b
d = gcd(p, q)
print(str(p // d) + '/' + str(q // d))
for i in range(int(input())): f(int(input()))
``` | output | 1 | 51,672 | 22 | 103,345 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Let's assume that
* v(n) is the largest prime number, that does not exceed n;
* u(n) is the smallest prime number strictly greater than n.
Find <image>.
Input
The first line contains integer t (1 β€ t β€ 500) β the number of testscases.
Each of the following t lines of the input contains integer n (2 β€ n β€ 109).
Output
Print t lines: the i-th of them must contain the answer to the i-th test as an irreducible fraction "p/q", where p, q are integers, q > 0.
Examples
Input
2
2
3
Output
1/6
7/30 | instruction | 0 | 51,673 | 22 | 103,346 |
Tags: math, number theory
Correct Solution:
```
T = int( input() )
#for every prime x
#(b-a)/ab
#1/a-1/b
MAX = 33000
bePrime = [0] * MAX;
primNum = []
for j in range(2, MAX):
if bePrime[j] == 0:
primNum.append( j )
i = j
while i < MAX:
bePrime[i] = 1
i = i + j
def isPrime( a ):
for j in primNum:
if j >= a:
return True
if a % j == 0:
return False
return True
def gcd( a, b ):
if b == 0:
return a
return gcd( b, a % b );
while T > 0:
num = 0;
n = int( input() )
m = n
while isPrime(m) == False:
m -= 1
while isPrime(n + 1) == False:
n += 1
num += 1
a = n - 1
b = 2 * ( n+1 )
a = a * (n+1) * m - num * b
b = b * (n+1) * m
g = gcd( a, b)
a //= g
b //= g
print( '{0}/{1}'.format( a, b ) )
T -= 1;
``` | output | 1 | 51,673 | 22 | 103,347 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,202 | 22 | 104,404 |
Tags: greedy, math, number theory
Correct Solution:
```
l, r = (int(x) for x in input().split())
answer = []
answer.append("YES")
for i in range(l, r + 1, 2):
pair = str(i) + " " + str(i + 1)
answer.append(pair)
print(*answer, sep='\n')
``` | output | 1 | 52,202 | 22 | 104,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,203 | 22 | 104,406 |
Tags: greedy, math, number theory
Correct Solution:
```
l,r = map(int,input().split())
print("YES")
for i in range(l,r+1,2):
print("{} {}".format(i,i+1))
``` | output | 1 | 52,203 | 22 | 104,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,204 | 22 | 104,408 |
Tags: greedy, math, number theory
Correct Solution:
```
p,s=map(int,input().split())
print('YES')
for i in range(p,s+1,2):
print(i,i+1)
``` | output | 1 | 52,204 | 22 | 104,409 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,205 | 22 | 104,410 |
Tags: greedy, math, number theory
Correct Solution:
```
#!/usr/bin/env python3
import sys
def rint():
return map(int, sys.stdin.readline().split())
#lines = stdin.readlines()
l, r = rint()
print("YES")
for i in range((r-l+1)//2):
print(l+2*i, l+2*i+1)
``` | output | 1 | 52,205 | 22 | 104,411 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,206 | 22 | 104,412 |
Tags: greedy, math, number theory
Correct Solution:
```
# ip=list(map(int,sys.stdin.readline().strip().split()))
import sys
a,b=list(map(int,sys.stdin.readline().strip().split()))
print("YES")
for i in range(a,b+1,2):
print(i,i+1)
``` | output | 1 | 52,206 | 22 | 104,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,207 | 22 | 104,414 |
Tags: greedy, math, number theory
Correct Solution:
```
a, b = [int(x) for x in input().split()]
print('YES')
for i in range(int((b-a+1)/2)):
x = a + i * 2
y = a + i * 2 + 1
print(f'{x} {y}')
``` | output | 1 | 52,207 | 22 | 104,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,208 | 22 | 104,416 |
Tags: greedy, math, number theory
Correct Solution:
```
a,b = map(int,input().split())
if (a-b+1)%2==0:
print('YES')
for i in range(a,b+1,2):
print(i,i+1)
else:
print('No')
``` | output | 1 | 52,208 | 22 | 104,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5 | instruction | 0 | 52,209 | 22 | 104,418 |
Tags: greedy, math, number theory
Correct Solution:
```
r,l=[int(i) for i in input().split()]
print("YES")
for i in range(r,l,2):
print(i,i+1)
``` | output | 1 | 52,209 | 22 | 104,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5
Submitted Solution:
```
'''
@author: neprostomaria
'''
def gcd(a, b):
while b:
a, b = b, a % b
return (a)
if __name__ == '__main__':
test = [int(x) for x in input().split()]
lst = list(range(test[0], test[1] + 1))
stop_flag = False
pair_num = int(len(lst)/2)
for index in range(pair_num):
if gcd(lst[len(lst) - 1 - index * 2], lst[len(lst) - 2 - index * 2]) != 1:
print("NO")
stop_flag = True
break
if not stop_flag:
print("YES")
for index in range(pair_num):
print(str(lst[len(lst) - 1 - index * 2]) + " " + str(lst[len(lst) - 2 - index * 2]))
``` | instruction | 0 | 52,210 | 22 | 104,420 |
Yes | output | 1 | 52,210 | 22 | 104,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5
Submitted Solution:
```
a=list(map(int,input().split()))
print("YES")
for i in range(a[0],a[1],2):
print(i,i+1)
``` | instruction | 0 | 52,211 | 22 | 104,422 |
Yes | output | 1 | 52,211 | 22 | 104,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5
Submitted Solution:
```
l, r = [int(x) for x in input().split()]
print("YES")
for x in range(l, r+1, 2):
print(x, x+1)
``` | instruction | 0 | 52,212 | 22 | 104,424 |
Yes | output | 1 | 52,212 | 22 | 104,425 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5
Submitted Solution:
```
from math import gcd
a, b = map(int, input().split())
print("YES")
for i in range (a, b + 1, 2):
print (i, i + 1)
``` | instruction | 0 | 52,213 | 22 | 104,426 |
Yes | output | 1 | 52,213 | 22 | 104,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a set of all integers from l to r inclusive, l < r, (r - l + 1) β€ 3 β
10^5 and (r - l) is always odd.
You want to split these numbers into exactly (r - l + 1)/(2) pairs in such a way that for each pair (i, j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.
Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.
Input
The only line contains two integers l and r (1 β€ l < r β€ 10^{18}, r - l + 1 β€ 3 β
10^5, (r - l) is odd).
Output
If any solution exists, print "YES" in the first line. Each of the next (r - l + 1)/(2) lines should contain some pair of integers. GCD of numbers in each pair should be equal to 1. All (r - l + 1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print "NO".
Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5
Submitted Solution:
```
l, r = map(int, input().split())
for i in range((r - l + 1) // 2):
print(l + 2*i, l + 2*i + 1)
``` | instruction | 0 | 52,214 | 22 | 104,428 |
No | output | 1 | 52,214 | 22 | 104,429 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.