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.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one. | instruction | 0 | 55,635 | 22 | 111,270 |
Tags: math
Correct Solution:
```
n, k = map(int, input().split())
r = k - 1
while n % r != 0:
r -= 1
m = n // r
x = k * m + r
print(x)
``` | output | 1 | 55,635 | 22 | 111,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one. | instruction | 0 | 55,636 | 22 | 111,272 |
Tags: math
Correct Solution:
```
n,k = [int(i) for i in input().split()]
ost = k - 1
while n % ost != 0:
ost -= 1
x = n//ost * k + ost
print(x)
``` | output | 1 | 55,636 | 22 | 111,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one. | instruction | 0 | 55,637 | 22 | 111,274 |
Tags: math
Correct Solution:
```
a, b = list(map(int, input().split()))
ans = 100000000000
if a == 0:
print(0)
else:
for i in range(1, b):
if a % i == 0:
ans = min(a // i * b + i, ans)
print(ans)
``` | output | 1 | 55,637 | 22 | 111,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one. | instruction | 0 | 55,638 | 22 | 111,276 |
Tags: math
Correct Solution:
```
import math
a = input().split()
n, k = int(a[0]), int(a[1])
res = []
if n == 1:
print(k + 1)
else:
for i in range(1, math.ceil(math.sqrt(int(n))) + 1):
if n % i==0:
if ((i + k * n/i) // k ) * ((i + k * n/i) % k) == n:
res.append(i + k * n/i)
if ((i * k + n/i) // k ) * ((i* k + n/i) % k) == n:
res.append(i * k + n/i)
print(int(min(res)))
``` | output | 1 | 55,638 | 22 | 111,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
s = str(input())
n = int(s.split()[0])
k = int(s.split()[1])
x = 1
p = []
while x<=n:
t = n%x
if (t==0):
d=int(n//x)
m=int(n//d)
num = int((k*d)+m)
if((num//k)*(num%k)==n):
p.append(int((k*d)+m))
x+=1
m=0
for i in p:
if(m==0):
m=i
else:
m=min(i, m)
print(m)
``` | instruction | 0 | 55,639 | 22 | 111,278 |
Yes | output | 1 | 55,639 | 22 | 111,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
n, k = list(map(int, input().split()))
a = k-1
while(a>0):
if n%a==0:
print(a+(n//a)*k)
break
a -= 1
``` | instruction | 0 | 55,640 | 22 | 111,280 |
Yes | output | 1 | 55,640 | 22 | 111,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
n, k = map(int, input().split())
for i in range(k - 1, 0, -1):
if n % i == 0:
print((n // i) * k + i)
break
``` | instruction | 0 | 55,641 | 22 | 111,282 |
Yes | output | 1 | 55,641 | 22 | 111,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
a, b = map(int,input().split())
r = 0
for i in range(1,b):
if a%i == 0 and i>r:
r = i
q = a//r
print(q*b+r)
``` | instruction | 0 | 55,642 | 22 | 111,284 |
Yes | output | 1 | 55,642 | 22 | 111,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
n, k = map(int, input().split())
i = 1
ans = []
for p in range(1, k):
a = str((n * k) / p + p)
b = a.index(".")
if len(a) - (b + 1) == 1 and a[-1] == "0":
ans.append(int(float(a)))
print(ans[-1])
``` | instruction | 0 | 55,643 | 22 | 111,286 |
No | output | 1 | 55,643 | 22 | 111,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
n,k=map(int,input().split())
mns=99999999
i=1
if max(n,k)%min(n,k)!=0:
print(n+k)
else:
while i in range(1,k):
mns1=n//i*k+i
mns2=(mns1//k)*(mns1%k)
if mns2==n:
mns=min(mns,mns1)
i+=1
print(mns)
``` | instruction | 0 | 55,644 | 22 | 111,288 |
No | output | 1 | 55,644 | 22 | 111,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
n, k= input().split()
n, k = int(n), int(k)
for x in range(1000000):
if (x//k)*(x%k)==n:
print(x)
break
``` | instruction | 0 | 55,645 | 22 | 111,290 |
No | output | 1 | 55,645 | 22 | 111,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya likes to solve equations. Today he wants to solve (x~div~k) β
(x mod k) = n, where div and mod stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, k and n are positive integer parameters, and x is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible x. Can you help him?
Input
The first line contains two integers n and k (1 β€ n β€ 10^6, 2 β€ k β€ 1000).
Output
Print a single integer x β the smallest positive integer solution to (x~div~k) β
(x mod k) = n. It is guaranteed that this equation has at least one positive integer solution.
Examples
Input
6 3
Output
11
Input
1 2
Output
3
Input
4 6
Output
10
Note
The result of integer division a~div~b is equal to the largest integer c such that b β
c β€ a. a modulo b (shortened a mod b) is the only integer c such that 0 β€ c < b, and a - c is divisible by b.
In the first sample, 11~div~3 = 3 and 11 mod 3 = 2. Since 3 β
2 = 6, then x = 11 is a solution to (x~div~3) β
(x mod 3) = 6. One can see that 19 is the only other positive integer solution, hence 11 is the smallest one.
Submitted Solution:
```
from math import sqrt
n, k = [int(s) for s in input().split()]
for i in range(n, n*n+1):
if (i//k)*(i%k) == n:
print(i)
break
``` | instruction | 0 | 55,646 | 22 | 111,292 |
No | output | 1 | 55,646 | 22 | 111,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,732 | 22 | 111,464 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
n,m,p=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
i=j=0
while(a[i]%p==0):
i+=1
while(b[j]%p==0):
j+=1
print(i+j)
``` | output | 1 | 55,732 | 22 | 111,465 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,733 | 22 | 111,466 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
N, M, P = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
ans = 0
for i, a in enumerate(A):
if a % P != 0:
ans = i
break
for i, b in enumerate(B):
if b % P != 0:
ans += i
break
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 55,733 | 22 | 111,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,734 | 22 | 111,468 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq
'''
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
def main():
try:
n,m,p=In()
a=list(In())
b=list(In())
for x in range(n):
if a[x]%p!=0:
break
for y in range(m):
if b[y]%p!=0:
break
print(x+y)
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
main()
``` | output | 1 | 55,734 | 22 | 111,469 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,735 | 22 | 111,470 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
import sys
input = lambda: sys.stdin.readline().rstrip()
N, M, P = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
for i, a in enumerate(A):
if a % P:
for j, b in enumerate(B):
if b % P:
print(i+j)
exit()
``` | output | 1 | 55,735 | 22 | 111,471 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,736 | 22 | 111,472 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
from sys import stdin
input = stdin.buffer.readline
n, m, p = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y = (0, 0)
while (a[x] % p) == 0:
x += 1
while (b[y] % p) == 0:
y += 1
print((x + y))
``` | output | 1 | 55,736 | 22 | 111,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,737 | 22 | 111,474 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
#threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
#sys.setrecursionlimit(300000)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class TreeNode:
def __init__(self, k, v):
self.key = k
self.value = v
self.left = None
self.right = None
self.parent = None
self.height = 1
self.num_left = 1
self.num_total = 1
class AvlTree:
def __init__(self):
self._tree = None
def add(self, k, v):
if not self._tree:
self._tree = TreeNode(k, v)
return
node = self._add(k, v)
if node:
self._rebalance(node)
def _add(self, k, v):
node = self._tree
while node:
if k < node.key:
if node.left:
node = node.left
else:
node.left = TreeNode(k, v)
node.left.parent = node
return node.left
elif node.key < k:
if node.right:
node = node.right
else:
node.right = TreeNode(k, v)
node.right.parent = node
return node.right
else:
node.value = v
return
@staticmethod
def get_height(x):
return x.height if x else 0
@staticmethod
def get_num_total(x):
return x.num_total if x else 0
def _rebalance(self, node):
n = node
while n:
lh = self.get_height(n.left)
rh = self.get_height(n.right)
n.height = max(lh, rh) + 1
balance_factor = lh - rh
n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
n.num_left = 1 + self.get_num_total(n.left)
if balance_factor > 1:
if self.get_height(n.left.left) < self.get_height(n.left.right):
self._rotate_left(n.left)
self._rotate_right(n)
elif balance_factor < -1:
if self.get_height(n.right.right) < self.get_height(n.right.left):
self._rotate_right(n.right)
self._rotate_left(n)
else:
n = n.parent
def _remove_one(self, node):
"""
Side effect!!! Changes node. Node should have exactly one child
"""
replacement = node.left or node.right
if node.parent:
if AvlTree._is_left(node):
node.parent.left = replacement
else:
node.parent.right = replacement
replacement.parent = node.parent
node.parent = None
else:
self._tree = replacement
replacement.parent = None
node.left = None
node.right = None
node.parent = None
self._rebalance(replacement)
def _remove_leaf(self, node):
if node.parent:
if AvlTree._is_left(node):
node.parent.left = None
else:
node.parent.right = None
self._rebalance(node.parent)
else:
self._tree = None
node.parent = None
node.left = None
node.right = None
def remove(self, k):
node = self._get_node(k)
if not node:
return
if AvlTree._is_leaf(node):
self._remove_leaf(node)
return
if node.left and node.right:
nxt = AvlTree._get_next(node)
node.key = nxt.key
node.value = nxt.value
if self._is_leaf(nxt):
self._remove_leaf(nxt)
else:
self._remove_one(nxt)
self._rebalance(node)
else:
self._remove_one(node)
def get(self, k):
node = self._get_node(k)
return node.value if node else -1
def _get_node(self, k):
if not self._tree:
return None
node = self._tree
while node:
if k < node.key:
node = node.left
elif node.key < k:
node = node.right
else:
return node
return None
def get_at(self, pos):
x = pos + 1
node = self._tree
while node:
if x < node.num_left:
node = node.left
elif node.num_left < x:
x -= node.num_left
node = node.right
else:
return (node.key, node.value)
raise IndexError("Out of ranges")
@staticmethod
def _is_left(node):
return node.parent.left and node.parent.left == node
@staticmethod
def _is_leaf(node):
return node.left is None and node.right is None
def _rotate_right(self, node):
if not node.parent:
self._tree = node.left
node.left.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.left
node.left.parent = node.parent
else:
node.parent.right = node.left
node.left.parent = node.parent
bk = node.left.right
node.left.right = node
node.parent = node.left
node.left = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
def _rotate_left(self, node):
if not node.parent:
self._tree = node.right
node.right.parent = None
elif AvlTree._is_left(node):
node.parent.left = node.right
node.right.parent = node.parent
else:
node.parent.right = node.right
node.right.parent = node.parent
bk = node.right.left
node.right.left = node
node.parent = node.right
node.right = bk
if bk:
bk.parent = node
node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
node.num_left = 1 + self.get_num_total(node.left)
@staticmethod
def _get_next(node):
if not node.right:
return node.parent
n = node.right
while n.left:
n = n.left
return n
# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
def __init__(self, data, default=0, func=lambda a, b: max(a , b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b:a + b):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
if a == 1 or n == 0:
return 1
if n % 2 == 0:
s = powm(a, n // 2, m)
return s * s % m
else:
return a * powm(a, n - 1, m) % m
# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in sorted(zipped_pairs)]
return z
# --------------------------------------------------product----------------------------------------
def product(l):
por = 1
for i in range(len(l)):
por *= l[i]
return por
# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
left = 0
right = n - 1
count = 0
while (left <= right):
mid = int((right + left) / 2)
# Check if middle element is
# less than or equal to key
if (arr[mid] < key):
count = mid + 1
left = mid + 1
# If key is smaller, ignore right half
else:
right = mid - 1
return count
# --------------------------------------------------binary----------------------------------------
def countdig(n):
c = 0
while (n > 0):
n //= 10
c += 1
return c
def binary(x, length):
y = bin(x)[2:]
return y if len(y) >= length else "0" * (length - len(y)) + y
def countGreater(arr, n, k):
l = 0
r = n - 1
# Stores the index of the left most element
# from the array which is greater than k
leftGreater = n
# Finds number of elements greater than k
while (l <= r):
m = int(l + (r - l) / 2)
if (arr[m] >= k):
leftGreater = m
r = m - 1
# If mid element is less than
# or equal to k update l
else:
l = m + 1
# Return the count of elements
# greater than k
return (n - leftGreater)
# --------------------------------------------------binary------------------------------------
n,m,p=map(int,input().split())
l=list(map(int,input().split()))
l1=list(map(int,input().split()))
ans=0
for i in range(n):
if l[i]%p!=0:
ans+=i
break
for i in range(m):
if l1[i]%p!=0:
ans+=i
break
print(ans)
``` | output | 1 | 55,737 | 22 | 111,475 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,738 | 22 | 111,476 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
n, m, p = map(int, input().split())
arr_1 = list(map(int, input().split()))
arr_2 = list(map(int, input().split()))
for i in range(n):
if arr_1[i] % p != 0:
d1 = i
break
for j in range(m):
if arr_2[j] % p != 0:
d2 = j
break
print(d1 + d2)
``` | output | 1 | 55,738 | 22 | 111,477 |
Provide tags and a correct Python 3 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,739 | 22 | 111,478 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
R = lambda: list(map(int,input().split()))
n,m,p=R()
a,b=R(),R()
i=0
while a[i]%p==0:
i+=1
j=0
while b[j]%p==0:
j+=1
print(i+j)
``` | output | 1 | 55,739 | 22 | 111,479 |
Provide tags and a correct Python 2 solution for this coding contest problem.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime. | instruction | 0 | 55,740 | 22 | 111,480 |
Tags: constructive algorithms, math, ternary search
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_num():
return int(raw_input())
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
_,_,p=in_arr()
ans=0
for i,x in enumerate(in_arr()):
if x%p:
ans+=i
break
for i,x in enumerate(in_arr()):
if x%p:
ans+=i
break
pr_num(ans)
``` | output | 1 | 55,740 | 22 | 111,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
l1=[int(i) for i in input().split()]
l2=[int(i)%l1[2] for i in input().split()]
l3=[int(i)%l1[2] for i in input().split()]
m=0
for i in range(len(l2)):
if l2[i]!=0:
m=i
break
for i in range(len(l3)):
if l3[i]!=0:
m=m+i
break
print(m)
``` | instruction | 0 | 55,741 | 22 | 111,482 |
Yes | output | 1 | 55,741 | 22 | 111,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
n, m, p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(n):
if a[i] % p != 0:
ar = i
break
for i in range(m):
if b[i] % p != 0:
br = i
break
print(ar + br)
``` | instruction | 0 | 55,742 | 22 | 111,484 |
Yes | output | 1 | 55,742 | 22 | 111,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n,m,p=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=-1
B=-1
for i in range(n):
if a[i]%p!=0:
A=i
break
for i in range(m):
if b[i]%p!=0:
B=i
break
print(A+B)
``` | instruction | 0 | 55,743 | 22 | 111,486 |
Yes | output | 1 | 55,743 | 22 | 111,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
#!/usr/bin/env python3
import sys
#lines = stdin.readlines()
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def rint():
return map(int, input().split())
#def input():
# return sys.stdin.readline().rstrip('\n')
def oint():
return int(input())
n = [0]*2
n[0], n[1], p = rint()
ans = 0
for c in range(2):
a = list(rint())
for i in range(n[c]):
if a[i]%p:
ans +=i
break
print(ans)
``` | instruction | 0 | 55,744 | 22 | 111,488 |
Yes | output | 1 | 55,744 | 22 | 111,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main():
def p(v, m):
if v < 0 or v >= len(m):
return 0
else:
return m[v]
n, m, MOD = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = a[-1] * b[-1]
if t % MOD != 0:
print(n + m - 2)
exit()
if a[0] * b[0] % MOD != 0:
print(0)
exit()
for i in range(1, max(m,n)):
cur = p(i, a) * p(i, b) + p(i * 2, b) * a[0] + p(i * 2, a) * b[0]
cur2 = p(i + 1, a) * p(i, b) + p(i + 1, b) * p(i, a) + p(i * 2 + 1, a) * b[0] + p(i * 2 + 1, b) * a[0]
if cur % MOD != 0:
print(i * 2)
exit()
if cur2 % MOD != 0:
print(i * 2 + 1)
exit()
main()
``` | instruction | 0 | 55,745 | 22 | 111,490 |
No | output | 1 | 55,745 | 22 | 111,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
from bisect import bisect_left, bisect_right, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
def data(): return sys.stdin.readline().strip()
def mdata(): return map(int, data().split())
n,m,p=mdata()
a=list(mdata())
b=list(mdata())
for i in range(min(n,m)):
if a[i]!=p or b[i]!=p:
if a[i]!=p:
if b[i]!=p:
print(i+i)
else:
ind=0
for j in range(i+1,m):
if b[j]!=p:
ind=j
break
print(i+ind)
else:
ind=0
for j in range(i+1,n):
if a[j]!=p:
ind=j
break
print(i+ind)
break
``` | instruction | 0 | 55,746 | 22 | 111,492 |
No | output | 1 | 55,746 | 22 | 111,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
import sys
input = sys.stdin.readline
def main():
N, M, P = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
if sum(A) * sum(B) < P:
print(0)
else:
if A[0] * B[0] % P != 0:
print(0)
return
if A[-1] * B[-1] % P != 0:
print(N + M - 2)
return
print((N + M - 2) // 2 + 1)
if __name__ == '__main__':
main()
``` | instruction | 0 | 55,747 | 22 | 111,494 |
No | output | 1 | 55,747 | 22 | 111,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x) = a_0 + a_1x + ... + a_{n-1}x^{n-1} and g(x) = b_0 + b_1x + ... + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a_0, a_1, ..., a_{n-1}) = gcd(b_0, b_1, ..., b_{m-1}) = 1. Let h(x) = f(x)β
g(x). Suppose that h(x) = c_0 + c_1x + ... + c_{n+m-2}x^{n+m-2}.
You are also given a prime number p. Professor R challenges you to find any t such that c_t isn't divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input
The first line of the input contains three integers, n, m and p (1 β€ n, m β€ 10^6, 2 β€ p β€ 10^9), β n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a_0, a_1, ..., a_{n-1} (1 β€ a_{i} β€ 10^{9}) β a_i is the coefficient of x^{i} in f(x).
The third line contains m integers b_0, b_1, ..., b_{m-1} (1 β€ b_{i} β€ 10^{9}) β b_i is the coefficient of x^{i} in g(x).
Output
Print a single integer t (0β€ t β€ n+m-2) β the appropriate power of x in h(x) whose coefficient isn't divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples
Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2
Note
In the first test case, f(x) is 2x^2 + x + 1 and g(x) is x + 2, their product h(x) being 2x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.
In the second test case, f(x) is x + 2 and g(x) is x + 3, their product h(x) being x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
Submitted Solution:
```
from sys import stdin, stdout
import math,sys
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
import bisect as bi
import heapq
'''
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
'''
#------------------Sublime--------------------------------------#
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
def main():
try:
n,m,p=In()
a=list(In())
b=list(In())
ans,ans2=[],[]
for x in a:
if x%p!=0:
ans.append(x)
for x in b:
if x%p!=0:
ans2.append(x)
print(ans[0]+ans2[0])
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
main()
``` | instruction | 0 | 55,748 | 22 | 111,496 |
No | output | 1 | 55,748 | 22 | 111,497 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,291 | 22 | 112,582 |
"Correct Solution:
```
N = int(input())
bi_N = bin(N)
tmp = len(bi_N)-3
print(2**tmp)
``` | output | 1 | 56,291 | 22 | 112,583 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,292 | 22 | 112,584 |
"Correct Solution:
```
from math import log2
print(2**int(log2(int(input()))))
``` | output | 1 | 56,292 | 22 | 112,585 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,293 | 22 | 112,586 |
"Correct Solution:
```
import math
print(2**math.floor(math.log2(int(input()))))
``` | output | 1 | 56,293 | 22 | 112,587 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,294 | 22 | 112,588 |
"Correct Solution:
```
N=int(input())
i=0
while pow(2, i+1)<=N:
i+=1
print(pow(2, i))
``` | output | 1 | 56,294 | 22 | 112,589 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,295 | 22 | 112,590 |
"Correct Solution:
```
N=int(input())
n=0
while N>=2**n:
n+=1
print(2**(n-1))
``` | output | 1 | 56,295 | 22 | 112,591 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,296 | 22 | 112,592 |
"Correct Solution:
```
n = int(input())
i = 1
while i<=n:
i = i*2
print(int(i/2))
``` | output | 1 | 56,296 | 22 | 112,593 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,297 | 22 | 112,594 |
"Correct Solution:
```
n = int(input())
p = 1
while p*2<=n:
p = p*2
print(p)
``` | output | 1 | 56,297 | 22 | 112,595 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64 | instruction | 0 | 56,298 | 22 | 112,596 |
"Correct Solution:
```
n = int(input())
import math
i = int(math.log2(n))
print(2**i)
``` | output | 1 | 56,298 | 22 | 112,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
N = int(input())
ans = 1
while ans*2 <= N:
ans *= 2
print(ans)
``` | instruction | 0 | 56,299 | 22 | 112,598 |
Yes | output | 1 | 56,299 | 22 | 112,599 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
N=int(input())
i=0
while 2**i<=N:
i+=1
print(2**(i-1))
``` | instruction | 0 | 56,300 | 22 | 112,600 |
Yes | output | 1 | 56,300 | 22 | 112,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
n = int(input())
print(2**(len(bin(n))-2-1))
``` | instruction | 0 | 56,301 | 22 | 112,602 |
Yes | output | 1 | 56,301 | 22 | 112,603 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
print(2 ** (len(bin(int(input()))) - 3))
``` | instruction | 0 | 56,302 | 22 | 112,604 |
Yes | output | 1 | 56,302 | 22 | 112,605 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
n = int(input())
list = []
for i in n:
counter = 0
while i%2 = 0:
counter += 1
i = i / 2
elif :
break
list.append(counter)
answer = list.index(max(list)) + 1
print(answer)
``` | instruction | 0 | 56,303 | 22 | 112,606 |
No | output | 1 | 56,303 | 22 | 112,607 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
num = int(input())
count_max = 0
for i in range(num):
tmp = i
count = 0
while tmp % 2 == 0:
tmp = tmp / 2
count += 1
if conut > count_max:
count_max = count
``` | instruction | 0 | 56,304 | 22 | 112,608 |
No | output | 1 | 56,304 | 22 | 112,609 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
n = int(input())
ans = 0
for i in range(1, 7):
if 2**i <= n:
ans = 2**i
print(ans)
``` | instruction | 0 | 56,305 | 22 | 112,610 |
No | output | 1 | 56,305 | 22 | 112,611 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
* 6 can be divided by 2 once: 6 -> 3.
* 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
* 3 can be divided by 2 zero times.
Constraints
* 1 β€ N β€ 100
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Examples
Input
7
Output
4
Input
32
Output
32
Input
1
Output
1
Input
100
Output
64
Submitted Solution:
```
N = int(input())
ans = 1
for i in range(7):
if 2**i < N:
ans = 2**i
else:
break
print(ans)
``` | instruction | 0 | 56,306 | 22 | 112,612 |
No | output | 1 | 56,306 | 22 | 112,613 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Of course, many of you can calculate Ο(n) β the number of positive integers that are less than or equal to n, that are coprime with n. But what if we need to calculate Ο(Ο(...Ο(n))), where function Ο is taken k times and n is given in the canonical decomposition into prime factors?
You are given n and k, calculate the value of Ο(Ο(...Ο(n))). Print the result in the canonical decomposition into prime factors.
Input
The first line contains integer m (1 β€ m β€ 105) β the number of distinct prime divisors in the canonical representaion of n.
Each of the next m lines contains a pair of space-separated integers pi, ai (2 β€ pi β€ 106; 1 β€ ai β€ 1017) β another prime divisor of number n and its power in the canonical representation. The sum of all ai doesn't exceed 1017. Prime divisors in the input follow in the strictly increasing order.
The last line contains integer k (1 β€ k β€ 1018).
Output
In the first line, print integer w β the number of distinct prime divisors of number Ο(Ο(...Ο(n))), where function Ο is taken k times.
Each of the next w lines must contain two space-separated integers qi, bi (bi β₯ 1) β another prime divisor and its power in the canonical representaion of the result. Numbers qi must go in the strictly increasing order.
Examples
Input
1
7 1
1
Output
2
2 1
3 1
Input
1
7 1
2
Output
1
2 1
Input
1
2 100000000000000000
10000000000000000
Output
1
2 90000000000000000
Note
You can read about canonical representation of a positive integer here: http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic.
You can read about function Ο(n) here: http://en.wikipedia.org/wiki/Euler's_totient_function.
Submitted Solution:
```
import os
os.listdir(path=".")
``` | instruction | 0 | 56,687 | 22 | 113,374 |
No | output | 1 | 56,687 | 22 | 113,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Of course, many of you can calculate Ο(n) β the number of positive integers that are less than or equal to n, that are coprime with n. But what if we need to calculate Ο(Ο(...Ο(n))), where function Ο is taken k times and n is given in the canonical decomposition into prime factors?
You are given n and k, calculate the value of Ο(Ο(...Ο(n))). Print the result in the canonical decomposition into prime factors.
Input
The first line contains integer m (1 β€ m β€ 105) β the number of distinct prime divisors in the canonical representaion of n.
Each of the next m lines contains a pair of space-separated integers pi, ai (2 β€ pi β€ 106; 1 β€ ai β€ 1017) β another prime divisor of number n and its power in the canonical representation. The sum of all ai doesn't exceed 1017. Prime divisors in the input follow in the strictly increasing order.
The last line contains integer k (1 β€ k β€ 1018).
Output
In the first line, print integer w β the number of distinct prime divisors of number Ο(Ο(...Ο(n))), where function Ο is taken k times.
Each of the next w lines must contain two space-separated integers qi, bi (bi β₯ 1) β another prime divisor and its power in the canonical representaion of the result. Numbers qi must go in the strictly increasing order.
Examples
Input
1
7 1
1
Output
2
2 1
3 1
Input
1
7 1
2
Output
1
2 1
Input
1
2 100000000000000000
10000000000000000
Output
1
2 90000000000000000
Note
You can read about canonical representation of a positive integer here: http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic.
You can read about function Ο(n) here: http://en.wikipedia.org/wiki/Euler's_totient_function.
Submitted Solution:
```
import os
print(os.listdir(path="."))
``` | instruction | 0 | 56,688 | 22 | 113,376 |
No | output | 1 | 56,688 | 22 | 113,377 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.
A set Ο of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation Ο, if pair <image>, in this case we use a notation <image>.
Binary relation is equivalence relation, if:
1. It is reflexive (for any a it is true that <image>);
2. It is symmetric (for any a, b it is true that if <image>, then <image>);
3. It is transitive (if <image> and <image>, than <image>).
Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":
Take any two elements, a and b. If <image>, then <image> (according to property (2)), which means <image> (according to property (3)).
It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.
Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).
Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.
Input
A single line contains a single integer n (1 β€ n β€ 4000).
Output
In a single line print the answer to the problem modulo 109 + 7.
Examples
Input
1
Output
1
Input
2
Output
3
Input
3
Output
10
Note
If n = 1 there is only one such relation β an empty one, i.e. <image>. In other words, for a single element x of set A the following is hold: <image>.
If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are <image>, Ο = {(x, x)}, Ο = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations. | instruction | 0 | 56,727 | 22 | 113,454 |
Tags: combinatorics, dp, math
Correct Solution:
```
mod = 10 ** 9 + 7
n = int(input())
a = [[0] * (n + 1) for i in range(n + 1)]
a[0][0] = 1
for i in range(1, n + 1):
a[i][0] = a[i - 1][i - 1]
for j in range(1, i + 1):
a[i][j] = (a[i][j - 1] + a[i - 1][j - 1]) % mod
print(a[n][n - 1])
``` | output | 1 | 56,727 | 22 | 113,455 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.
A set Ο of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation Ο, if pair <image>, in this case we use a notation <image>.
Binary relation is equivalence relation, if:
1. It is reflexive (for any a it is true that <image>);
2. It is symmetric (for any a, b it is true that if <image>, then <image>);
3. It is transitive (if <image> and <image>, than <image>).
Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":
Take any two elements, a and b. If <image>, then <image> (according to property (2)), which means <image> (according to property (3)).
It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.
Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).
Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.
Input
A single line contains a single integer n (1 β€ n β€ 4000).
Output
In a single line print the answer to the problem modulo 109 + 7.
Examples
Input
1
Output
1
Input
2
Output
3
Input
3
Output
10
Note
If n = 1 there is only one such relation β an empty one, i.e. <image>. In other words, for a single element x of set A the following is hold: <image>.
If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are <image>, Ο = {(x, x)}, Ο = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations. | instruction | 0 | 56,728 | 22 | 113,456 |
Tags: combinatorics, dp, math
Correct Solution:
```
from math import factorial
cat = [1, 1]
p = 10**9 + 7
n = int(input())
ans = 0
fac = [1]
mat = [[0 for i in range(n + 1)] for j in range(n + 1)]
mat[0][0] = 1
for i in range(1, n + 1):
mat[i][0] = mat[i - 1][i - 1]
for j in range(i):
mat[i][j + 1] = (mat[i][j] + mat[i - 1][j]) % p
print(mat[n][n - 1] % p)
``` | output | 1 | 56,728 | 22 | 113,457 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation.
A set Ο of pairs (a, b) of elements of some set A is called a binary relation on set A. For two elements a and b of the set A we say that they are in relation Ο, if pair <image>, in this case we use a notation <image>.
Binary relation is equivalence relation, if:
1. It is reflexive (for any a it is true that <image>);
2. It is symmetric (for any a, b it is true that if <image>, then <image>);
3. It is transitive (if <image> and <image>, than <image>).
Little Johnny is not completely a fool and he noticed that the first condition is not necessary! Here is his "proof":
Take any two elements, a and b. If <image>, then <image> (according to property (2)), which means <image> (according to property (3)).
It's very simple, isn't it? However, you noticed that Johnny's "proof" is wrong, and decided to show him a lot of examples that prove him wrong.
Here's your task: count the number of binary relations over a set of size n such that they are symmetric, transitive, but not an equivalence relations (i.e. they are not reflexive).
Since their number may be very large (not 0, according to Little Johnny), print the remainder of integer division of this number by 109 + 7.
Input
A single line contains a single integer n (1 β€ n β€ 4000).
Output
In a single line print the answer to the problem modulo 109 + 7.
Examples
Input
1
Output
1
Input
2
Output
3
Input
3
Output
10
Note
If n = 1 there is only one such relation β an empty one, i.e. <image>. In other words, for a single element x of set A the following is hold: <image>.
If n = 2 there are three such relations. Let's assume that set A consists of two elements, x and y. Then the valid relations are <image>, Ο = {(x, x)}, Ο = {(y, y)}. It is easy to see that the three listed binary relations are symmetric and transitive relations, but they are not equivalence relations. | instruction | 0 | 56,729 | 22 | 113,458 |
Tags: combinatorics, dp, math
Correct Solution:
```
def main():
mod = 10 ** 9 + 7
n = int(input())
a = [[0] * (n + 1) for i in range(n + 1)]
a[0][0] = 1
for i in range(1, n + 1):
a[i][0] = a[i - 1][i - 1]
for j in range(1, i + 1):
a[i][j] = (a[i][j - 1] + a[i - 1][j - 1]) % mod
print(a[n][n - 1])
main()
``` | output | 1 | 56,729 | 22 | 113,459 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.