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.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4 | instruction | 0 | 79,241 | 22 | 158,482 |
Tags: implementation, math
Correct Solution:
```
def gcd(a, b):
return b if a == 0 else gcd(b % a, a)
n = int(input())
a = list(map(int, input().split()))
g = a[0]
for i in range(1, n):
g = gcd(g , a[i])
ans = 0
i = 1
while i*i <= g:
if g % i == 0:
ans += 1
if i != g // i: ans += 1
i += 1
print(ans)
``` | output | 1 | 79,241 | 22 | 158,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4 | instruction | 0 | 79,242 | 22 | 158,484 |
Tags: implementation, math
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
a=list(set(a))
def find_gcd(x, y):
while(y):
x, y = y, x % y
return x
z=len(a)
if z==1:
if a[0]==1:
print(1)
else:
c=2
p=2
while p*p<=a[0]:
if p*p==a[0]:
c+=1
elif a[0]%p==0:
c+=2
p+=1
print(c)
else:
num1 = a[0]
num2 = a[1]
gcd = find_gcd(num1, num2)
for i in range(2, len(a)):
gcd = find_gcd(gcd, a[i])
if gcd==1:
print(1)
else:
m=min(a)
st=set([1,m])
c=2
p=2
while p*p<=gcd:
if p*p==gcd:
c=c+1
elif gcd%p==0:
c+=2
p+=1
print(c)
``` | output | 1 | 79,242 | 22 | 158,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
import sys
input = sys.stdin.readline
import math
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
n = int(input())
a = list(map(int, input().split()))
b = a[0]
for i in range(1, n):
b = math.gcd(b, a[i])
print(len(make_divisors(b)))
``` | instruction | 0 | 79,243 | 22 | 158,486 |
Yes | output | 1 | 79,243 | 22 | 158,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
from math import sqrt
def gcd(a,b):
if b== 0:
return a
else:
return gcd(b,a%b)
n = int(input())
numeros = list(map(int,input().split()))
anterior = numeros[0]
for i in range(1,n):
anterior = gcd(max(anterior, numeros[i]), min(anterior,numeros[i]))
ans = 0
i = 1
contador = 0
while i * i < anterior:
if anterior % i == 0:
contador += 2
i += 1
if i*i == anterior:
contador += 1
print(contador)
``` | instruction | 0 | 79,244 | 22 | 158,488 |
Yes | output | 1 | 79,244 | 22 | 158,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
from math import gcd
n=int(input())
a=list(map(int,input().split()))
g=a[0]
for i in range(1,n):
g=gcd(g,a[i])
if g>1:
c=2
i=2
while i*i<g:
if g%i==0:
c+=2
i+=1
if i*i==g:
c+=1
print(c)
else:
print(1)
``` | instruction | 0 | 79,245 | 22 | 158,490 |
Yes | output | 1 | 79,245 | 22 | 158,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
def nod(x,y):
while x > 0 and y > 0:
if x > y:
x = x % y
else:
y = y % x
return(x + y)
n = int(input())
a = [int(x) for x in input().split()]
b = min(a)
for i in range(n):
x = a[i]
y = b
b = nod(x,y)
k = 1
if b == 1:
print(k)
else:
k = 2
m = int(b ** 0.5)
while m > 1:
if b % m == 0:
if b // m == m:
k +=1
else:
k += 2
m -= 1
print(k)
``` | instruction | 0 | 79,246 | 22 | 158,492 |
Yes | output | 1 | 79,246 | 22 | 158,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
a = int(input())
t = list(map(int,input().split()))
u=t[0]
import math
for j in range(a):
u=math.gcd(u,t[j])
s=0
for k in range(1,int(u**0.5)+2):
if u%k==0:
s+=1
print(s+1)
``` | instruction | 0 | 79,247 | 22 | 158,494 |
No | output | 1 | 79,247 | 22 | 158,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
import math
def gcd (a,b):
if b==0:
return a
return gcd(b,a%b)
t=int(input())
s=input()
list=s.split()
for i in range(len(list)):
list[i]=int(list[i])
ans=gcd(list[0],list[1])
for i in range(1,len(list)):
ans=gcd(ans,list[i])
num=0
for i in range(1,math.ceil(math.sqrt(ans))):
if(ans%i==0):
num+=2
if(math.sqrt(ans)*math.sqrt(ans)==ans):
num+=1
print(num)
``` | instruction | 0 | 79,248 | 22 | 158,496 |
No | output | 1 | 79,248 | 22 | 158,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
from math import gcd
from sys import stdin
n = int(input())
a = list(map(int,stdin.readline().split()))
g = gcd(a[0],a[min(1,n-1)])
for i in range(2,n):
g = gcd(g,a[i])
if g == 1:
print(1)
else:
ans = 0
for i in range(1,int(g**0.5)+1):
if g % i == 0:
ans += 2
print(ans)
``` | instruction | 0 | 79,249 | 22 | 158,498 |
No | output | 1 | 79,249 | 22 | 158,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given an array a consisting of n integers.
Your task is to say the number of such positive integers x such that x divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array.
For example, if the array a will be [2, 4, 6, 2, 10], then 1 and 2 divide each number from the array (so the answer for this test is 2).
Input
The first line of the input contains one integer n (1 β€ n β€ 4 β
10^5) β the number of elements in a.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^{12}), where a_i is the i-th element of a.
Output
Print one integer β the number of such positive integers x such that x divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array).
Examples
Input
5
1 2 3 4 5
Output
1
Input
6
6 90 12 18 30 18
Output
4
Submitted Solution:
```
from sys import *
from math import *
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
a.sort()
b=[]
for i in range(1,int(sqrt(a[0]))+1):
if a[0]%i==0:
b.append(i)
b.append(a[0]//i)
b.sort()
for i in range(1,len(b)):
if b[i]==b[i-1]:
b[i]=-1
s=sum(a)
ans=0
for i in range(len(b)):
if b[i]!=-1:
if s%b[i]==0:
ans+=1
print(ans)
``` | instruction | 0 | 79,250 | 22 | 158,500 |
No | output | 1 | 79,250 | 22 | 158,501 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is n and its coefficients are integers not exceeding k by the absolute value. More formally:
Let a0, a1, ..., an denote the coefficients, so <image>. Then, a polynomial P(x) is valid if all the following conditions are satisfied:
* ai is integer for every i;
* |ai| β€ k for every i;
* an β 0.
Limak has recently got a valid polynomial P with coefficients a0, a1, a2, ..., an. He noticed that P(2) β 0 and he wants to change it. He is going to change one coefficient to get a valid polynomial Q of degree n that Q(2) = 0. Count the number of ways to do so. You should count two ways as a distinct if coefficients of target polynoms differ.
Input
The first line contains two integers n and k (1 β€ n β€ 200 000, 1 β€ k β€ 109) β the degree of the polynomial and the limit for absolute values of coefficients.
The second line contains n + 1 integers a0, a1, ..., an (|ai| β€ k, an β 0) β describing a valid polynomial <image>. It's guaranteed that P(2) β 0.
Output
Print the number of ways to change one coefficient to get a valid polynomial Q that Q(2) = 0.
Examples
Input
3 1000000000
10 -9 -3 5
Output
3
Input
3 12
10 -9 -3 5
Output
2
Input
2 20
14 -7 19
Output
0
Note
In the first sample, we are given a polynomial P(x) = 10 - 9x - 3x2 + 5x3.
Limak can change one coefficient in three ways:
1. He can set a0 = - 10. Then he would get Q(x) = - 10 - 9x - 3x2 + 5x3 and indeed Q(2) = - 10 - 18 - 12 + 40 = 0.
2. Or he can set a2 = - 8. Then Q(x) = 10 - 9x - 8x2 + 5x3 and indeed Q(2) = 10 - 18 - 32 + 40 = 0.
3. Or he can set a1 = - 19. Then Q(x) = 10 - 19x - 3x2 + 5x3 and indeed Q(2) = 10 - 38 - 12 + 40 = 0.
In the second sample, we are given the same polynomial. This time though, k is equal to 12 instead of 109. Two first of ways listed above are still valid but in the third way we would get |a1| > k what is not allowed. Thus, the answer is 2 this time. | instruction | 0 | 79,579 | 22 | 159,158 |
Tags: hashing, implementation, math
Correct Solution:
```
def convert_to_binary(coef):
res = []
n = len(coef)
carry = 0
i = 0
while i < n + 1000:
if i >= n and not carry:
break
cur = carry
if i < n:
cur += coef[i]
mod = cur % 2
div = cur // 2
# print(cur, div, mod)
res.append(mod)
carry = div
i += 1
return res, carry
n, k = map(int, input().split())
coef = list(map(int, input().split()))
b, carry = convert_to_binary(coef)
ref = False
if carry < 0:
b, carry = convert_to_binary(list(map(lambda x: -x, coef)))
ref = True
last = len(b) - 1
while b[last] != 1:
last -= 1
ans = 0
for i in range(0, n + 1):
if last - i > 40:
continue
cur = 0
for j in range(i, last + 1):
cur += b[j] * (2 ** (j - i))
new_coef = coef[i] - cur
if ref:
new_coef = coef[i] + cur
if abs(new_coef) > k:
if b[i] == 1:
break
continue
if i == n and new_coef == 0:
if b[i] == 1:
break
continue
ans += 1
if b[i] == 1:
break
print(ans)
``` | output | 1 | 79,579 | 22 | 159,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After playing with her beautiful array, Mishka decided to learn some math. After learning how to multiply, divide and what is divisibility, she is now interested in solving the following problem.
You are given integer k and array a1, a2, ..., an of n integers. You are to find non-empty subsequence of array elements such that the product of its elements is divisible by k and it contains minimum possible number of elements.
Formally, you are to find a sequence of indices 1 β€ i1 < i2 < ... < im β€ n such that <image> is divisible by k while m is minimum possible among all such variants.
If there are more than one such subsequences, you should choose one among them, such that sum of its elements is minimum possible.
Mishka quickly solved this problem. Will you do so?
Input
The first line of the input contains two integers n and k (1 β€ n β€ 1 000, 1 β€ k β€ 1012).
The second line of the input contains n integers a1, a2, ..., an (1 β€ ai β€ 1012) β array elements.
Output
Print single positive integer m in the first line β the number of elements in desired sequence.
In the second line print m distinct integers β the sequence of indices of given array elements, which should be taken into the desired sequence.
If there are more than one such subsequence (e.g. subsequence of minimum possible number of elements and with minimum possible sum of elements), you can print any of them.
If there are no such subsequences, print - 1 in the only line.
Example
Input
5 60
2 4 6 5 2
Output
3
4 3 1
Submitted Solution:
```
import sys
input = sys.stdin.readline
def gcd(a, b):
return a if b == 0 else gcd(b, a % b)
MSZ = 41
n, k = map(int, input().split())
seq = [(i, gcd(int(v), k)) for i, v in enumerate(input().split(), start=1)]
seq.sort(reverse=True)
seq = [1] + seq
MSZ = min(MSZ, n + 1)
dp = [[1] * MSZ for _ in range(n + 1)]
par = [[-1] * MSZ for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, MSZ):
dp[i][j] = dp[i - 1][j]
par[i][j] = (i - 1, j)
alt = gcd(dp[i - 1][j - 1] * seq[i][1], k)
if alt > dp[i][j]:
dp[i][j] = alt
par[i][j] = (i - 1, j - 1)
# print(f'i={i}, j={j}, dpv={dp[i][j]}')
best = 1000000000
besti = -1
for i in range(1, n + 1):
for j in range(1, MSZ):
if dp[i][j] == k:
best = min(best, j)
besti = i
if best == 1000000000:
print(-1)
else:
print(best)
# backtrack
ans = []
curi = besti
curj = best
while curi > 0 and curj > 0:
pari, parj = par[curi][curj]
if parj < curj:
ans.append(seq[curi][0])
curi = pari
curj = parj
ans.sort()
print(' '.join(map(str, ans)))
``` | instruction | 0 | 79,600 | 22 | 159,200 |
No | output | 1 | 79,600 | 22 | 159,201 |
Provide a correct Python 3 solution for this coding contest problem.
Rational numbers are numbers represented by ratios of two integers. For a prime number p, one of the elementary theorems in the number theory is that there is no rational number equal to βp. Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to βp
Now, given a positive integer n, we define a set Qn of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to n. For example, Q4 is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively.
Your job is to write a program that reads two integers p and n and reports two rational numbers x / y and u / v, where u / v < βp < x / y and there are no other elements of Qn between u/v and x/y. When n is greater than βp, such a pair of rational numbers always exists.
Input
The input consists of lines each of which contains two positive integers, a prime number p and an integer n in the following format.
p n
They are separated by a space character. You can assume that p and n are less than 10000, and that n is greater than βp. The end of the input is indicated by a line consisting of two zeros.
Output
For each input line, your program should output a line consisting of the two rational numbers x / y and u / v (x / y > u / v) separated by a space character in the following format.
x/y u/v
They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively.
Example
Input
2 5
3 10
5 100
0 0
Output
3/2 4/3
7/4 5/3
85/38 38/17 | instruction | 0 | 79,871 | 22 | 159,742 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def stern_brocot(p, n):
la = 0; lb = 1
ra = 1; rb = 0
lu = ru = 1
lx = 0; ly = 1
rx = 1; ry = 0
while lu or ru:
ma = la + ra; mb = lb + rb
if p * mb**2 < ma**2:
ra = ma; rb = mb
if ma <= n and mb <= n:
rx = ma; ry = mb
else:
lu = 0
else:
la = ma; lb = mb
if ma <= n and mb <= n:
lx = ma; ly = mb
else:
ru = 0
return lx, ly, rx, ry
while 1:
p, n = map(int, readline().split())
if p == 0:
break
lx, ly, rx, ry = stern_brocot(p, n)
write("%d/%d %d/%d\n" % (rx, ry, lx, ly))
``` | output | 1 | 79,871 | 22 | 159,743 |
Provide a correct Python 3 solution for this coding contest problem.
Rational numbers are numbers represented by ratios of two integers. For a prime number p, one of the elementary theorems in the number theory is that there is no rational number equal to βp. Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to βp
Now, given a positive integer n, we define a set Qn of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to n. For example, Q4 is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively.
Your job is to write a program that reads two integers p and n and reports two rational numbers x / y and u / v, where u / v < βp < x / y and there are no other elements of Qn between u/v and x/y. When n is greater than βp, such a pair of rational numbers always exists.
Input
The input consists of lines each of which contains two positive integers, a prime number p and an integer n in the following format.
p n
They are separated by a space character. You can assume that p and n are less than 10000, and that n is greater than βp. The end of the input is indicated by a line consisting of two zeros.
Output
For each input line, your program should output a line consisting of the two rational numbers x / y and u / v (x / y > u / v) separated by a space character in the following format.
x/y u/v
They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively.
Example
Input
2 5
3 10
5 100
0 0
Output
3/2 4/3
7/4 5/3
85/38 38/17 | instruction | 0 | 79,872 | 22 | 159,744 |
"Correct Solution:
```
# AOJ 1208
import sys
import math
def rational(p, n):
rt = math.sqrt(p)
k = math.floor(rt)
mi = n
mx = n
mikk = 0
mibb = 0
mxkk = 0
mxbb = 0
for i in range(1, n+1):
a = (rt - k) * i
b = math.floor(a)
if mi > a - b and k * i + b <= n:
mi = a - b
mikk = i
mibb = b
if mx > b + 1 - a and k * i + (b + 1) <= n:
mx = b + 1 - a
mxkk = i
mxbb = b
print("{}/{} {}/{}".format(k * mxkk + (mxbb + 1), mxkk, k * mikk + mibb, mikk))
while True:
line = input().split()
p, n = map(int, list(line))
if p == 0 and n == 0:
break
rational(p, n)
``` | output | 1 | 79,872 | 22 | 159,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,921 | 22 | 159,842 |
Tags: interactive, math, number theory
Correct Solution:
```
import math
n=int(input())
factordict={}
superfactors={}
inputs=[]
for i in range(n):
inputs.append(int(input()))
for guy in inputs:
if guy==round(guy**0.5)**2:
if guy==round(guy**0.25)**4:
a=round(guy**0.25)
if a in factordict:
factordict[a]+=4
else:
factordict[a]=4
else:
a=round(guy**0.5)
if a in factordict:
factordict[a]+=2
else:
factordict[a]=2
elif guy==round(guy**(1/3))**3:
a=round(guy**(1/3))
if a in factordict:
factordict[a]+=3
else:
factordict[a]=3
else:
j=0
for guy2 in inputs:
b=math.gcd(guy,guy2)
if b>1 and not guy==guy2:
if b in factordict:
factordict[b]+=1
else:
factordict[b]=1
if guy//b in factordict:
factordict[guy//b]+=1
else:
factordict[guy//b]=1
j=1
break
if j==0:
if guy in superfactors:
superfactors[guy]+=1
else:
superfactors[guy]=1
prod=1
for guy in factordict:
prod*=(factordict[guy]+1)
prod=prod%998244353
for guy in superfactors:
prod*=(superfactors[guy]+1)**2
prod=prod%998244353
print(prod)
``` | output | 1 | 79,921 | 22 | 159,843 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,922 | 22 | 159,844 |
Tags: interactive, math, number theory
Correct Solution:
```
def gcd(a, b):
if a > b:
a, b = b, a
if b % a==0:
return a
return gcd(b % a, a)
def process(A):
d = {}
other = []
for n in A:
is_fourth = False
is_cube = False
is_square = False
n4 = int(n**0.25)
if n4**4==n:
if (n4, 0) not in d:
d[(n4,0)] = 0
d[(n4, 0)]+=4
is_fourth = True
if not is_fourth:
n3 = int(n**(1/3))
if n3**3==n or (n3+1)**3==n or (n3-1)**3==n:
if (n3+1)**3==n:
n3+=1
elif (n3-1)**3==n:
n3-=1
if (n3, 0) not in d:
d[(n3, 0)] = 0
d[(n3, 0)]+=3
is_cube = True
if not is_cube:
n2 = int(n**0.5)
if n2**2==n:
if (n2, 0) not in d:
d[(n2, 0)]=0
d[(n2, 0)]+=2
is_square = True
if not is_square:
other.append(n)
# print(d, other)
for x in other:
x_break = set([])
to_remove = {}
broken = False
for y in d:
g = gcd(x, y[0])
if g != 1:
if y[1]==0:
broken = True
p1 = x//g
p2 = g
x_break.add(p1)
x_break.add(p2)
elif x != y[0]:
broken = True
p1 = x//g
p2 = g
p3 = y[0]//g
to_remove[y] = [p2, p3]
x_break.add(p1)
x_break.add(p2)
# print(x_break, to_remove, broken)
if not broken:
if (x, 1) not in d:
d[(x, 1)] = 0
d[(x, 1)]+=1
else:
for y in to_remove:
R = d[y]
d.pop(y)
a, b= to_remove[y]
if (a, 0) not in d:
d[(a, 0)] = 0
if (b, 0) not in d:
d[(b, 0)] = 0
d[(a, 0)]+=R
d[(b, 0)]+=R
for a in x_break:
if (a, 0) not in d:
d[(a, 0)] = 0
d[(a, 0)]+=1
answer = 1
# print(d)
for x in d:
if x[1]==0:
answer = answer*(d[x]+1)
answer = answer % 998244353
else:
answer = answer*(d[x]+1)**2
answer = answer % 998244353
return answer
n = int(input())
A = []
for i in range(n):
m = int(input())
A.append(m)
print(process(A))
``` | output | 1 | 79,922 | 22 | 159,845 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,923 | 22 | 159,846 |
Tags: interactive, math, number theory
Correct Solution:
```
mod=998244353
dic={}
def gcd(a,b):
if (b==0):
return a
return gcd(b,a%b)
def adddic(key,i):
if key in dic.keys():
dic[key]+=i
else:
dic[key]=i
n=int(input())
l=[[int(input()),0] for i in range(n)]
l.sort()
for p in l:
a,b,c=int(p[0]**(1/2)),int(p[0]**(1/3)),int(p[0]**(1/4))
a=max(a,2)
b=max(b,2)
c=max(c,2)
if p[0]==(c-1)**4 or p[0]==c**4 or p[0]==(c+1)**4:
if p[0]%c==0:
pass
elif p[0]%(c-1)==0:
c=c-1
elif p[0]%(c+1)==0:
c=c+1
adddic(c,4)
p[0]=1
p[1]=1
elif p[0]==(b-1)**3 or p[0]==b**3 or p[0]==(b+1)**3:
if p[0]%b==0:
pass
elif p[0]%(b-1)==0:
b=b-1
elif p[0]%(b+1)==0:
b=b+1
adddic(b,3)
p[0]=1
p[1]=1
elif p[0]==(a-1)**2 or p[0]==a**2 or p[0]==(a+1)**2:
if p[0]%a==0:
pass
elif p[0]%(a-1)==0:
a=a-1
elif p[0]%(a+1)==0:
a=a+1
adddic(a,2)
p[0]=1
p[1]=1
for i in range(n):
for j in dic.keys():
if l[i][0]%j==0:
dic[j]+=1
adddic(l[i][0]//j,1)
l[i][0]=1
l[i][1]=1
break
for i in range(n-1):
for j in range(n-1,i,-1):
if l[i][1]==1 or l[j][1]==1:
continue
if l[i][0]==l[j][0]:
continue
g=gcd(l[i][0],l[j][0])
if 1<g<l[i][0]:
buf=[g]
while len(buf)>0:
h=buf.pop()
for k in range(n):
if l[k][0]%h==0:
adddic(h,1)
adddic(l[k][0]//h,1)
buf.append(l[k][0]//h)
l[k][0]=1
l[k][1]=1
dic2={}
for p in l:
if p[0]==1:
continue
if p[0] in dic2.keys():
dic2[p[0]]+=1
else:
dic2[p[0]]=1
res=1
for k in dic2.keys():
res*=dic2[k]+1
res%=mod
res*=dic2[k]+1
res%=mod
for k in dic.keys():
res*=dic[k]+1
res%=mod
print(res)
``` | output | 1 | 79,923 | 22 | 159,847 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,924 | 22 | 159,848 |
Tags: interactive, math, number theory
Correct Solution:
```
import math
import sys
from decimal import Decimal
n=int(input())
d={}
f={}
s=set()
for j in range(n):
i=int(input())
f.setdefault(i,0)
f[i]+=1
x=i**.25
x=int(x)
y=i**.5
y=int(y)
if x**4==i:
d.setdefault(x,0)
d[x]+=4
elif y*y==i:
x=int(i**.5)
d.setdefault(x, 0)
d[x] += 2
elif int(i**(1./3)) ** 3 == i:
x=int(math.pow(i,1/3))
d.setdefault(x,0)
d[x]+=3
elif (1+int(i**(1./3))) ** 3 == i:
x=int(math.pow(i,1/3))+1
d.setdefault(x,0)
d[x]+=3
else:
s.add(i)
rem=set()
# print(d)
# print(s)
for i in s:
if i in rem:
continue
for j in s:
if i==j:
continue
if math.gcd(i,j)!=1:
a,b,c=math.gcd(i,j),i//math.gcd(i,j),j//math.gcd(i,j)
d.setdefault(a,0)
d.setdefault(b,0)
d.setdefault(c,0)
d[a]+=f[i]
d[b]+=f[i]
if j not in rem:
d[c]+=f[j]
d[a]+=f[j]
rem.add(i)
rem.add(j)
break
for i in s:
if i in rem:
continue
for j in d:
if i%j==0:
d[j]+=f[i]
d.setdefault(i//j,0)
d[i//j]+=f[i]
rem.add(i)
break
k=-1
for i in s:
if i not in rem:
d[k]=f[i]
k-=1
d[k]=f[i]
k-=1
ans=1
#print(rem,d)
for k in d:
ans*=d[k]+1
ans=ans%998244353
print(ans)
sys.stdout.flush()
``` | output | 1 | 79,924 | 22 | 159,849 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,925 | 22 | 159,850 |
Tags: interactive, math, number theory
Correct Solution:
```
import math
mod = 998244353
n = int(input())
a = []
for _ in range(n):
x = int(input())
a.append(x)
def sieve(n):
composite = [False] * n
primes = []
for i in range(2, n):
if not composite[i]:
primes.append(i)
for j in range(i * i, n, i):
composite[j] = True
return primes, composite
primes, composite = sieve(1000010)
def is_prime(x):
if x < 2:
return False
if x < len(composite):
return not composite[x]
for y in primes:
if y * y > x:
break
if x % y == 0:
return False
return True
def cubic_root(x):
y = (int) (x ** (1. / 3))
while y ** 3 < x:
y += 1
while y ** 3 > x:
y -= 1
return y
def square_root(x):
y = (int) (x ** (1. / 2))
while y ** 2 < x:
y += 1
while y ** 2 > x:
y -= 1
return y
def fourth_root(x):
y = (int) (x ** (1. / 4))
while y ** 4 < x:
y += 1
while y ** 4 > x:
y -= 1
return y
prime_map = {}
int_map = {}
ans = 1
def shared_gcd(x):
for y in a:
if math.gcd(x, y) > 1 and math.gcd(x, y) < x:
return math.gcd(x, y)
return 1
for x in a:
x_sqrt = square_root(x)
if x_sqrt ** 2 == x and is_prime(x_sqrt):
prime_map[x_sqrt] = prime_map.get(x_sqrt, 0) + 2
else:
x_cubic = cubic_root(x)
if x_cubic ** 3 == x and is_prime(x_cubic):
prime_map[x_cubic] = prime_map.get(x_cubic, 0) + 3
else:
x_fourth = fourth_root(x)
if x_fourth ** 4 == x and is_prime(x_fourth):
prime_map[x_fourth] = prime_map.get(x_fourth, 0) + 4
else:
p = shared_gcd(x)
if p > 1:
q = x // p
assert p * q == x
prime_map[p] = prime_map.get(p, 0) + 1
prime_map[q] = prime_map.get(q, 0) + 1
else:
int_map[x] = int_map.get(x, 0) + 1
ans = 1
for _, count in prime_map.items():
ans *= (count + 1)
ans %= mod
for _, count in int_map.items():
ans *= (count + 1) * (count + 1)
ans %= mod
print(ans)
``` | output | 1 | 79,925 | 22 | 159,851 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,926 | 22 | 159,852 |
Tags: interactive, math, number theory
Correct Solution:
```
from math import gcd
from collections import Counter
n = int(input())
a_is = []
pqs = []
ps = Counter()
for i in range(n):
a_i = int(input())
a_is.append(a_i)
p = round(a_i ** (1 / 2))
if p ** 2 == a_i:
d = round(p ** (1 / 2))
if d ** 4 == a_i:
ps[d] += 4
else:
ps[p] += 2
continue
p = round(a_i ** (1 / 3))
if p ** 3 == a_i:
ps[p] += 3
else:
pqs.append(a_i)
outliers = Counter()
for pq in pqs:
for a_i in a_is:
g = gcd(pq , a_i)
if g != 1 and a_i != pq:
ps[g] += 1
ps[pq // g] += 1
break
# pq is coprime with every a_i that is
# different from pq.
else:
outliers[pq] += 1
pi = 1
MOD = 998244353
for p in ps.values():
pi = pi * (p + 1) % MOD
for p in outliers.values():
pi = pi * (p + 1) ** 2 % MOD
print(pi)
``` | output | 1 | 79,926 | 22 | 159,853 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,927 | 22 | 159,854 |
Tags: interactive, math, number theory
Correct Solution:
```
import math
import sys
from decimal import Decimal
n=int(input())
d={}
f={}
s=set()
for j in range(n):
i=int(input())
f.setdefault(i,0)
f[i]+=1
x=i**.25
x=int(x)
y=i**.5
y=int(y)
if x**4==i:
d.setdefault(x,0)
d[x]+=4
elif y*y==i:
x=int(i**.5)
d.setdefault(x, 0)
d[x] += 2
elif int(i**(1./3)) ** 3 == i:
x=int(math.pow(i,1/3))
d.setdefault(x,0)
d[x]+=3
elif (1+int(i**(1./3))) ** 3 == i:
x=int(math.pow(i,1/3))+1
d.setdefault(x,0)
d[x]+=3
elif (int(i**(1./3))-1) ** 3 == i:
x=int(math.pow(i,1/3))-1
d.setdefault(x,0)
d[x]+=3
else:
s.add(i)
rem=set()
# print(d)
# print(s)
for i in s:
if i in rem:
continue
for j in s:
if i==j:
continue
if math.gcd(i,j)!=1:
a,b,c=math.gcd(i,j),i//math.gcd(i,j),j//math.gcd(i,j)
d.setdefault(a,0)
d.setdefault(b,0)
d.setdefault(c,0)
d[a]+=f[i]
d[b]+=f[i]
if j not in rem:
d[c]+=f[j]
d[a]+=f[j]
rem.add(i)
rem.add(j)
break
for i in s:
if i in rem:
continue
for j in d:
if i%j==0:
d[j]+=f[i]
d.setdefault(i//j,0)
d[i//j]+=f[i]
rem.add(i)
break
k=-1
for i in s:
if i not in rem:
d[k]=f[i]
k-=1
d[k]=f[i]
k-=1
ans=1
#print(rem,d)
for k in d:
ans*=d[k]+1
ans=ans%998244353
print(ans)
sys.stdout.flush()
``` | output | 1 | 79,927 | 22 | 159,855 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10. | instruction | 0 | 79,928 | 22 | 159,856 |
Tags: interactive, math, number theory
Correct Solution:
```
from sys import stdin
from collections import Counter
from math import sqrt, gcd
def is_prime(n):
d = 2
while d * d <= n:
if n % d == 0:
return False
d += 1
return n > 1
def prime_factorize(n):
if n in (0, 1):
return []
fact = []
while n > 1:
i = 2
while i <= n:
if n % i == 0:
break
i += 1
# finding exponent
e = 1
while n % i == 0:
n //= i
e += 1
if e - 1 > 1:
fact.append((i, e - 1))
return fact
elif e - 1 == 1:
fact.append((i, e - 1))
fact.append((n, 1))
return fact
def f(n):
if int(sqrt(n))**2 == n:
if int(sqrt(int(sqrt(n))))**4 == n:
return 4, int(sqrt(int(sqrt(n))))
else:
return 2, int(sqrt(n))
elif round(n**(1/3))**3 == n:
return 3, round(n**(1/3))
else:
return None, None
t = int(input())
pf = Counter()
a = []
for _ in range(t):
n, = map(int, stdin.readline().split())
a.append(n)
ans = 1
spec = Counter()
for i in range(t):
other = a[:i] + a[i + 1:]
e, p = f(a[i])
if e == None:
z = True
for j in other:
if gcd(j, a[i]) != 1 and j != a[i]:
z = False
k = gcd(j, a[i])
pf[k] += 1
pf[a[i]//k] += 1
break
if z:
spec[a[i]] += 1
else:
pf[p] += e
for i in pf.values():
ans = ((i + 1)*ans) % 998244353
for i in spec.values():
ans = ((i + 1)**2)*ans % 998244353
print (ans % 998244353 )
``` | output | 1 | 79,928 | 22 | 159,857 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
from math import gcd
from collections import Counter
# n -> cantidad de numeros que tiene la entrada
n = int(input())
# a_is -> lista donde se guardaran los valores (a_i)
# que pasen.
a_is = []
# pqs -> lista donde se guardaran los numeros que
# sean de la forma p * q, con p y q primos.
pqs = []
# ps -> contador que contendra los primos que
# participan en la factorizacion de los a_i
# y cuantas veces se repiten
ps = Counter()
# Se realiza este for para ir leyendo cada a_i
# y se aprovecha para realizar las demas operaciones.
for i in range(n):
a_i = int(input())
a_is.append(a_i)
# Se comprueba que el a_i sea de la forma p ^ 2 o p ^ 4
p = round(a_i ** (1 / 2))
if p ** 2 == a_i:
# Se comprueba si es especificamente de la forma p ^ 4
d = round(p ** (1 / 2))
if d ** 4 == a_i:
ps[d] += 4
# se comprueba si es especificamente de la forma p ^ 2
else:
ps[p] += 2
continue
# se comprueba si tiene la forma p ^ 3
p = round(a_i ** (1 / 3))
if p ** 3 == a_i:
ps[p] += 3
# si no tiene ninguna de estas formas, es de la forma p * q
else:
# se agrega a la lista de numeros con forma p * q
pqs.append(a_i)
# outliers -> un contador para guardar todos los a_i que son de forma p * q y primos relativos con todos los a_j, con a_i distinto de a_j
outliers = Counter()
for pq in pqs:
for a_i in a_is:
g = gcd(pq , a_i)
if g != 1 and a_i != pq:
ps[g] += 1
ps[pq // g] += 1
break
else:
outliers[pq] += 1
# total -> entero para calcular el total de divisores
total = 1
MOD = 998244353
for p in ps.values():
total = total * (p + 1) % MOD
for p in outliers.values():
total = total * (p + 1) ** 2 % MOD
print(total)
``` | instruction | 0 | 79,929 | 22 | 159,858 |
Yes | output | 1 | 79,929 | 22 | 159,859 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
from math import gcd
def divisors(n, a):
d = {}
bad = []
for i in range(n):
c = a[i]
if (int(c ** 0.25 + 0.0001)) ** 4 == c:
p = int(c ** 0.25 + 0.0001)
if p not in d:
d[p] = 4
else:
d[p] += 4
elif (int(c ** (1 / 3) + 0.0001)) ** 3 == c:
p = int(c ** (1 / 3) + 0.0001)
if p not in d:
d[p] = 3
else:
d[p] += 3
elif (int(c ** 0.5 + 0.001)) ** 2 == c:
p = int(c ** 0.5 + 0.0001)
if p not in d:
d[p] = 2
else:
d[p] += 2
else:
bad.append(c)
skipped = {}
for i in range(len(bad)):
for j in range(len(a)):
g = gcd(bad[i], a[j])
if (bad[i] == a[j]) or (g == 1):
continue
else:
if g not in d:
d[g] = 1
else:
d[g] += 1
if (bad[i] // g) not in d:
d[bad[i] // g] = 1
else:
d[bad[i] // g] += 1
break
else:
if bad[i] not in skipped:
skipped[bad[i]] = 1
else:
skipped[bad[i]] += 1
ans = 1
MOD = 998244353
for i in d:
ans = ans * (d[i] + 1) % MOD
for i in skipped:
ans = ans * (skipped[i] + 1) ** 2 % MOD
return ans
if __name__ == "__main__":
n = int(input())
a = [int(input()) for i in range(n)]
result = divisors(n, a)
print(result)
``` | instruction | 0 | 79,930 | 22 | 159,860 |
Yes | output | 1 | 79,930 | 22 | 159,861 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
import sys
import math
import collections
import heapq
import decimal
input=sys.stdin.readline
n=int(input())
mod=998244353
l=[]
f=[]
d=collections.Counter()
for i in range(n):
a=int(input())
l.append(a)
k=round(a**(1/2))
if(k*k==a):
k1=round(k**(1/2))
if(k1*k1*k1*k1==a):
d[k1]+=4
else:
d[k]+=2
continue
k=round(a**(1/3))
if(k*k*k==a):
d[k]+=3
else:
f.append(a)
d1=collections.Counter()
for i in f:
for j in l:
g=math.gcd(i,j)
if(g!=1 and j!=i):
d[g]+=1
d[i//g]+=1
break
else:
d1[i]+=1
prod=1
for i in d.values():
prod=(prod*(i+1))%mod
for i in d1.values():
prod=prod*(i+1)**2%mod
print(prod)
``` | instruction | 0 | 79,931 | 22 | 159,862 |
Yes | output | 1 | 79,931 | 22 | 159,863 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
from sys import stdout
ppp=998244353
n=int(input())
numbers=[int(input()) for i in range(n)]
def gcd(x,y):
x,y=max(x,y),min(x,y)
while y>0:
x=x%y
x,y=y,x
return x
def ssqr(x,k):
if x==1: return 1
l,r=1,x
while r-l>1:
m=(r+l)//2
q=m**k
if q==x: return m
elif q<x: l=m
else: r=m
return -1
pr=dict()
non_pr=dict()
def razl(i,gde):
x=gde[i]
k2=ssqr(x,4)
if k2!=-1: return [k2,k2,k2,k2]
k2=ssqr(x,3)
if k2!=-1: return [k2,k2,k2]
k2=ssqr(x,2)
if k2!=-1: return [k2,k2]
for j in range(len(gde)):
if gde[i]!=gde[j]:
gg=gcd(gde[i],gde[j])
if gg>1: return (gg,x//gg)
return [-1]
for i in range(n):
a=razl(i,numbers)
if a[0]==-1:
if non_pr.get(numbers[i])==None:
non_pr[numbers[i]]=1
else: non_pr[numbers[i]]+=1
else:
for j in a:
if pr.get(j)==None:
pr[j]=1
else: pr[j]+=1
answer=1
for ii,i in pr.items():
answer=(answer*(i+1))%ppp
for ii,i in non_pr.items():
answer=(answer*(i+1))%ppp
answer=(answer*(i+1))%ppp
print(answer)
stdout.flush()
``` | instruction | 0 | 79,932 | 22 | 159,864 |
Yes | output | 1 | 79,932 | 22 | 159,865 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
from math import sqrt
from random import randint
import sys
MOD = 998244353;
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
def g(x,n):
return (x*x+c)%n
def func(n):
x = 4;
y = 4;
d = 1;
while d == 1:
x = g(x,n);
y = g(g(y,n),n);
d = gcd(abs(x-y),n);
if (d == n):
return -1;
else:
return d
c = randint(-1,1)
x = randint(1,1000)
n = int(sys.stdin.readline())
a = []
for i in range(n):
a.append(int(sys.stdin.readline()))
m = {}
for i in range(n):
if a[i] == 1:
continue
t = int(round(sqrt(int(round(sqrt(a[i]))))))
u = int(round(sqrt(a[i])))
v = int(round(a[i]**(1/3)))
if t*t*t*t == a[i]:
try:
m[t] += 4
except:
m[t] = 4
elif u*u == a[i]:
try:
m[u] += 2
except:
m[u] = 2
elif v*v*v == a[i]:
if v in m:
m[v] += 3
else:
m[v] = 3
else:
t = func(a[i])
if t == -1:
if a[i] in m:
m[a[i]] += 1
else:
m[a[i]] = 1
else:
if t in m:
m[t] += 1;
else:
m[t] = 1
if a[i]/t in m:
m[a[i]/t] += 1
else:
m[a[i]/t] = 1
res = 1
for i in m:
res = (res*(m[i]+1))%MOD
print(res)
``` | instruction | 0 | 79,933 | 22 | 159,866 |
No | output | 1 | 79,933 | 22 | 159,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
from math import gcd
from collections import Counter
n = int(input())
a_is = []
pqs = []
ps = Counter()
for i in range(n):
a_i = int(input())
a_is.append(a_i)
p = int(a_i ** (1 / 2))
if p ** 2 == a_i:
d = int(p ** (1 / 2))
if d ** 4 == a_i:
ps[d] += 4
else:
ps[p] += 2
continue
p = int(a_i ** (1 / 3))
if p ** 3 == a_i:
ps[p] += 3
else:
pqs.append(a_i)
outliers = Counter()
for pq in pqs:
for a_i in a_is:
g = gcd(pq , a_i)
print(pq, a_i, g)
if g != 1 and a_i != pq:
ps[g] += 1
ps[pq // g] += 1
break
# pq is coprime with every a_i that is
# different from pq.
else:
outliers[pq] += 1
pi = 1
MOD = 998244353
for p in ps.values():
pi = pi * (p + 1) % MOD
for p in outliers.values():
pi = pi * (p + 1) ** 2 % MOD
print(pi)
``` | instruction | 0 | 79,934 | 22 | 159,868 |
No | output | 1 | 79,934 | 22 | 159,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
import math
import sys
from collections import defaultdict
n = int(input())
values = []
for i in range(n):
values.append(int(input()))
# def find_first(t):
# t_sqrt = math.ceil(math.sqrt(t))
# for i in range(2, t_sqrt + 1):
# if t % i == 0:
# return i
from fractions import gcd
primes__ = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973]
def pollard_rho(n, seed=2, f=lambda x: x**2 + 1):
x, y, d = seed, seed, 1
while d == 1:
x = f(x) % n
y = f(f(y)) % n
d = gcd((x - y) % n, n)
return None if d == n else d
def isqrt(n):
x = n
y = (x + n // x) // 2
while y < x:
x = y
y = (x + n // x) // 2
return x
def find_first_(n):
if n%2 == 0:
return (n//2, 2)
a = isqrt(n) # int(ceil(n**0.5))
for prime_ in primes__:
if n % prime_ == 0:
return (prime_, n // prime_)
b2 = a*a - n
b = isqrt(n) # int(b2**0.5)
count = 0
while b*b != b2:
a = a + 1
b2 = a*a - n
b = isqrt(b2) # int(b2**0.5)
count += 1
p=a+b
q=a-b
return (p, q)
result = defaultdict(int)
for value in values:
sqrt_val = isqrt(value)
if sqrt_val**2 == value:
qt_val = isqrt(sqrt_val)
if qt_val**4 == value:
result[qt_val]+=4
else:
result[sqrt_val]+=2
continue
(p, q) = (None, None)
for k in result.keys():
if value % k == 0:
temp = value//k
if temp > k:
(p, q) = (temp, k)
else:
(p, q) = (k, temp)
break
if not p:
(p, q) = find_first_(value)
if q**2 == p:
result[q]+=3
else:
result[p]+=1
result[q]+=1
final = 1
# print(result)
for k,v in result.items():
final = final*((v+1) % 998244353)
final = final % 998244353
print(final)
sys.stdout.flush()
``` | instruction | 0 | 79,935 | 22 | 159,870 |
No | output | 1 | 79,935 | 22 | 159,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n integers a_1, a_2, β¦, a_n. Each of a_i has between 3 and 5 divisors. Consider a = β a_i β the product of all input integers. Find the number of divisors of a. As this number may be very large, print it modulo prime number 998244353.
Input
The first line contains a single integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains an integer a_i (1 β€ a_i β€ 2β
10^{18}). It is guaranteed that the number of divisors of each a_i is between 3 and 5.
Output
Print a single integer d β the number of divisors of the product a_1 β
a_2 β
... β
a_n modulo 998244353.
Hacks input
For hacks, the input needs to be provided in a special format.
The first line contains an integer n (1 β€ n β€ 500) β the number of numbers.
Each of the next n lines contains a prime factorization of a_i. The line contains an integer k_i (2 β€ k_i β€ 4) β the number of prime factors of a_i and k_i integers p_{i,j} (2 β€ p_{i,j} β€ 2 β
10^{18}) where p_{i,j} is the j-th prime factor of a_i.
Before supplying the input to the contestant, a_i = β p_{i,j} are calculated. Note that each p_{i,j} must be prime, each computed a_i must satisfy a_i β€ 2β
10^{18} and must have between 3 and 5 divisors. The contestant will be given only a_i, and not its prime factorization.
For example, you need to use this test to get the first sample:
3
2 3 3
2 3 5
2 11 13
Interaction
From the technical side, this problem is interactive. Therefore, do not forget to output end of line and flush the output. Also, do not read more than you need. To flush the output, use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
Examples
Input
3
9
15
143
Output
32
Input
1
7400840699802997
Output
4
Input
8
4606061759128693
4606066102679989
4606069767552943
4606063116488033
4606063930903637
4606064745319241
4606063930904021
4606065559735517
Output
1920
Input
3
4
8
16
Output
10
Note
In the first case, a = 19305. Its divisors are 1, 3, 5, 9, 11, 13, 15, 27, 33, 39, 45, 55, 65, 99, 117, 135, 143, 165, 195, 297, 351, 429, 495, 585, 715, 1287, 1485, 1755, 2145, 3861, 6435, 19305 β a total of 32.
In the second case, a has four divisors: 1, 86028121, 86028157, and 7400840699802997 .
In the third case a = 202600445671925364698739061629083877981962069703140268516570564888699 375209477214045102253766023072401557491054453690213483547.
In the fourth case, a=512=2^9, so answer equals to 10.
Submitted Solution:
```
from math import *
MOD = 998244353;
def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
def g(x,n):
return (x*x+1)%n
def func(n):
x = 2;
y = 2;
d = 1;
while d == 1:
x = g(x,n);
y = g(g(y,n),n);
d = gcd(abs(x-y),n);
if (d == n):
return -1;
else:
return d
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
m = {}
for i in range(n):
if a[i] == 1:
continue
t = int(round(sqrt(int(round(sqrt(a[i]))))))
u = int(round(sqrt(a[i])))
v = int(round(a[i] ** 1/3))
if t*t*t*t == a[i]:
if t in m:
m[t] += 4
else:
m[t] = 4
elif u*u == a[i]:
if u in m:
m[u] += 2
else:
m[u] = 2
elif v*v*v == a[i]:
if v in m:
m[v] += 3
else:
m[v] = 3
else:
t = func(a[i])
if t == -1:
if a[i] in m:
m[a[i]] += 1
else:
m[a[i]] = 1
else:
if t in m:
m[t] += 1;
else:
m[t] = 1
if a[i]/t in m:
m[a[i]/t] += 1
else:
m[a[i]/t] = 1
res = 1
for i in m:
res = (res*(m[i]+1))%MOD
print(res)
``` | instruction | 0 | 79,936 | 22 | 159,872 |
No | output | 1 | 79,936 | 22 | 159,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,973 | 22 | 159,946 |
Tags: binary search, data structures, number theory
Correct Solution:
```
entrada = int(input())
temporario = [-1] * 100005
i=1
while(i<=entrada):
resposta=0
x,y = input().split()
x = int(x)
y = int(y)
j = 1
while(j*j<=x):
if (x%j==0):
if (i-temporario[j]>y):
resposta += 1
if (x-j*j and i-temporario[int(x/j)]>y):
resposta += 1
temporario[j]=temporario[int(x/j)]=i
j += 1
print(resposta)
i += 1
``` | output | 1 | 79,973 | 22 | 159,947 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,974 | 22 | 159,948 |
Tags: binary search, data structures, number theory
Correct Solution:
```
maxn=100000
div=[0]*(maxn+1)
last=[-maxn]*(maxn+1)
for i in range(maxn+1):
div[i]=list()
for i in range(2,maxn+1):
for j in range(i,maxn+1,i):
div[j].append(i)
t=int(input())
for k in range(0,t):
x_i,y_i = input().split(" ")
x_i=int(x_i)
y_i=int(y_i)
if y_i==0:
print(len(div[x_i])+1)
else:
print(sum(1 for v in div[x_i] if last[v]<k-y_i))
for d in div[x_i]:
last[d]=k
``` | output | 1 | 79,974 | 22 | 159,949 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,975 | 22 | 159,950 |
Tags: binary search, data structures, number theory
Correct Solution:
```
import sys
import collections as cc
input=sys.stdin.buffer.readline
I=lambda:list(map(int,input().split()))
prev=cc.defaultdict(int)
for tc in range(int(input())):
x,y=I()
div=set()
for i in range(1,int(x**0.5)+1):
if x%i==0:
div.add(i)
div.add(x//i)
ans=0
now=tc+1
for i in div:
if now-prev[i]>y:
ans+=1
prev[i]=now
print(ans)
``` | output | 1 | 79,975 | 22 | 159,951 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,976 | 22 | 159,952 |
Tags: binary search, data structures, number theory
Correct Solution:
```
import sys
import collections as cc
input=sys.stdin.readline
I=lambda:list(map(int,input().split()))
prev=cc.defaultdict(int)
for tc in range(int(input())):
x,y=I()
div=set()
for i in range(1,int(x**0.5)+1):
if x%i==0:
div.add(i)
div.add(x//i)
ans=0
now=tc+1
for i in div:
if now-prev[i]>y:
ans+=1
prev[i]=now
print(ans)
``` | output | 1 | 79,976 | 22 | 159,953 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,977 | 22 | 159,954 |
Tags: binary search, data structures, number theory
Correct Solution:
```
#!/usr/bin/env python3
from math import sqrt
n = int(input())
latest = {}
for i in range(1, n+1):
x, y = map(int, input().split())
cnt = 0
for d in range(1, int(sqrt(x))+1):
if x % d != 0:
continue
if latest.get(d, 0) < i - y:
cnt += 1
latest[d] = i
q = x // d
if q == d:
continue
if latest.get(q, 0) < i - y:
cnt += 1
latest[q] = i
print(cnt)
``` | output | 1 | 79,977 | 22 | 159,955 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,978 | 22 | 159,956 |
Tags: binary search, data structures, number theory
Correct Solution:
```
import sys,collections as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
def div(b):
an=[]
for i in range(1,int(b**0.5)+1):
if b%i==0:
an.append(i)
if i!=b//i:
an.append(b//i)
return an
n,=I()
ar=[]
vis=[-1]*(10**5+2)
for i in range(n):
a,b=I()
an=0
dv=div(a)
#print(dv,vis[:20])
for j in dv:
if vis[j]<i-b:
an+=1
vis[j]=i
print(an)
``` | output | 1 | 79,978 | 22 | 159,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,979 | 22 | 159,958 |
Tags: binary search, data structures, number theory
Correct Solution:
```
from math import sqrt
n = int(input().rstrip())
f = [-100000 for i in range(100001)]
for j in range(n):
x, y = tuple(int(i) for i in input().rstrip().split())
c = 0
for i in range(1, int(sqrt(x)+1)):
if x%i == 0:
q = x//i
p = i
if(f[p]<j-y):
c+=1
f[p] = j
if(f[q]<j-y):
c+=1
f[q] = j
print(c)
``` | output | 1 | 79,979 | 22 | 159,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18 | instruction | 0 | 79,980 | 22 | 159,960 |
Tags: binary search, data structures, number theory
Correct Solution:
```
from collections import defaultdict
mp=defaultdict(lambda :0)
x=int(input())
for k in range(1,x+1):
a,b=map(int,input().split())
res=0
for n in range(1,int(a**.5)+1):
if a%n==0:
if mp[n]==0:
res+=1
elif mp[n]<k-b:
res+=1
mp[n]=k
if n*n!=a:
v=a//n
if mp[v]==0:
res+=1
elif mp[v]<k-b:
res+=1
mp[v]=k
print(res)
``` | output | 1 | 79,980 | 22 | 159,961 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
Submitted Solution:
```
from math import sqrt,ceil
n=int(input())
l=[[] for i in range(n)]
ans=0
d=dict()
for i in range(n):
a,b=map(int,input().split())
ans=0
for j in range(1,ceil(sqrt(a))+1):
if a%j==0:
j2=a//j
if j!=j2:
if not j in d:
d[j]=i
ans+=1
else:
t=d[j]
if i-b>t:
ans+=1
d[j]=i
if not j2 in d:
d[j2]=i
ans+=1
else:
t=d[j2]
if i-b>t:
ans+=1
d[j2]=i
else:
if not j in d:
d[j]=i
ans+=1
else:
t=d[j]
if i-b>t:
ans+=1
d[j]=i
print(ans)
``` | instruction | 0 | 79,981 | 22 | 159,962 |
Yes | output | 1 | 79,981 | 22 | 159,963 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
Submitted Solution:
```
from sys import stdin as inp
from math import sqrt
primos5 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397]
def primedec(n):
res = []
#totaldiv = 1
if n in primos5: return [[n, 1]]
for p in primos5:
if p > sqrt(n): break
N = n
ex = 0
while (N % p == 0):
ex += 1
N /= p
if (ex != 0):
res.append([p, ex])
#totaldiv *= (ex + 1)
return res
def divs(n, pdec):
res = [1]
for i in range(len(pdec)):
p = pdec[i][0]
ex = pdec[i][1]
clen = len(res)
for j in range(clen):
for e in range(1, ex+1):
res.append(res[j]*(p**e))
return res
t = int(inp.readline())
xs = [0]*t
print(divs(5, primedec(5)))
for i in range(t):
xs[i], yi = map(int, inp.readline().split())
ares = divs(xs[i], primedec(xs[i]))
for j in range(i - yi, i):
indtorem = []
for k in range(len(ares)):
d = ares[k]
#print(d)
if xs[j] % d== 0:
indtorem.append(k)
ares = [ares[k] for k in range(len(ares)) if k not in indtorem]
print(len(ares))
``` | instruction | 0 | 79,982 | 22 | 159,964 |
No | output | 1 | 79,982 | 22 | 159,965 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
Submitted Solution:
```
import sys
def divisor(n):
div = list()
i = 1
sqrt = n**(1/2)
while i <= sqrt:
if (n % i) == 0:
div.append(i)
if i != (n/i):
div.append(int(n/i))
i += 1
return div
n = int(sys.stdin.readline())
xs = list()
for i in range(n):
x = list(map(int, sys.stdin.readline().split()))
div = divisor(x[0])
if i == 0:
print(len(div))
xs.append(x[0])
continue
ran = xs[i-x[1]:]
for k in ran:
j = 0
while j < len(div):
v = div[j]
if (k % v) == 0:
div.remove(v)
j += 1
xs.append(x[0])
print(len(div))
``` | instruction | 0 | 79,983 | 22 | 159,966 |
No | output | 1 | 79,983 | 22 | 159,967 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
Submitted Solution:
```
import sys
def divisor(n):
div = list()
i = 1
sqrt = n**(1/2)
while i <= sqrt:
if (n % i) == 0:
div.append(i)
if i != (n/i):
div.append(int(n/i))
i += 1
return div
n = int(sys.stdin.readline())
xs = list()
for i in range(n):
x = list(map(int, sys.stdin.readline().split()))
div = divisor(x[0])
if x[1] == 0 or i == 0:
print(len(div))
xs.append(x[0])
continue
b = i-x[1] if i-x[1] >= 0 else 0
ran = xs[i-x[1]:]
for k in ran:
j = 0
temp = div
while j < len(div):
v = div[j]
if (int(k % v)) == 0:
temp.remove(v)
j += 1
div = temp
xs.append(x[0])
print(len(div))
``` | instruction | 0 | 79,984 | 22 | 159,968 |
No | output | 1 | 79,984 | 22 | 159,969 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him.
Input
The first line contains an integer n (1 β€ n β€ 105). Each of the following n lines contain two space-separated integers xi and yi (1 β€ xi β€ 105, 0 β€ yi β€ i - 1, where i is the query's ordinal number; the numeration starts with 1).
If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration.
Output
For each query print the answer on a single line: the number of positive integers k such that <image>
Examples
Input
6
4 0
3 1
5 2
6 2
18 4
10000 3
Output
3
1
1
2
2
22
Note
Let's write out the divisors that give answers for the first 5 queries:
1) 1, 2, 4
2) 3
3) 5
4) 2, 6
5) 9, 18
Submitted Solution:
```
maxn=100000
div=[0]*(maxn+1)
last=[-maxn]*(maxn+1)
for i in range(maxn+1):
div[i]=list()
for i in range(2,int(maxn/2)):
for j in range(i,maxn+1,i):
div[j].append(i)
t=int(input())
for k in range(0,t):
x_i,y_i = input().split(" ")
x_i=int(x_i)
y_i=int(y_i)
if y_i==0:
print(len(div[x_i])+1)
else:
print(sum(1 for v in div[x_i] if last[v]<k-y_i))
for d in div[x_i]:
last[d]=k
``` | instruction | 0 | 79,985 | 22 | 159,970 |
No | output | 1 | 79,985 | 22 | 159,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,055 | 22 | 160,110 |
Tags: math
Correct Solution:
```
test = int(input())
for z in range(test):
a, b = map(int, input().split())
ans = 0
current = 9
while current <= b:
if (current + 1 == 10 ** len(str(current))):
ans += a
current = current * 10 + 9
print(ans)
``` | output | 1 | 80,055 | 22 | 160,111 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,056 | 22 | 160,112 |
Tags: math
Correct Solution:
```
check = [0, 9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999]
for _ in range(int(input())):
a, b = map(int, input().split())
count = 0
for i in range(10):
if (b >= check[i]):
count = i
else:
break
print(a*count)
``` | output | 1 | 80,056 | 22 | 160,113 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,057 | 22 | 160,114 |
Tags: math
Correct Solution:
```
t = int(input())
for i in range(t):
a , b = input().split()
b_value = len(b) - 1
if '9'*len(b) == b:
b_value = len(b)
ans = int(a)*b_value
print(ans)
``` | output | 1 | 80,057 | 22 | 160,115 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,058 | 22 | 160,116 |
Tags: math
Correct Solution:
```
t=int(input())
for _ in range(t):
a,b=map(int,input().split(" "))
s=len(str(b+1))-1
print(a*s)
``` | output | 1 | 80,058 | 22 | 160,117 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,059 | 22 | 160,118 |
Tags: math
Correct Solution:
```
t=int(input())
for i in range(0,t):
ab=input().split()
a=int(ab[0])
b=int(ab[1])
x=len(str(b+1))-1
print(a*x)
``` | output | 1 | 80,059 | 22 | 160,119 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,060 | 22 | 160,120 |
Tags: math
Correct Solution:
```
t=int(input())
for q in range(t):
a,b = map(int, input().split())
s2=len(str(b))
if int('9'*s2)>b:
print((s2-1)*a)
else:
print(s2*a)
``` | output | 1 | 80,060 | 22 | 160,121 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Try guessing the statement from this picture <http://tiny.cc/ogyoiz>.
You are given two integers A and B, calculate the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true; conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). a and b should not contain leading zeroes.
Input
The first line contains t (1 β€ t β€ 100) β the number of test cases.
Each test case contains two integers A and B (1 β€ A, B β€ 10^9).
Output
Print one integer β the number of pairs (a, b) such that 1 β€ a β€ A, 1 β€ b β€ B, and the equation a β
b + a + b = conc(a, b) is true.
Example
Input
3
1 11
4 2
191 31415926
Output
1
0
1337
Note
There is only one suitable pair in the first test case: a = 1, b = 9 (1 + 9 + 1 β
9 = 19). | instruction | 0 | 80,061 | 22 | 160,122 |
Tags: math
Correct Solution:
```
t = int(input())
for _ in range(t):
a, b = map(int, input().split())
i = "9"
while int(i) <= b:
i += "9"
print((len(i)-1)*a)
``` | output | 1 | 80,061 | 22 | 160,123 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.