description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≀ The sum of N over all the test cases ≀ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≀ N ≀ 15 : 37 points. $ $1 ≀ N ≀ 1000 : 24 points.$ $1 ≀ N ≀ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
import sys def find(arr, n): s = [None] * (n + 1) s[0] = 0 su = 0 for i in range(1, n + 1): su = (su + arr[i - 1]) % n if s[su] is not None: print(i - s[su]) for j in range(s[su], i): sys.stdout.write(str(j + 1) + " ") sys.stdout.write("\n") return 0 else: s[su] = i print(-1) t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) find(arr, n)
IMPORT FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≀ The sum of N over all the test cases ≀ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≀ N ≀ 15 : 37 points. $ $1 ≀ N ≀ 1000 : 24 points.$ $1 ≀ N ≀ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
test = int(input()) for i in range(test): n = int(input()) arr = list(map(int, input().split())) d = dict() d[0] = [0] s = 0 for i in range(n): s = (s + arr[i]) % n if not d.get(s, False): d[s] = [i + 1] else: start = d[s][0] end = i + 1 print(end - start) print(*list(range(start + 1, end + 1))) break else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≀ The sum of N over all the test cases ≀ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≀ N ≀ 15 : 37 points. $ $1 ≀ N ≀ 1000 : 24 points.$ $1 ≀ N ≀ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
def find(n, arr): s = [None] * (n + 1) s[0] = 0 su = 0 for i in range(1, n + 1): su = (su + arr[i - 1]) % n if s[su] is not None: print(i - s[su]) print(" ".join(str(j + 1) for j in range(s[su], i))) return 0 else: s[su] = i print(-1) for _ in range(int(input())): find(int(input()), list(map(int, input().split())))
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NONE EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≀ The sum of N over all the test cases ≀ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≀ N ≀ 15 : 37 points. $ $1 ≀ N ≀ 1000 : 24 points.$ $1 ≀ N ≀ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) prefix = [0] * (len(arr) + 1) for i, ele in enumerate(arr): prefix[i + 1] = prefix[i] + ele mod_arr = [0] * (n + 1) mod_loc = {} for i, ele in enumerate(prefix): mod_arr[i] = prefix[i] % n if mod_arr[i] in mod_loc.keys(): diff = i - mod_loc[mod_arr[i]] print(diff) for counter in range(mod_loc[mod_arr[i]] + 1, i + 1, 1): print(counter, end=" ") print() break else: mod_loc[mod_arr[i]] = i
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≀ The sum of N over all the test cases ≀ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≀ N ≀ 15 : 37 points. $ $1 ≀ N ≀ 1000 : 24 points.$ $1 ≀ N ≀ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = [] for i in range(n): if i == 0: b.append(a[i] % n) else: b.append((b[-1] + a[i]) % n) d = {} for idx, i in enumerate(b): if i == 0: res = list(range(1, idx + 2)) print(len(res)) print(*res) break if i not in d: d[i] = idx else: res = list(range(d[i] + 2, idx + 2)) print(len(res)) print(*res) break
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≀ The sum of N over all the test cases ≀ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≀ N ≀ 15 : 37 points. $ $1 ≀ N ≀ 1000 : 24 points.$ $1 ≀ N ≀ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
for i in range(int(input())): n = int(input()) arr = [int(x) for x in input().split()] freq = [0] * (n + 1) summ = 0 dic = {(0): 1} for i in range(n): summ += arr[i] mod = summ % n freq[i + 1] = mod if mod in dic: dic[mod] += 1 else: dic[mod] = 1 if sum(dic.values()) == n: print(-1) else: ans = [] key = -1 for i in dic: if dic[i] > 1: key = i break count = 0 for i in range(n + 1): if count == 2: break elif freq[i] == key and count == 0: count += 1 elif count == 1: ans.append(i) if freq[i] == key: count += 1 break print(len(ans)) print(*ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
primeUpto = [0] * 10000003 prime = [1] * 10000003 prime[0] = prime[1] = 0 def countPrime(): n = 10000001 p = 2 while p * p <= n: if prime[p] == 1: for i in range(p * p, n + 1, p): prime[i] = 0 p += 1 for i in range(1, 10000002): primeUpto[i] = primeUpto[i - 1] + prime[i] countPrime() for _ in range(int(input())): n = int(input()) if n == 3: print(2) elif n == 2: print(1) else: print(primeUpto[n] - primeUpto[n // 2] + 1)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(): a = [0] * 10000001 n = 10000000 cnt = 0 prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 for p in range(2, n + 1): if prime[p]: cnt += 1 a[p] = cnt return a T = int(input()) num = SieveOfEratosthenes() while T > 0: N = int(input()) if N == 2: print(1) T -= 1 continue if N == 3: print(2) T -= 1 continue even = N // 2 print(num[N] - (num[N // 2] - 1)) T -= 1
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 prefixsumprime = [(0) for i in range(n + 1)] for i in range(2, 10**7 + 1): if prime[i]: prefixsumprime[i] = prefixsumprime[i - 1] + 1 else: prefixsumprime[i] = prefixsumprime[i - 1] return prefixsumprime prefixsumprime = SieveOfEratosthenes(10**7) for _ in range(int(input())): n = int(input()) if n <= 3: print(n - 1) else: print(prefixsumprime[n] - prefixsumprime[n // 2] + 1)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(2 * p, n + 1, p): prime[i] = False p += 1 prime[0] = False prime[1] = False return prime primes = SieveOfEratosthenes(10**7 + 5) count_1 = 0 pricount = [0] for i in range(1, 10**7 + 6): if primes[i]: count_1 += 1 pricount.append(count_1) for i in range(int(input())): n = int(input()) j = 0 x = 1 y = 1 count = 0 if n == 2: print(1) continue elif n == 3: print(2) continue print(pricount[n] - pricount[n // 2] + 1)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(N): prime = [(True) for i in range(N + 1)] prime[0] = prime[1] = 0 p = 2 while p * p <= N: if prime[p] == True: for i in range(p * p, N + 1, p): prime[i] = False p += 1 return prime def pre(): p1 = SieveOfEratosthenes(10**7 + 1) prime = [None] * (10**7 + 1) c = 0 for i in range(10**7 + 1): if p1[i]: c += 1 prime[i] = c return prime t = int(input()) prime = pre() for i in range(1, t + 1): n = int(input()) if n == 2: print(1) continue elif n == 3: print(2) continue groups = 1 + prime[n] - prime[n // 2] print(groups)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
lim = 10000000 util = [0] * 10000001 def helper(): isp = [True] * 10000001 i = 2 while i * i <= lim: if isp[i] == True: j = i * 2 while j <= lim: isp[j] = False j += i i += 1 util[0] = 0 util[1] = 0 i = 2 while i <= lim: util[i] = util[i - 1] if isp[i]: util[i] += 1 i += 1 helper() t = int(input()) while t > 0: n = int(input()) if n == 2: print(1) elif n == 3 or n == 4: print(2) else: mid = n // 2 res = util[n] - util[mid] print(res + 1) t -= 1
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def seive(n): prefix_ar = [(0) for i in range(n + 1)] ls = [(True) for i in range(n + 1)] ls[0] = False ls[1] = False for i in range(2, n + 1): val = ls[i] if i * i <= n + 1: if val == True: for j in range(i * i, n + 1, i): if j % i == 0: ls[j] = False else: break for i in range(1, n + 1): val = ls[i] if val == True: prefix_ar[i] = prefix_ar[i - 1] + 1 else: prefix_ar[i] = prefix_ar[i - 1] return prefix_ar n = 10**7 + 1 prefix_ar = seive(n) T = int(input()) mx = 0 ls = [] for _ in range(T): i = int(input()) if i == 2: print(1) continue if i == 3: print(2) continue print(1 + prefix_ar[i] - prefix_ar[i // 2])
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def sieve(arr, primes, m): for i in range(2, m + 1): arr[i] = arr[i - 1] if primes[i]: arr[i] += 1 for j in range(2 * i, m + 1, i): primes[j] = 0 t = int(input()) n = [] m = 0 for i in range(t): n.append(int(input())) m = max(n[-1], m) arr = [0] * (m + 1) primes = [1] * (m + 1) primes[0], primes[1] = 0, 0 sieve(arr, primes, m) for i in range(t): print(arr[n[i]] - max(1, arr[n[i] // 2]) + 1)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
try: def sieve_of_eratosthenes(): A = [0, 1] pr = 0 j = int(10000000.0 + 1) prime = [(True) for i in range(j + 1)] B = [] p = 2 while p * p <= j: if prime[p]: for i in range(p * p, j + 1, p): prime[i] = False p += 1 for p in range(2, j + 1): if prime[p]: pr += 1 A.append(pr) return A arr = sieve_of_eratosthenes() for _ in range(int(input())): N = int(input()) print(arr[N] - arr[int(N / 2)] + 1) except: pass
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
N = int(10000000.0 + 2) def sieve(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0] = False prime[1] = False return prime prime = sieve(N) def pre_count(prime): prefix_prime = [] count = 0 for i in range(N + 1): if prime[i]: count += 1 prefix_prime.append(count) return prefix_prime prefix_prime = pre_count(prime) t = int(input()) for _ in range(t): n = int(input()) if n == 2: print(1) elif n == 3: print(2) else: lim = int(n / 2) extra = prefix_prime[n] - prefix_prime[lim] print(extra + 1)
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
try: def seivelist(n): a = [0] * (n + 1) sqrtn = int(n**0.5) curprime = 2 primesprefixsum = [0] * (n + 1) nextprime = 2 while curprime <= sqrtn: j = 2 curprime = nextprime primemul = curprime * j while primemul < n + 1: a[primemul] = -1 j += 1 primemul = j * curprime for i in range(curprime + 1, sqrtn + 1): if a[i] == 0: nextprime = i break if nextprime == curprime: break for i in range(2, n + 1): primesprefixsum[i] = primesprefixsum[i - 1] if a[i] == 0: primesprefixsum[i] += 1 return primesprefixsum maxn = -1 a = [] for _ in range(int(input())): n = int(input()) a.append(n) maxn = max(n, maxn) pps = seivelist(maxn) for n in a: ans = pps[n] - pps[n // 2] + 1 if n < 4: ans -= 1 print(ans) except EOFError: pass
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
N = int(10000000.0 + 1) prime = [(True) for i in range(N + 1)] prefix = [0] * (N + 2) def siev(): p = 2 while p * p <= N: if prime[p] == True: for i in range(p * p, N + 1, p): prime[i] = False p += 1 def func(): prefix[2] = 1 prefix[3] = 2 prefix[4] = 2 count = 2 for p in range(5, N + 1): if prime[p]: count += 1 elif p % 2 == 0 and prime[p // 2]: count -= 1 prefix[p] = count siev() func() for _ in range(int(input())): n = int(input()) print(prefix[n])
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p]: for i in range(p * p, n + 1, p): prime[i] = False p += 1 return prime def func(): MAX = 10**7 + 1 prime = SieveOfEratosthenes(MAX) prefix_arr = [0, 0] for i in range(2, MAX): if prime[i]: prefix_arr.append(prefix_arr[-1] + 1) else: prefix_arr.append(prefix_arr[-1]) return prefix_arr prefix_arr = func() for _ in range(int(input())): N = int(input()) if N <= 3: print(prefix_arr[N]) else: print(prefix_arr[N] - prefix_arr[N // 2] + 1)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
limit = 10000000 arr = [True] * (limit + 1) arr[0] = arr[1] = False for i in range(int(limit**0.5)): if arr[i]: for j in range(i * 2, len(arr), i): arr[j] = False primes = [] j = 0 for i in range(len(arr)): if arr[i]: j += 1 primes.append(j) for i in range(int(input())): n = int(input()) if n < 4: print(primes[n] - primes[n // 2 - 1]) continue print(primes[n] - primes[n // 2] + 1)
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
t = int(input()) def SieveOfEratosthenes(n): prime = [(1) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == 1: for i in range(p * p, n + 1, p): prime[i] = 0 p += 1 return prime c = SieveOfEratosthenes(10**7 + 1) for i in range(3, len(c) // 2): if c[i] == 1: c[2 * i] = -1 c[i] = 1 for i in range(3, len(c)): c[i] += c[i - 1] for i in range(t): n = int(input()) h = 0 print(c[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def buildPrime(): prime = [1] * (MAXIMUM + 1) p = 2 while p * p <= MAXIMUM: if prime[p] == 1: i = p * 2 while i <= MAXIMUM: prime[i] = 0 i += p p += 1 for p in range(2, MAXIMUM + 1): prefix[p] = prefix[p - 1] if prime[p] == 1: prefix[p] += 1 def answer(Left, Rright): return prefix[Rright] - prefix[Left - 1] MAXIMUM = 10000000 prefix = [0] * (MAXIMUM + 1) buildPrime() t = int(input()) for case in range(t): n = int(input()) if n < 4: print(answer(n // 2 + 1, n)) else: print(1 + answer(n // 2 + 1, n))
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def primeNumbers(): prime[0] = prime[1] = False i = 2 while i * i < n: if prime[i]: j = i * i while j <= n: prime[j] = False j += i i += 1 def pre(): count = 0 for i in range(1, n + 1): if prime[i]: count += 1 prefix[i] = count def totalComponents(m): if 2 <= m <= 3: return m - 1 return prefix[m] - prefix[m // 2] + 1 t = int(input()) a = [0] * t for i in range(t): a[i] = int(input()) n = max(a) prime = [True] * (n + 1) prefix = [0] * (n + 1) primeNumbers() pre() for i in range(t): print(totalComponents(a[i]))
FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_DEF IF NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
from itertools import accumulate max = 10000000 sieve = [(1) for i in range(max + 1)] sieve[0], sieve[1] = 0, 0 p = 2 while p * p <= max: if sieve[p]: for i in range(p * p, max + 1, p): sieve[i] = False p += 1 prime = list(accumulate(sieve)) t = int(input()) for _ in range(t): n = int(input()) if n == 2: print(1) elif n == 3: print(2) else: print(1 + prime[n] - prime[n // 2])
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
from itertools import accumulate n = 10000000 prime = [(1) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p]: for i in range(p * p, n + 1, p): prime[i] = False p += 1 prime[0] = 0 prime[1] = 0 prime_number = list(accumulate(prime)) for testcase in range(int(input())): n = int(input()) if n == 2: print(1) elif n == 3: print(2) else: print(1 + prime_number[n] - prime_number[n // 2])
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 c = 0 prefix = [(0) for jk in range(n)] for p in range(2, n): if prime[p]: c += 1 prefix[p] = c return prefix x = SieveOfEratosthenes(int(10000000.0 + 2)) for t in range(int(input())): N = int(input()) if N == 2: print("1") elif N == 3: print("2") else: l = int(N / 2) tot = x[N] - x[l] print(tot + 1)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(n, d): c = 0 prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 return prime b = [] d = {} b = SieveOfEratosthenes(10000001, d) p = 0 for i in range(2, 10000001): if b[i] == True: p += 1 d[i] = p t = int(input()) for test in range(t): n = int(input()) c = 0 if n == 2: print(1) elif n == 3: print(2) else: c = 0 x = 0 z = n // 2 for i in range(n, z, -1): if b[i] == True: x = d[i] break for i in range(z, 1, -1): if b[i] == True: c = d[i] break print(x - c + 1)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
prime = [(True) for i in range(10000001)] p = 2 while p * p < 10000001: if prime[p] == True: for i in range(p * p, 10000001, p): prime[i] = False p += 1 tpr = 0 tprime = [] for i in range(2, 10000001): if prime[i]: tpr += 1 tprime.append(tpr) for _ in range(int(input())): n = int(input()) start = tprime[n // 2 - 2] end = tprime[n - 2] if n == 2: print(1) elif n == 3: print(2) else: print(end - start + 1)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
from itertools import accumulate primes = [(1) for _ in range(pow(10, 7) + 1)] primes[0], primes[1] = 0, 0 for num in range(2, 4 * pow(10, 3)): if primes[num] == 1: for x in range(2 * num, pow(10, 7) + 1, num): primes[x] = 0 primes[2] = 0 prime_cnt = list(accumulate(primes)) for _ in range(int(input())): n = int(input()) print(prime_cnt[n] - prime_cnt[n // 2] + 1)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
N = 10000002 prime = [True] * (N + 1) prefixsum = [0] * (N + 1) def sieve(): prime[0] = prime[1] = False i = 2 while i * i < N: if prime[i]: for j in range(i * i, N + 1, i): prime[j] = False i += 1 def pref(): cnt = 0 for i in range(1, N + 1): if prime[i]: cnt += 1 prefixsum[i] = cnt sieve() pref() t = int(input()) while t: n = int(input()) if n == 2: print(1) elif n == 3: print(2) else: print(1 + prefixsum[n] - prefixsum[n // 2]) t -= 1
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def seive(n): prefix_ar = [(0) for i in range(n + 1)] ls = [(True) for i in range(n + 1)] ls[0] = False ls[1] = False for i in range(2, n + 1): val = ls[i] if i * i <= n + 1: if val == True: for j in range(i * i, n + 1, i): if j % i == 0: ls[j] = False else: break for i in range(1, n + 1): val = ls[i] if val == True: prefix_ar[i] = prefix_ar[i - 1] + 1 else: prefix_ar[i] = prefix_ar[i - 1] return prefix_ar def fun(lx, mx): n = mx prefix_ar = seive(n) for i in lx: if i == 2: print(1) continue if i == 3: print(2) continue print(1 + prefix_ar[i] - prefix_ar[i // 2]) T = int(input()) mx = 0 ls = [] for _ in range(T): n = int(input()) ls.append(n) mx = max(mx, n) fun(ls, mx)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
query = [] for _ in range(int(input())): query.append(int(input())) n = max(query) prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 dp = [(0) for j in range(n + 1)] dp[1], dp[2] = 1, 1 for j in range(3, n + 1): if prime[j]: dp[j] = dp[j - 1] + 1 else: dp[j] = dp[j - 1] for j in query: print(dp[j] - dp[j // 2] + 1)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def SieveOfEratosthenes(n): prime = [(True) for i in range(n + 1)] p = 2 while p * p <= n: if prime[p] == True: for i in range(p * p, n + 1, p): prime[i] = False p += 1 li = [0, 0] x = 0 for i in range(2, n): if prime[i]: x += 1 li.append(x) return li li = SieveOfEratosthenes(10**7 + 1) t = int(input()) while t > 0: t = t - 1 ans = 1 n = int(input()) if n == 2: print(1) elif n == 3: print(2) else: print(li[n] - li[n // 2] + 1)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def prime(n): i = 2 global l while i * i < n: if arr[i] == True: for j in range(i * i, n, i): arr[j] = False i += 1 count = 0 for i in range(2, n): if arr[i]: count += 1 prime_count[i] = count n = 10**7 + 1 arr = [True] * n prime_count = [0] * n prime(n) t = int(input()) while t: N = int(input()) if N == 2: print(1) elif N == 3: print(2) else: print(prime_count[N] - prime_count[N // 2] + 1) t -= 1
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
prime = [True] * int(10000000.0 + 2) prime[0] = prime[1] = False prefix_prime = [0] def sieve(N=int(10000000.0 + 1)): N = N + 1 i = 2 while i * i < N: if prime[i]: for j in range(i**2, N, i): prime[j] = False i += 1 sieve() def precount_prime(): count = 0 for i in range(1, int(10000000.0 + 1)): if prime[i]: count += 1 prefix_prime.append(count) precount_prime() for _ in range(int(input())): N = int(input()) if N == 2: print(1) elif N == 3: print(2) else: f = 1 + prefix_prime[N] - prefix_prime[N // 2] print(f)
ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
from sys import stdin, stdout input = stdin.readline def im(): return map(int, input().split()) def ii(): return int(input()) def il(): return list(map(int, input().split())) def ins(): return input()[:-1] N = int(10000000.0) + 5 prime = [1] * N prime[0] = prime[1] = 0 i = 2 while i * i < N: if prime[i] == 1: for j in range(i * i, N, i): prime[j] = 0 i += 1 prime[3] = 2 for i in range(4, N): prime[i] += prime[i - 1] for _ in range(ii()): n = ii() if n == 2: print(1) elif n == 3: print(2) else: print(prime[n] - prime[n // 2] + 1)
ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
try: MAX = 10000000 prefix = [0] * (MAX + 1) def buildPrefix(): prime = [1] * (MAX + 1) p = 2 while p * p <= MAX: if prime[p] == 1: i = p * 2 while i <= MAX: prime[i] = 0 i += p p += 1 for p in range(2, MAX + 1): prefix[p] = prefix[p - 1] if prime[p] == 1: prefix[p] += 1 def query(L, R): return prefix[R] - prefix[L - 1] buildPrefix() for t in range(int(input())): N = int(input()) if N == 2: print(1) continue primes = query(N // 2 + 1, N) if primes == N - 1: print(primes) else: print(1 + primes) except: pass
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
def sieve(n): l = [(True) for i in range(n + 1)] l[0], l[1] = False, False for i in range(2, int(n**0.5) + 1): if l[i] == True: for i in range(i * i, n + 1, i): l[i] = False return l r = sieve(10**7 + 2) c, l = 0, [] for i in range(0, 10**7 + 1): if r[i] == True: c += 1 l.append(c) for _ in range(int(input())): n = int(input()) if n == 2: print(1) elif n == 3: print(2) else: print(1 + l[n] - l[n // 2])
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
t = int(input()) big = 10**7 + 1 l = [(1) for i in range(big + 1)] l[0] = l[1] = 0 for i in range(2, int(big ** (1 / 2) + 1)): if l[i]: for j in range(i * i, big, i): l[j] = 0 c = 0 a = [(0) for i in range(big + 1)] for i in range(big + 1): if l[i] == 1: c += 1 a[i] = c for co in range(t): q = int(int(input())) v = q // 2 if q == 2: print(1) elif q == 3: print(2) else: print(a[q] - a[v] + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
n = 10**7 seive = [False] * (n + 1) seive[0], seive[1] = True, True p = 2 while p * p <= n: if seive[p] == False: for i in range(p * p, len(seive), p): seive[i] = True p += 1 def is_prime(n): return not seive[n] table = [0] * (n + 1) table[2] = 1 for i in range(2, len(table)): if is_prime(i): table[i] = table[i - 1] + 1 else: table[i] = table[i - 1] def solve(n): l = [1, 2, 2, 3] if n < 6: return l[n - 2] else: return table[n] - table[n // 2] + 1 t = int(input()) for tc in range(t): n = int(input()) print(solve(n))
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FUNC_DEF RETURN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER RETURN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given all $N - 1$ integers in the range $[2, N]$. In each step, you choose $2$ distinct integers and if they share a common factor greater than $1$, you combine them into the same group. You keep doing it until no further merging is possible. Belonging to a group is an equivalence relation. So if integers $a$ and $b$ are in the same group and integers $b$ and $c$ are in the same group, then integers $a$ and $c$ are also said to be in the same group. Find the total number of groups formed in the end. ------ Input ------ First line will contain $T$, number of test cases. Then the test cases follow. Each test case contains a single line of input, a single integer $N$. ------ Output ------ For each test case, output in a single line the answer to the problem. ------ Constraints ------ $1 ≀ T ≀ 2\cdot 10^{5}$ $2 ≀ N ≀ 10^{7}$ ------ Subtasks ------ Subtask #1 (30 points): $1 ≀ T ≀ 200$ $2 ≀ N ≀ 1000$ Subtask #2 (70 points): original constraints ----- Sample Input 1 ------ 3 2 4 8 ----- Sample Output 1 ------ 1 2 3 ----- explanation 1 ------ Test Case $1$: The final group is $\{2\}$. Test Case $2$: The final groups are $\{2, 4\}$, and $\{3\}$. Test Case $3$: The final groups are $\{2, 3, 4, 6, 8\}$, $\{5\}$, and $\{7\}$.
t = int(input()) l = [0] * (10**7 + 1) def seive(maxi): prime = [(True) for i in range(maxi + 1)] p = 2 c = 0 while p * p <= maxi: if prime[p] == True: for i in range(p * p, maxi + 1, p): prime[i] = False p += 1 for p in range(2, maxi + 1): if prime[p]: c += 1 l[p] = c seive(10**7) for _ in range(t): n = int(input()) if n <= 3: print(n - 1) else: ans = l[n] - l[n // 2] + 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
"It does not matter how slowly you go as long as you do not stop." - Confucius You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$): - Let's define an array $B$ as $S$ concatenated with itself $m$ times, where $m$ is the smallest integer such that $m(r-l+1) \ge K$. - Next, let's sort $B$ and define $X = B_K$, i.e. as a $K$-th smallest element of $B$. Note that $|B| \ge K$. - Then, let's define $F$ as the number of occurrences of $X$ in $S$. - The subarray $S$ is beautiful if $F$ occurs in $S$ at least once. Find the number of beautiful subarrays of $A$. Two subarrays $A_l, A_{l+1}, \ldots, A_r$ and $A_p, A_{p+1}, \ldots, A_q$ are different if $l \neq p$ or $r \neq q$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer - the number of beautiful subarrays. -----Constraints----- - $1 \le T \le 5$ - $1 \le N \le 2,000$ - $1 \le K \le 10^9$ - $1 \le A_i \le 2000$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): $1 \le N \le 200$ Subtask #2 (80 points): original constraints -----Example Input----- 1 3 3 1 2 3 -----Example Output----- 3 -----Explanation----- Example case 1: There are six subarrays of $A$: $[1]$, $[2]$, $[3]$, $[1, 2]$, $[2, 3]$, $[1, 2, 3]$. The corresponding arrays $B$ are $[1, 1, 1]$, $[2, 2, 2]$, $[3, 3, 3]$, $[1, 2, 1, 2]$, $[2, 3, 2, 3]$, $[1, 2, 3]$. Three of the subarrays are beautiful: $[1]$, $[1, 2]$ and $[1, 2, 3]$. For these subarrays, $X$ is $1$, $2$ and $3$ respectively (for example, for $S = [1, 2]$, $B = [1, 2, 1, 2]$ is sorted to $[1, 1, 2, 2]$ and $X = 2$ is the $3$-rd element). Then, $F = 1$ for each of these subarrays, and each of these subarrays contains $1$.
def division(a, b): if a % b == 0: return a // b return a // b + 1 test = int(input()) for _ in range(test): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] res = 0 p = [] for i in range(n): p.append(division(k, division(k, i + 1)) - 1) for i in range(n): if a[i] == 1: res += 1 inarr = [0] * 2001 inarr[a[i]] = 1 arr = [] o = a[i] nop = 1 for j in range(i + 1, n): inarr[a[j]] += 1 c = p[j - i] - p[j - i - 1] if a[j] < o: c -= 1 if c == -1: nop -= 1 if nop == 0: q = o - 1 while inarr[q] == 0: q -= 1 o = q nop = inarr[o] else: while c: c -= 1 nop += 1 if nop > inarr[o]: q = o + 1 while inarr[q] == 0: q += 1 o = q nop = 1 if inarr[inarr[o]] != 0: res += 1 print(res)
FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
"It does not matter how slowly you go as long as you do not stop." - Confucius You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$): - Let's define an array $B$ as $S$ concatenated with itself $m$ times, where $m$ is the smallest integer such that $m(r-l+1) \ge K$. - Next, let's sort $B$ and define $X = B_K$, i.e. as a $K$-th smallest element of $B$. Note that $|B| \ge K$. - Then, let's define $F$ as the number of occurrences of $X$ in $S$. - The subarray $S$ is beautiful if $F$ occurs in $S$ at least once. Find the number of beautiful subarrays of $A$. Two subarrays $A_l, A_{l+1}, \ldots, A_r$ and $A_p, A_{p+1}, \ldots, A_q$ are different if $l \neq p$ or $r \neq q$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer - the number of beautiful subarrays. -----Constraints----- - $1 \le T \le 5$ - $1 \le N \le 2,000$ - $1 \le K \le 10^9$ - $1 \le A_i \le 2000$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): $1 \le N \le 200$ Subtask #2 (80 points): original constraints -----Example Input----- 1 3 3 1 2 3 -----Example Output----- 3 -----Explanation----- Example case 1: There are six subarrays of $A$: $[1]$, $[2]$, $[3]$, $[1, 2]$, $[2, 3]$, $[1, 2, 3]$. The corresponding arrays $B$ are $[1, 1, 1]$, $[2, 2, 2]$, $[3, 3, 3]$, $[1, 2, 1, 2]$, $[2, 3, 2, 3]$, $[1, 2, 3]$. Three of the subarrays are beautiful: $[1]$, $[1, 2]$ and $[1, 2, 3]$. For these subarrays, $X$ is $1$, $2$ and $3$ respectively (for example, for $S = [1, 2]$, $B = [1, 2, 1, 2]$ is sorted to $[1, 1, 2, 2]$ and $X = 2$ is the $3$-rd element). Then, $F = 1$ for each of these subarrays, and each of these subarrays contains $1$.
def ceil(x, y): if x % y: return x // y + 1 else: return x // y MAX = 2001 t = int(input()) for t_i in range(t): N, K = map(int, input().split()) Arr = list(map(int, input().split())) res = 0 count_list = [None] * MAX for i in range(N): for value in range(MAX): count_list[value] = 0 max_item = Arr[i] current_item = Arr[i] current_item_dis = 0 for j in range(i, N): size = j - i + 1 new_pos = ceil(K, ceil(K, size)) new_item = Arr[j] count_list[new_item] += 1 if new_item > max_item: max_item = new_item if size == new_pos: current_item = max_item current_item_dis = count_list[max_item] - 1 elif new_item < current_item: if current_item_dis: current_item_dis -= 1 else: current_item -= 1 while not count_list[current_item]: current_item -= 1 current_item_dis = count_list[current_item] - 1 if count_list[count_list[current_item]]: res += 1 print(res)
FUNC_DEF IF BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has a sequence A_{1}, A_{2}, \ldots, A_{N}. Let's call a contiguous subsequence of A a *segment*. A segment is *good* if it can be divided into at most K segments such that the sum of elements in each of these sub-segments is at most S. You need to find the maximum number of elements in a good segment. ------ Input Format ------ - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains three space-separated integers N, K and S. - The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer β€” the maximum length of a good segment. ------ Constraints ------ $1 ≀T ≀150,000$ $1 ≀K ≀N ≀10^{5}$ $1 ≀S ≀10^{9}$ $1 ≀A_{i} ≀S$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $10^{6}$ ------ subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 2 5 2 5 1 3 2 1 5 5 3 5 5 1 5 1 1 ----- Sample Output 1 ------ 4 4 ----- explanation 1 ------ Example case 1: One of the segments with length $4$ is $[1, 3, 2, 1]$. It can be divided into two segments $[1, 3]$ and $[2, 1]$ whose sums are at most $S = 5$.
def solver(): suf = list(range(N + 1)) right = total = 0 for i in range(N): while right < N and total + arr[right] <= S: total += arr[right] right += 1 suf[i] = right if right > i: total -= arr[i] else: right += 1 ans = list(range(N + 1)) for i in range(20): if K >> i & 1: for j in range(N): ans[j] = suf[ans[j]] for k in range(N): suf[k] = suf[suf[k]] return max(map(lambda x: ans[x] - x, range(N))) T = int(input()) for t in range(T): N, K, S = map(int, input().split()) arr = list(map(int, input().split())) print(solver())
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has a sequence A_{1}, A_{2}, \ldots, A_{N}. Let's call a contiguous subsequence of A a *segment*. A segment is *good* if it can be divided into at most K segments such that the sum of elements in each of these sub-segments is at most S. You need to find the maximum number of elements in a good segment. ------ Input Format ------ - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains three space-separated integers N, K and S. - The second line contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}. ------ Output Format ------ For each test case, print a single line containing one integer β€” the maximum length of a good segment. ------ Constraints ------ $1 ≀T ≀150,000$ $1 ≀K ≀N ≀10^{5}$ $1 ≀S ≀10^{9}$ $1 ≀A_{i} ≀S$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $10^{6}$ ------ subtasks ------ Subtask #1 (100 points): original constraints ----- Sample Input 1 ------ 2 5 2 5 1 3 2 1 5 5 3 5 5 1 5 1 1 ----- Sample Output 1 ------ 4 4 ----- explanation 1 ------ Example case 1: One of the segments with length $4$ is $[1, 3, 2, 1]$. It can be divided into two segments $[1, 3]$ and $[2, 1]$ whose sums are at most $S = 5$.
def build(N, start_index): up = [([None] * N) for _ in range(20)] up[0] = start_index for i in range(1, 20): for j in range(N): p = up[i - 1][j] if p == -1: up[i][j] = -1 else: up[i][j] = up[i - 1][p] return up def call(up, node, K): last, jump = node, 1 for i in range(19): if node == -1: break if K & jump: node = up[i][node] jump <<= 1 return last - node def solve(nums, N, K, S): start_index, j, curr = [], 0, 0 for i in range(N): curr += nums[i] while curr > S: curr -= nums[j] j += 1 start_index.append(j - 1) up = build(N, start_index) res = 0 for i in range(N - 1, -1, -1): res = max(res, call(up, i, K)) return res T = int(input()) for _ in range(T): N, K, S = tuple(map(int, input().split())) nums = list(map(int, input().split())) print(solve(nums, N, K, S))
FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = input().split() k, d, t = int(k), int(d), int(t) time = 0 if True: m = int((k - 1) / d) * d + d - k tc = k + 0.5 * m ta = k + m l = int(t / tc) time = ta * l if k > t - l * tc: time += t - l * tc else: time += k time += 2 * (t - l * tc - k) print(time)
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) a = 2 * k + (k + d - 1) // d * d - k q, r = divmod(2 * t, a) T = q * ((k + d - 1) // d * d) if 0 <= r <= 2 * k: T += r / 2 else: T += k + (r - 2 * k) print(T)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0: print(t) else: if d >= k: gap = d - k else: gap = (k // d + 1) * d - k rd = k + gap / 2 tt = k + gap ans = t // rd * tt rem = t - t // rd * rd if k >= rem: ans += rem else: ans += k rem -= k ans += rem * 2 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = list(map(float, input().split())) if k >= t: print(t) exit(0) if k % d == 0: print(t) exit(0) d = k - k % d + d ans = 1.0 // (k / t + (d - k) / (2 * t)) * d w = 1.0 % (k / t + (d - k) / (2 * t)) if w <= k / t: ans += w * t else: w = 1.0 % (k / t + (d - k) / (2 * t)) w -= k / t ans += k ans += 2 * w * t print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) nocooking = (d - k % d) % d cycle = k + nocooking percyc = 2 * k + nocooking goal = 2 * t minutes = goal // percyc * cycle goal = goal % percyc if goal > 2 * k: minutes += k minutes += goal - 2 * k else: minutes += goal / 2 print(minutes)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
s = ["3", "2", "6"] def chef(s): s = list(map(int, s)) k, n, t = s[0], s[1], s[2] b = n if k % b == 0 or k >= t: return t if k > b: y = int(k / b + 1) * b b = y m = 0 i = 0 u = 1 / (k / t + (b - k) / (2 * t)) i += int(u) * b m += int(u) * (k / t + (b - k) / (2 * t)) if float("{0:.10f}".format(u)) == 0: return i z = 1 - m if z < k / t: h = z * t i += h else: h = (z - k / t) * (2 * t) i += h + k ans = i return ans def main(): s = input().split() print(chef(s)) main()
ASSIGN VAR LIST STRING STRING STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR RETURN VAR IF VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
def solve(k, d, t): q, r = divmod(k, d) up = d - r if r != 0 else 0 perblock2 = k * 2 + up qt, rt = divmod(2 * t, perblock2) if rt <= k * 2: extra = rt / 2 else: extra = rt - k return (k + up) * qt + extra k, d, t = [int(v) for v in input().split()] print(solve(k, d, t))
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = (int(x) for x in input().split()) if d >= k: chunksize = d chunkspeed = k + (d - k) / 2 else: if k % d == 0: chunksize = k else: chunksize = (k // d + 1) * d chunkspeed = k + (chunksize - k) / 2 chunks = int(t / chunkspeed) ans = chunksize * chunks rem = t - chunkspeed * chunks if rem <= k: ans += rem else: ans += k rem -= k ans += rem * 2 print(f"{ans:f}")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) w = t * 2 period = (k + d - 1) // d * d slow_per_period = (d - k % d) % d period_w = slow_per_period + (period - slow_per_period) * 2 n_periods = w // period_w remaining_w = w % period_w remaining_time = 0 if remaining_w <= (period - slow_per_period) * 2: remaining_time = remaining_w / 2 else: slow_remaining_w = remaining_w - (period - slow_per_period) * 2 remaining_time = period - slow_per_period + slow_remaining_w print(n_periods * period + remaining_time)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) t *= 2 if k > d: if k % d == 0: d = k else: d = (k // d + 1) * d q = d + k ans = t // q * d t %= q if t <= 2 * k: print(t / 2 + ans) else: print(ans + t - k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) d = (k + d - 1) // d * d T = 2 * t z = T // (k + d) fullTime = z * d rest = T - z * (k + d) t1 = 2 * k if rest <= t1: fullTime += rest / 2 else: fullTime += k + (rest - t1) print(fullTime)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split(" ")) nm = 0 if k % d != 0: p = (k // d + 1) * d a = k b = p - k ans = (2 * a + b) / (2 * t) tp = 2 * t // (2 * a + b) nm += tp * p if (2 * a + b) * tp + 2 * a >= 2 * t: z = ans * tp print(nm + (1 - z) * t) else: z = ans * tp + a / t print(nm + a + (1 - z) * 2 * t) else: print(t)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = [int(x) for x in input().split()] n = 0 n = int(k / d) if n * d == k: n -= 1 cycle_len = (n + 1) * d num_cycles = int(2 * t / ((n + 1) * d + k)) remaining_minutes = t - num_cycles * (k + ((n + 1) * d - k) / 2) if remaining_minutes < k: print(num_cycles * cycle_len + remaining_minutes) else: print(num_cycles * cycle_len + k + (remaining_minutes - k) * 2)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) a = d - k % d if a == d: a = 0 b = k + a / 2 ans = 0 ans += t // b * (k + a) t = t % b if t <= k: ans += t else: ans += k + (t - k) * 2 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k >= t or k % d == 0: print(t) exit() if d < k: dd = d * (k // d) d = dd + d no_of_cycles = 2 * t // (k + d) cooked = no_of_cycles * (k + d) / (2 * t) remaining = 1 - cooked ans = no_of_cycles * d if remaining <= k / t: ans += remaining * t else: remaining -= k / t ans += k ans += remaining * 2 * t print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0: d = int(k / d) * d else: d = (int(k / d) + 1) * d tme = k + (d - k) / 2 ans = int(t / tme) * d elap = int(t / tme) * tme if t - elap < k: ans += t - elap else: ans += k + (t - elap - k) * 2 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k >= t or k % d == 0: print(t) exit() x = d - k % d num = 2 * t // (2 * k + x) rem = t - num * (k + x / 2) ans = (k + x) * num if rem + 1e-10 <= k: ans += rem else: ans += k + (rem - k) * 2 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) d = (k + d - 1) // d * d def f(tp): r = 0 dd = int(tp) // d tp -= d * dd r += (d + k) / (2 * t) * dd if tp <= k: r += tp / t else: r += k / t r += (tp - k) / (2 * t) return r L = 0 R = 2e18 ITR = 1000 for _ in range(ITR): M = (L + R) / 2.0 if f(M) >= 1.0: R = M else: L = M print("{:.10f}".format(L))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k1, d, t = [int(x) for x in input().split()] k2 = int(k1 / d) if k1 % d: k2 += 1 k2 = d * k2 - k1 c = int(t / (k1 + k2 / 2)) ans = c * (k1 + k2) l = c * (k1 + k2 / 2) t -= l if t > k1: ans += k1 t -= k1 ans += t * 2 else: ans += t print("%.9f" % ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = [int(i) for i in input().split()] t = 2 * t if d >= k: s = 2 * k + (d - k) tt = k + (d - k) if s >= t: if 2 * k >= t: print(t // 2) exit(0) else: print(k + 2 * (t // 2 - k)) exit(0) h = t // s x = t % s if x <= 2 * k: print(h * tt + x / 2) else: print(h * tt + k + (x - 2 * k)) else: last = 0 if k % d == 0: last = k else: last = k - k % d + d s = 2 * k + (last - k) tt = k + (last - k) if s >= t: if 2 * k >= t: print(t // 2) exit(0) else: print(k + 2 * (t // 2 - k)) exit(0) h = t // s x = t % s if x <= 2 * k: print(h * tt + x / 2) else: print(h * tt + k + (x - 2 * k))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
def solve(): k, d, t = [int(x) for x in input().split()] if k >= d and k % d == 0: print(t) return elif k > d: d = k // d * d + d N = 2 * t // (k + d) x = N * (d + k) / (2 * t) if x + k / t >= 1: y = t - N * (d + k) / 2 res = N * d + y else: y = 2 * t - N * (d + k) - 2 * k res = N * d + y + k print(res) solve()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = list(map(int, input().split())) inef_time = 2 * t if k % d == 0: print(t) exit() cycle_len = d * (k // d + 1) full_cycles_effective_time = k + cycle_len cycles_count = inef_time // full_cycles_effective_time cycle_remnants = inef_time % full_cycles_effective_time total_time = cycle_len * cycles_count if cycle_remnants > 2 * k: total_time += k + (cycle_remnants - 2 * k) else: total_time += cycle_remnants / 2 print(total_time)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0: print(t) exit() r = k % d ot = (d - r) / 2 ot += k ct = k + (d - r) cn = int(t // ot) ans = cn * ct rt = t - cn * ot if rt < k: ans += rt else: ans += k rt -= k ans += rt * 2 ans = "%.10f" % float(ans) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
def get_time(T, k, d): e = -(k % d) if e < 0: e += d C = k + e con = T // C * k + min(T % C, k) coff = T // C * e + T % C - min(T % C, k) return con + coff / 2 k, d, t = map(int, input().split()) l = 1 r = 10**25 while l <= r: g = (l + r) / 2 tmp = get_time(g, k, d) if abs(tmp - t) < 10**-9: print(g) break if tmp < t: l = g else: r = g
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = [int(x) for x in input().split()] if d >= k: off1 = d - k elif k % d == 0: off1 = 0 else: off1 = d - k % d reptime = k + off1 / 2 times = t // reptime trest = t - times * reptime sol = times * (k + off1) if trest <= k: sol += trest else: sol += k sol += 2 * (trest - k) print("%.8f" % sol)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
wait, cook, warm = 0, 0, 0 k, d, t = map(int, input().split()) if k % d == 0: print(t, ".0", sep="") exit() wait = k - k % d + d cook = k warm = wait - cook cooked = cook * 2 + warm ans = t * 2 // cooked * wait now_cooked = ans // wait * cooked if now_cooked + k * 2 >= t * 2: ans *= 2 ans += t * 2 - now_cooked print(ans / 2) exit() else: now_cooked += k * 2 ans += k ans += t * 2 - now_cooked print(ans)
ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
raws = [int(x) for x in input().split(" ") if x] k, d, t = raws[0], raws[1], raws[2] tp = k // d if k % d > 0: tp += 1 d *= tp rnd2 = 2 * k + (d - k) nd = 2 * t // rnd2 ans = nd * d rest2 = 2 * t % rnd2 if rest2 <= k * 2: ans += rest2 / 2 else: ans += k + (rest2 / 2 - k) * 2 print(ans)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k >= t: print(t) exit() elif k >= d and k % d == 0: print(t) elif d > k: cycle = k + (d - k) / 2 time_percycle = d time = time_percycle * (t // cycle) cooked = t // cycle * cycle time_left = t - cooked if time_left <= k: print(time_left + time) else: time_left -= k print(time + k + 2 * time_left) exit() elif d < k: cycle = k + (k // d + 1) * d % k / 2 time_percycle = (k // d + 1) * d time = time_percycle * (t // cycle) cooked = t // cycle * cycle time_left = t - cooked if time_left <= k: print(time_left + time) else: time_left -= k print(time + k + 2 * time_left)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = list(map(int, input().split())) if k % d == 0: print(t) exit() m = (k + d - 1) // d * d if 2 * t % (m + k) == 0: print(m * 2 * t / (m + k)) exit() n = 2 * t // (m + k) res = n * m f = 1 - (m + k) * n / (2 * t) if f <= k / t: print(res + f * t) else: res += k f -= k / t print(res + f * 2 * t)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0: ans = t elif k < d: comp = k + (d - k) / 2 md = t % comp ans = t // comp * d if md <= k: ans += md else: ans += k + (md - k) * 2 elif k > d: kek = k // d if k % d: kek += 1 dlina = kek * d comp = k + (dlina - k) / 2 md = t % comp ans = t // comp * dlina if md <= k: ans += md else: ans += k + (md - k) * 2 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = input().split() k, d, t = int(k), int(d), int(t) on = k off = d - (k - 1) % d - 1 cycle = on + off / 2 time = (on + off) * (t // cycle) t -= cycle * (t // cycle) if t < k: print(t + time) else: print(time + k + (t - k) * 2)
ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0: print(t) elif k > d: tb = d * (k // d) + d x = tb + k y = tb * (2 * t // x) rem = 2 * t - x * (2 * t // x) if rem == 0: print(y) else: rem = rem / 2 if rem <= k: print(y + rem) else: rem = rem - k print(y + k + 2 * rem) else: x = d + k y = d * (t * 2 // x) rem = 2 * t - x * (t * 2 // x) if rem == 0: print(y) else: rem = rem / 2 if rem <= k: print(y + rem) else: rem = rem - k print(y + k + 2 * rem)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = [int(x) for x in input().split()] a = k % d b = k // d blok = d * (b + (1 if a > 0 else 0)) gm = b * d + a bm = d - a if a != 0 else 0 t_per_blok = gm + 0.5 * bm res = blok * (t // t_per_blok) t = t % t_per_blok res += min(t, gm) t = max(0, t - gm) res += 2 * t print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0: print(t) else: if d > k: p, p1 = d, k else: p = (k // d + 1) * d p1 = k p2 = p - p1 g = 2 * p1 + p2 a1 = 2 * t // g * p a2 = min(2 * t % g / 2, p1) a3 = max(2 * t % g - 2 * p1, 0) print(a1 + a2 + a3)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) l = int(1) r = int(1000000000000000000) while l < r: m = (l + r) // 2 if m * d >= k: r = m else: l = m + 1 ck = d * l peerck = k + (ck - k) / 2.0 l = int(0) r = int(1000000000000000000) while l < r: m = (l + r) // 2 if (r - l) % 2 == 1: m = m + 1 if peerck * m <= t: l = m else: r = m - 1 res = l * ck t = t - peerck * l if k > t: print(res + t) else: print(res + (t - k) * 2 + k)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = map(int, input().split()) if k % d == 0 or k >= t: print(t) else: if k < d: w1 = k w2 = d - k e = w1 / t r = w2 / (2 * t) s = e + r else: w1 = k w2 = d - k % d e = w1 / t r = w2 / (2 * t) s = e + r l = 1.0 // s ans = (w1 + w2) * l v = 1.0 % (e + r) a = 0 if e == v: v -= e print(ans + w1) exit() if e < v: a = w1 v -= e a += v * 2 * t print(ans + a) exit() a = v * t print(ans + a) exit()
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on. During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly. It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off. Input The single line contains three integers k, d and t (1 ≀ k, d, t ≀ 1018). Output Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9. Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if <image>. Examples Input 3 2 6 Output 6.5 Input 4 2 20 Output 20.0 Note In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for <image>. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for <image>. Thus, after four minutes the chicken will be cooked for <image>. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready <image>. In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.
k, d, t = (int(x) for x in input().split()) d_0 = d if k > d: d_0 = d if k % d != 0 else 0 d_0 += k // d * d time = t // (k + (d_0 - k) * 0.5) t -= (k + (d_0 - k) * 0.5) * time if t < k: print(time * d_0 + t) else: print(time * d_0 + k + (t - k) * 2)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
import itertools t = int(input()) for i in range(t): n, k = map(int, input().split()) num = list(map(int, input().split(maxsplit=n))) y = list(itertools.combinations(num, k)) num1 = [] for i in range(len(y)): num1.append(sum(y[i])) print(num1.count(min(num1)))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def fact(n): res = 1 for i in range(1, n + 1): res *= i return res t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) arr.sort() tot = 0 for i in range(k): tot += arr[i] count = 0 for i in range(n): if arr[i] == arr[k - 1]: count += 1 orig_count = 0 for i in range(k): if arr[i] == arr[k - 1]: orig_count += 1 print(fact(count) // (fact(orig_count) * fact(count - orig_count)))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
from itertools import combinations t = int(input()) while t > 0: n, k = map(int, input().split()) y = list(map(int, input().split())) y.sort() k1 = [] for i in range(len(y)): if i > k - 1: if y[i] != k1[-1]: break else: k1.append(y[i]) else: k1.append(y[i]) from itertools import combinations ans = list(combinations(k1, k)) l = [] for i in ans: l.append(sum(i)) print(l.count(min(l))) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def ncr(n, r): c = list() for i in range(0, n + 1): l = list() for j in range(0, r + 1): l.append(0) c.append(l) for i in range(0, n + 1): for j in range(0, min(i, r) + 1): if j == 0 or j == i: c[i][j] = 1 elif j == 1 or j == i - 1: c[i][j] = i else: c[i][j] = c[i - 1][j] + c[i - 1][j - 1] return c[n][r] t = int(input()) for i in range(t): n, k = map(int, input().split()) l = list(map(int, input().split())) l = sorted(l) m = max(l[:k]) m_count = l[:k].count(m) total_count = l.count(m) print(ncr(total_count, m_count))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
comb = [[(0) for i in range(51)] for j in range(51)] for i in range(51): comb[i][0] = 1 for i in range(1, 51): for j in range(1, 51): comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1] test = int(input()) while test > 0: n, k = map(int, input().split()) a = list(map(int, input().split())) a.sort() b = a[:k] print(comb[a.count(b[-1])][b.count(b[-1])]) test -= 1
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
C = [1, 1] for i in range(2, 51): C += [C[-1] * i] for _ in range(int(input())): N, K = [int(i) for i in input().split(" ")] A = [int(i) for i in input().split(" ")] A.sort() B = {} for i in range(N): if A[i] in B: B[A[i]] += 1 else: B[A[i]] = 1 count = 1 for i in B: if K < B[i]: count = C[B[i]] // (C[B[i] - K] * C[K]) break K -= B[i] print(count)
ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def fact(n): res = 1 for i in range(2, n + 1): res = res * i return res def nCr(n, r): return fact(n) / (fact(r) * fact(n - r)) for _ in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) arr = sorted(arr) last_index_of_k = arr[k - 1] count = 0 for i in range(n): if arr[i] == last_index_of_k: count += 1 num = 0 for i in range(k): if arr[i] == last_index_of_k: num += 1 print(int(nCr(count, num)))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
for _ in range(int(input())): n, k = map(int, input().split()) x = sorted(list(map(int, input().split()))) i = x.count(x[k - 1]) j = x[:k].count(x[k - 1]) a = b = 1 for i in range(i - j + 1, i + 1): a *= i for j in range(1, j + 1): b *= j print(a // b)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def fact(n): if n < 2: return 1 return n * fact(n - 1) def ncr(n, r): return fact(n) // (fact(r) * fact(n - r)) t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() count_z = a.count(a[k - 1]) count_z_seq = a[:k].count(a[k - 1]) print(ncr(count_z, count_z_seq))
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def sort(array): new_list = [] for num in array: start = 0 end = len(new_list) while start < end: mid = (start + end) // 2 if new_list[mid] > num: end = mid else: start = mid + 1 new_list.insert(start, num) return new_list tests = int(input()) for _ in range(tests): n, k = [int(j) for j in input().split()] nums = [int(j) for j in input().split()] sorted_nums = sort(nums) value = sorted_nums[k - 1] repeats = 0 for i in range(k): if sorted_nums[i] == value: repeats += 1 size = repeats for i in range(k, n): if sorted_nums[i] == value: size += 1 fact = [(1) for _ in range(size + 1)] for i in range(1, size + 1): fact[i] = i * fact[i - 1] print(fact[size] // (fact[repeats] * fact[size - repeats]))
FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
t = int(input()) while t: n, k = list(map(int, input().split())) a = list(map(int, input().split())) nis = 1 while k: nm = a.count(min(a)) if nm >= k: for i in range(k): nis *= nm - i kf = 1 for i in range(2, k + 1): kf *= i nis /= kf break else: k -= nm a = [x for x in a if x != min(a)] print(int(nis)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def fact(n): if n == 0 or n == 1: return 1 ans = 1 for i in range(2, n + 1): ans *= i return ans def nCr(n, r): return int(fact(n) / (fact(r) * fact(n - r))) t = int(input()) while t: n, k = map(int, input().split()) ele = input().split() arr = [int(j) for j in ele] set_arr = set(arr) count = [] for i in sorted(set_arr): count.append(arr.count(i)) if k < count[0]: print(nCr(count[0], k)) elif k == count[0]: print(1) else: ind = -1 summ = 0 while summ < k: ind += 1 summ += count[ind] req = summ - k print(nCr(count[ind], req)) t -= 1
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
import itertools t = int(input()) for i in range(t): def subset(num, k): return list(itertools.combinations(num, k)) n, k = list(map(int, input().split())) num = list(map(int, input().split())) y = subset(num, k) num1 = [] for i in range(len(y)): num1.append(sum(y[i])) x = min(num1) print(num1.count(x))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
tests = int(input()) for _ in range(tests): n, k = [int(j) for j in input().split()] nums = [int(j) for j in input().split()] sorted_nums = list(nums) sorted_nums.sort() value = sorted_nums[k - 1] repeats = 0 for i in range(k): if sorted_nums[i] == value: repeats += 1 size = repeats for i in range(k, n): if sorted_nums[i] == value: size += 1 fact = [(1) for _ in range(size + 1)] for i in range(1, size + 1): fact[i] = i * fact[i - 1] print(fact[size] // (fact[repeats] * fact[size - repeats]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def gcd(a, b): if b == 0: return a return gcd(b, a % b) def factorial(n, r): p = 1 k = 1 if n - r < r: r = n - r if r != 0: while r: p *= n k *= r y = gcd(p, k) p //= y k //= y n -= 1 r -= 1 return p t = int(input()) for i in range(t): n, k = map(int, input().split()) l = list(map(int, input().split())) l.sort() num = l[k - 1] t = l.count(num) r = l[:k].count(num) print(factorial(t, r))
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def fact(n): if n == 0 or n == 1: return 1 ans = 1 for i in range(2, n + 1): ans *= i return ans def nCr(n, r): return int(fact(n) / (fact(r) * fact(n - r))) for t in range(int(input())): n, k = map(int, input().split()) A = list(map(int, input().split())) A.sort() a = A[:k] if a[-1] == a[0]: temp = A.count(a[0]) if temp > k: print(nCr(temp, k)) else: print(1) else: temp = A.count(a[-1]) if temp > a.count(a[-1]): print(nCr(temp, a.count(a[-1]))) else: print(1)
FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $K$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$.
def fattoriale(n): p = 1 for i in range(2, n + 1): p *= i return p tests = int(input()) for _ in range(tests): N, K = map(int, input().split(" ")) arr = list(map(int, input().split(" ")))[:N] Q = [0] * 100 for elem in arr: Q[elem - 1] += 1 i = -1 while K > 0: i += 1 K -= Q[i] coeff = int(fattoriale(Q[i]) / (fattoriale(K + Q[i]) * fattoriale(-K))) print(coeff)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to $2\times$ the client's median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn't send the client any notifications until they have at least that trailing number of prior days' transaction data. Given the number of trailing days $\boldsymbol{d}$ and a client's total daily expenditures for a period of $n$ days, determine the number of times the client will receive a notification over all $n$ days. Example $expenditure=[10,20,30,40]$ $\boldsymbol{d}=3$ On the first three days, they just collect spending data. At day $4$, trailing expenditures are $[10,20,30]$. The median is $\textbf{20}$ and the day's expenditure is $\boldsymbol{40}$. Because $40\geq2\times20$, there will be a notice. The next day, trailing expenditures are $[20,30,40]$ and the expenditures are $50$. This is less than $2\times30$ so no notice will be sent. Over the period, there was one notice sent. Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia) Function Description Complete the function activityNotifications in the editor below. activityNotifications has the following parameter(s): int expenditure[n]: daily expenditures int d: the lookback days for median spending Returns int: the number of notices sent Input Format The first line contains two space-separated integers $n$ and $\boldsymbol{d}$, the number of days of transaction data, and the number of trailing days' data used to calculate median spending respectively. The second line contains $n$ space-separated non-negative integers where each integer $\boldsymbol{i}$ denotes $\textit{expenditure[i]}$. Constraints $1\leq n\leq2\times10^5$ $1\leq d\leq n$ $0\leq\textit{expenditure[i]}\leq200$ Output Format Sample Input 0 STDIN Function ----- -------- 9 5 expenditure[] size n =9, d = 5 2 3 4 2 3 6 8 4 5 expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5] Sample Output 0 2 Explanation 0 Determine the total number of $notifications$ the client receives over a period of $n=9$ days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: $notifications=0$. On the sixth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,4,2,3\}$, and $\textit{median}=3$ dollars. The client spends $\boldsymbol{6}$ dollars, which triggers a notification because $6\geq2\times{median}$: $notifications=0+1=1$. On the seventh day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{3,4,2,3,6\}$, and $\textit{median}=3$ dollars. The client spends $8$ dollars, which triggers a notification because $8\geq2\times{median}$: $notifications=1+1=2$. On the eighth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{4,2,3,6,8\}$, and $median=4$ dollars. The client spends $4$ dollars, which does not trigger a notification because $4<2\times{median}$: $notifications=2$. On the ninth day, the bank has $\boldsymbol{d}=5$ days of prior transaction data, $\{2,3,6,8,4\}$, and a transaction median of $4$ dollars. The client spends $5$ dollars, which does not trigger a notification because $5<2\times{median}$: $notifications=2$. Sample Input 1 5 4 1 2 3 4 4 Sample Output 1 0 There are $4$ days of data required so the first day a notice might go out is day $5$. Our trailing expenditures are $[1,2,3,4]$ with a median of $2.5$ The client spends $4$ which is less than $2\times2.5$ so no notification is sent.
days, sample_days = [int(i) for i in input().split()] exp = [int(i) for i in input().split()] noti = 0 w = [0] * 201 for i in range(sample_days): w[exp[i]] += 1 for i in range(days - sample_days): index, low, high = 0, 0, 0 if sample_days % 2 == 1: for j in range(201): index += w[j] if index >= sample_days // 2 + 1: med = j * 2 break else: for j in range(201): index += w[j] if index >= sample_days // 2 and low == 0: low = j if index >= sample_days // 2 + 1 and high == 0: high = j if low != 0 and high != 0: med = low + high break if exp[i + sample_days] >= med: noti += 1 w[exp[i]] -= 1 w[exp[i + sample_days]] += 1 print(noti)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR