description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys seen_cool = False no_counter = 0 normal = ["great", "bad", "think", "touch", "cool"] for i in range(10): print(i) sys.stdout.flush() s = input() if s == "no": no_counter += 1 if no_counter > 3: print("normal") break else: found = False for f in normal: if f in s: found = True if found: print("normal") else: print("grumpy") break
IMPORT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
i = 0 exec( """print(i,flush=1);i+=1;x=input() if x!='no':print('grumpy'if x[-2:]in'lenuseay'else'normal');quit() """ * 7 )
ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys grum = [ "don't even", "are you serious", "go die in a hole", "worse", "terrible", "no way", ] for i in range(10): print(i) sys.stdout.flush() s = sys.stdin.readline().strip().lower() if s != "no": print("grumpy" if s in grum else "normal") sys.exit()
IMPORT ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING STRING EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys i = 0 while i < 10: print(i) sys.stdout.flush() ans = sys.stdin.readline().strip().lower() if ans == "no": i += 1 continue if ans[:3] in ["gre", "not", "coo", "don"] and ans[-4:] != "even": print("normal") else: print("grumpy") sys.stdout.flush() break
IMPORT ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR STRING VAR NUMBER IF VAR NUMBER LIST STRING STRING STRING STRING VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys normal_only = ["not bad\n", "great\n", "don't touch me\n", "don't think so\n", "cool\n"] grumpy_only = [ "don't even\n", "terrible\n", "worse\n", "no way\n", "go die in a hole\n", "are you serious\n", ] def query(a): print(str(a), flush=True) res = sys.stdin.readline() return res for i in range(0, 10): res = query(i) if res in normal_only: print("normal", flush=True) sys.exit() elif res in grumpy_only: print("grumpy", flush=True) sys.exit()
IMPORT ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for i in a: sys.stdout.flush() print(i, flush=True) sys.stdout.flush() s = str(input()) sys.stdout.flush() if s == "no": sys.stdout.flush() continue if ( s == "great" or s == "cool" or s == "not bad" or s == "don't touch me" or s == "don't think so" ): print("normal", flush=True) break else: print("grumpy", flush=True) break
IMPORT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING NUMBER
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
import sys for i in range(0, 10): print(i) sys.stdout.flush() res = input() if res != "no": if res in [ "great", "don't think so", "don't touch me", "not bad", "cool", "great", ]: print("normal") else: print("grumpy") sys.stdout.flush() exit()
IMPORT FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR LIST STRING STRING STRING STRING STRING STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
ans = "" i = 0 while not ans: print(i, flush=1) s = input() if s != "no": if s in [ "great", "great!", "don't think so", "not bad", "cool", "don't touch me", "don't touch me!", ]: ans = "normal" else: ans = "grumpy" i += 1 print(ans)
ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR LIST STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat. <image> However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat. <image> You have met a cat. Can you figure out whether it's normal or grumpy? Interaction This is an interactive problem. Initially you're not given any information about the cat. Instead, the cat is divided into ten areas, indexed from 0 to 9. In one query you can choose which area you'll pet and print the corresponding index to standard out. You will get the cat's response, as depicted on the corresponding map, via standard in. For simplicity all responses are written in lowercase. Once you're certain what type of cat you're dealing with, output "normal" or "grumpy" to standard out. Note Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer.
normal = ["great", "don't think so", "don't touch me", "not bad", "cool"] response = "no" x = 0 while response == "no": print(x, flush=True) response = input() x += 1 print("normal") if response in normal else print("grumpy")
ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
T = int(input()) r = 1 def getans(target, n): ans = [] num1 = target num2 = n flag = True while True: if num1 > num2: num1 = (num1 - 1) // num2 + 1 ans.append([target, n]) elif num1 < num2: num2 = (num2 - 1) // num1 + 1 ans.append([n, target]) else: if num1 == 2 and num2 == 2: ans.append([target, n]) break else: flag = False break if len(ans) > 7 or not flag: return [] ans = ans[::-1] for i in range(n - 2): if i + 2 == target: continue ans.append([i + 2, n]) return ans[::-1] while r <= T: n = int(input()) for target in range(2, int(n**0.5 + 1) + 1): ans = getans(target, n) if len(ans) == 0: continue else: break print(len(ans)) for ele in ans: print(ele[0], ele[1]) r += 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR RETURN LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR RETURN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def cd(x, y): return (x + y - 1) // y t = int(input()) for _ in range(t): out = [] n = int(input()) large = n for i in range(n - 1, 1, -1): while cd(large, i) in [i, i + 1]: out.append(str(n) + " " + str(i)) large = cd(large, i) out.append(str(i) + " " + str(n)) print(len(out)) print("\n".join(out))
FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR VAR VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys def input(): return sys.stdin.readline().strip() def solve(): for t in range(int(input())): n = int(input()) j = n res = [] while j != 2: x = int(j**0.5) if x * x < j: x += 1 for i in range(x + 1, j): res.append((i, i + 1)) res.append((j, x)) res.append((j, x)) j = x print(len(res)) for a, b in res: print(a, b) solve()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
for _ in range(int(input())): n = int(input()) cur = n down = {cur} while cur > 2: bsl, bsr = 1, cur while bsl + 1 < bsr: bsm = (bsl + bsr) // 2 if bsm**2 < cur: bsl = bsm else: bsr = bsm cur = bsr down.add(cur) ans = [(i, n) for i in range(3, n) if i not in down] down = sorted(down, reverse=True) for i, j in zip(down, down[1:]): ans.append((i, j)) ans.append((i, j)) print(len(ans)) for i, j in ans: print(i, j)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) for _ in range(t): n = int(input()) ans = [] if n > 12: for i in range(13, n): ans.append((i, n)) prod = 1 while prod < n: ans.append((n, 12)) prod *= 12 for i in range(5, 12): ans.append((i, 12)) ans.append((12, 4)) ans.append((12, 3)) ans.append((3, 4)) ans.append((4, 2)) ans.append((4, 2)) else: for i in range(3, n): ans.append((i, n)) prod = 1 while prod < n: ans.append((n, 2)) prod *= 2 print(len(ans)) for i, j in ans: print(i, j)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
ansl = [] for _ in range(int(input())): al = [] n = int(input()) v = n if n <= 16: for i in range(3, n): al.append((i, n)) while v > 1: al.append((n, 2)) v = (v - 1) // 2 + 1 ansl.append(al) continue for i in range(3, n): if i != 16: al.append((i, n)) v = n while v > 1: al.append((n, 16)) v = (v - 1) // 16 + 1 for j in range(4): al.append((16, 2)) ansl.append(al) for row in ansl: print(len(row)) for a, b in row: print(a, b)
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
for i in range(int(input())): n = int(input()) if n <= 4: print(n - 1) for i in range(3, n): print(i, i + 1) print(n, 2) print(n, 2) elif n <= 8: print(n) for i in range(3, n): print(i, i + 1) for i in range(3): print(n, 2) else: print(n + 5) for i in range(9, n): print(i, i + 1) for i in range(6): print(n, 8) for i in range(3, 8): print(i, i + 1) for i in range(3): print(8, 2)
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 FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) while t: t -= 1 n = int(input()) l = [] x = 2 while x < n: l.append(x) x *= x l.append(n) ans = [] for i in range(3, n): if not i in l: ans.append([i, n]) l = l[::-1] y = len(l) for i in range(0, y - 1): ans.append([l[i], l[i + 1]]) ans.append([l[i], l[i + 1]]) print(len(ans)) for i in ans: print(f"{i[0]} {i[1]}")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
for _ in range(int(input())): n = int(input()) if n <= 8: temp = n cnt = 0 while temp != 1: temp = (temp + 1) // 2 cnt += 1 print(cnt + n - 3) for i in range(3, n): print(i, n) for i in range(cnt): print(n, 2) else: temp = n cnt = 0 while temp != 1: temp = (temp + 7) // 8 cnt += 1 print(cnt + n - 1) for i in range(3, n): if i != 8: print(i, n) for i in range(cnt): print(n, 8) print(8, 2) print(8, 2) print(8, 2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
for _ in range(int(input())): n = int(input()) a = [2, 3, 5, 22, 448, 200000] na = [] for i in range(len(a)): if a[i] < n: na.append(a[i]) else: na.append(n) break na.reverse() ans = [] for i in range(1, len(na)): for j in range(na[i] + 1, na[i - 1]): ans.append([j, na[i - 1]]) ans.append([na[i - 1], na[i]]) ans.append([na[i - 1], na[i]]) print(len(ans)) for x in ans: print(*x)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.readline def main(): n = int(input()) if n <= 2: print(0) return if n < 10: mv = [n] else: num = n mv = [] while num > 2: mv.append(num) num = num // 10 if mv[-1] > 10: mv.append(5) ans = [] for i in range(3, n + 1): if i in mv: continue ans.append((i, n)) m = len(mv) for i in range(m - 1): n1, n2 = mv[i], mv[i + 1] while n1 > 1: ans.append((mv[i], mv[i + 1])) n1 = n1 // n2 if n1 % n2 == 0 else n1 // n2 + 1 mi = mv[-1] while mi > 1: ans.append((mv[-1], 2)) mi = mi // 2 if mi % 2 == 0 else mi // 2 + 1 print(len(ans)) for a, b in ans: print(a, b) return for _ in range(int(input())): main()
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) for i in range(t): n = int(input()) if n == 3: print(2) print(3, 2) print(3, 2) continue if n < 28: num = n temp = 0 while num > 1: temp2 = int(num % 3 != 0) num //= 3 num += temp2 temp += 1 print(n - 4 + temp + 2) for i in range(3, n - 1): print(i + 1, n) for i in range(temp): print(n, 3) print(3, 2) print(3, 2) elif n < 257: num = n temp = 0 while num > 1: temp2 = int(num % 27 != 0) num //= 27 num += temp2 temp += 1 print(n - 5 + temp + 5) for i in range(3, 26): print(i + 1, n) for i in range(27, n - 1): print(i + 1, n) for i in range(temp): print(n, 27) print(27, 3) print(27, 3) print(27, 3) print(3, 2) print(3, 2) else: num = n temp = 0 while num > 1: temp2 = int(num % 256 != 0) num //= 256 num += temp2 temp += 1 print(n - 5 + temp + 6) print(3, n) for i in range(4, 255): print(i + 1, n) for i in range(256, n - 1): print(i + 1, n) for i in range(temp): print(n, 256) print(256, 4) print(256, 4) print(256, 4) print(256, 4) print(4, 2) print(4, 2)
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 EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) if n == 3: ans = [[3, 2], [3, 2]] elif n == 4: ans = [[3, 4], [4, 2], [4, 2]] elif n < 9: ans = [] for i in range(3, n): ans.append([i, n]) for i in range(4): ans.append([n, 2]) else: ans = [] for i in range(3, n): if i == 4 or i == 8: continue ans.append([i, n]) for i in range(6): ans.append([n, 8]) ans.append([8, 4]) ans.append([8, 4]) ans.append([4, 2]) ans.append([4, 2]) print(len(ans)) for i in ans: print(*i)
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER IF VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
from sys import stdin def main(): from sys import stdin input = stdin.buffer.readline for _ in range(int(input())): n = int(input()) for i in range(1, n): x = n y = i c = 0 while min(x, y) > 1: if x < y: x, y = y, x x = (x + y - 1) // y c += 1 if max(x, y) == 2 and c <= 8: print(n - 3 + c) for j in range(2, n): if j != i: print(j, n) x = n y = i while min(x, y) > 1: if x < y: print(i, n) y = (y + x - 1) // x else: print(n, i) x = (x + y - 1) // y break main()
FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def solve1(n): a = [] c = 0 for i in range(3, n): a.append(i) a.append(i + 1) c = c + 1 t = 0 z = n while z != 1: z = (z + 1) // 2 t = t + 1 for i in range(t): a.append(n) a.append(2) print(c + t) d = 0 for i in range(0, len(a)): print(a[i], end=" ") d = d + 1 if d == 2: d = 0 print() def solve2(): n = int(input()) if n <= 8: solve1(n) else: a = [] c = 0 for i in range(3, n): if i != 8: a.append(i) a.append(n) nn = n while nn != 1: a.append(n) a.append(8) nn = (nn + 7) // 8 a.append(8) a.append(2) a.append(8) a.append(2) a.append(8) a.append(2) print(len(a) // 2) d = 0 for i in range(0, len(a)): print(a[i], end=" ") d = d + 1 if d == 2: d = 0 print() for testis in range(int(input())): solve2()
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.buffer.readline def multiLineArrayOfArraysPrint(arr): print("\n".join([" ".join([str(x) for x in y]) for y in arr])) numbers = [2, 4] while numbers[-1] < 200000: numbers.append(numbers[-1] * numbers[-2]) t = int(input()) for _ in range(t): n = int(input()) if n == 1 or n == 2: print(0) elif n == 3: print(2) print("3 2") print("3 2") else: ans = [] for i in range(len(numbers) - 1): if numbers[i + 1] > n: b = numbers[i] a = numbers[i - 1] break for i in range(2, n): if i != a and i != b: ans.append([i, n]) if n != b: ans.append([n, b]) ans.append([n, b]) aa = a bb = b while not (aa == 1 or bb == 1): if bb > aa: ans.append([b, a]) bb = (bb + aa - 1) // aa else: ans.append([a, b]) aa = (aa + bb - 1) // bb print(len(ans)) multiLineArrayOfArraysPrint(ans)
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER 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 VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) lg = [0] * (2 * 10**5 + 5) for i in range(2, 2 * 10**5 + 1): lg[i] = lg[i // 2] + 1 for _ in range(t): n = int(input()) if n == 3: print(2) print(3, 2) print(3, 2) else: max_lg = lg[n] keep = [] cand = set(range(2, n + 1)) while max_lg > 0: keep.append(1 << max_lg) cand.remove(1 << max_lg) max_lg //= 2 op = [] keep.sort(reverse=True) if 1 << lg[n] != n: cand.remove(n) cand.add(2) for elm in cand: op.append((elm, n)) if 1 << lg[n] != n: op.append((n, 1 << lg[n])) for i in range(1, len(keep)): cnt = lg[keep[i - 1]] // lg[keep[i]] if lg[keep[i - 1]] % lg[keep[i]] != 0: cnt += 1 if i == len(keep) - 1 and 1 << lg[n] != n: for _ in range(cnt): op.append((keep[i - 1], n)) continue for _ in range(cnt): op.append((keep[i - 1], keep[i])) print(len(op)) for p in op: print(*p)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
UPOW = 4 for _ in " " * int(input()): n = int(input()) sq = int(n ** (1 / UPOW)) if sq**UPOW != n: sq += 1 nt = n sqt = sq ops = [] for i in range(3, n): if i != sq: ops.append((i, n)) while nt > 1: ops.append((n, sq)) nt = (nt + sq - 1) // sq while sqt > 1 and sq != 2: ops.append((sq, 2)) sqt = (sqt + 1) // 2 print(len(ops)) for o in ops: print(*o)
ASSIGN VAR NUMBER FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys for _ in range(int(sys.stdin.readline().strip())): n = int(sys.stdin.readline().strip()) s = 0 m = n o = [] n -= 1 while n > 1: while (n - 1) ** 2 > m: o.append(str(n) + " " + str(m) + "\n") s += 1 n -= 1 s += 2 o.append(str(m) + " " + str(n) + "\n") o.append(str(m) + " " + str(n) + "\n") m = n n -= 1 print(s) for i in o: sys.stdout.write(i)
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def solve(): N = int(input()) s = set() i = 2 while i < N: s.add(i) i **= 2 s.add(N) ans = [] for i in range(2, N + 1): if i not in s: ans.append((i, N)) s = sorted(list(s)) for i in range(len(s) - 2, -1, -1): ans.append((s[i + 1], s[i])) ans.append((s[i + 1], s[i])) print(len(ans)) for i in ans: print(i[0], i[1]) pass for tc in range(int(input())): solve()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys t = int(sys.stdin.readline().strip()) for _ in range(t): n = int(sys.stdin.readline().strip()) if n <= 8: cnt = n - 1 - 2 tl = 0 x = n while x != 1: x = (x + 1) // 2 tl += 1 print(cnt + tl) for j in range(n - 1, 2, -1): print(j, n) for j in range(tl): print(n, 2) else: cnt = n - 1 x = n tl = 0 while x != 1: x = (x + 7) // 8 tl += 1 print(cnt + tl) for j in range(n - 1, 2, -1): if j != 8: print(j, n) for j in range(tl): print(n, 8) for j in range(3): print(8, 2)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def dev(n, m): ret = n // m if n % m != 0: ret += 1 return ret T = int(input()) lis = [int(input()) for i in range(T)] for t in range(T): n = lis[t] count = 1 tmp = 2 for i in range(10): tmp = tmp * tmp if tmp >= n: break count += 1 dic = {(2): 0, (4): 0, (16): 0, (256): 0, (65536): 0} de = [1, 2, 4, 16, 256, 65536] print(n + count - 2) for i in range(3, n): if not i in dic: print(i, n) print(n, de[count]) print(n, de[count]) for i in range(count, 1, -1): print(de[i], de[i - 1]) print(de[i], de[i - 1])
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) for _ in range(t): n = int(input()) if n <= 2**5: print(n + 2) for i in range(3, n): print(i, i + 1) for i in range(1, 6): print(n, 2) else: print(n + 5) so = 3 while so**5 <= n: so += 1 for i in range(3, so): print(i, i + 1) for i in range(so + 1, so**3): print(i, i + 1) for i in range(so**3 + 1, n): print(i, i + 1) print(n, so**3) print(n, so**3) print(so**3, so) print(so**3, so) print(so**3, so) for i in range(5): print(so, 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) while t > 0: n = int(input()) ans = [] if n <= 8: for i in range(n - 1, 2, -1): ans.append([i, n]) temp = n while temp > 1: ans.append([n, 2]) if temp / 2 == temp // 2: temp = temp / 2 else: temp = temp // 2 + 1 else: for i in range(n - 1, 8, -1): ans.append([i, n]) temp = n while temp > 1: ans.append([n, 8]) if temp / 8 == temp // 8: temp = temp / 8 else: temp = temp // 8 + 1 for i in range(7, 2, -1): ans.append([i, 8]) temp = 8 while temp > 1: ans.append([8, 2]) if temp / 2 == temp // 2: temp = temp / 2 else: temp = temp // 2 + 1 print(len(ans)) for i in ans: print(i[0], i[1]) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def oot(n): lst1 = [n] nt = n while nt > 2: nt = nt ** (1 / 2) if nt != int(nt): nt = int(nt) + 1 lst1.append(int(nt)) print(n - 3 + len(lst1)) for i in range(3, n): if i not in lst1: print(i, i + 1) for i in range(len(lst1) - 1): print(lst1[i], lst1[i + 1]) print(lst1[i], lst1[i + 1]) t = int(input()) for i in range(t): x = int(input()) oot(x)
FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR 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 VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
T = int(input()) for t in range(T): d = int(input()) n = d ans = [] while n > 2: for i in range(n): if i * i >= n: if n >= (i - 1) * (i - 1) + i - 1: for j in range(n - 1, i, -1): ans.append([j, n]) ans.append([n, i]) ans.append([n, i]) else: for j in range(n - 1, i, -1): ans.append([j, n]) ans.append([n, i - 1]) ans.append([n, i]) n = i break print(len(ans)) for i in ans: print(*i, sep=" ")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.buffer.readline t = int(input()) for _ in range(t): n = int(input()) a = [(i + 1) for i in range(n)] ans = [] for i in range(3, n)[::-1]: x, y = i, n if -(-a[y - 1] // a[x - 1]) >= a[x - 1]: ans.append((y, x)) a[y - 1] = -(-a[y - 1] // a[x - 1]) ans.append((x, y)) a[x - 1] = -(-a[x - 1] // a[y - 1]) x, y = 2, n ans.append((y, x)) a[y - 1] = -(-a[y - 1] // a[x - 1]) ans.append((y, x)) a[y - 1] = -(-a[y - 1] // a[x - 1]) ans.append((y, x)) a[y - 1] = -(-a[y - 1] // a[x - 1]) print(len(ans)) for res in ans: print(*res)
IMPORT ASSIGN 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 BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) ans = [] if n <= 8: temp = n cnt = 0 while temp != 1: temp = (temp + 1) // 2 cnt += 1 for i in range(3, n): ans.append(f"{i} {n}") for i in range(cnt): ans.append(f"{n} {2}") print(len(ans)) print(*ans, sep="\n") else: temp = n cnt = 0 while temp != 1: temp = (temp + 7) // 8 cnt += 1 for i in range(3, n): if i != 8: ans.append(f"{i} {n}") for i in range(cnt): ans.append(f"{n} {8}") ans.append(f"{8} {2}") ans.append(f"{8} {2}") ans.append(f"{8} {2}") print(len(ans)) print(*ans, sep="\n")
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR STRING VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR NUMBER STRING NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.readline t = int(input()) for you in range(t): n = int(input()) l = [] if n == 3: print(2) print(3, 2) print(3, 2) continue curr = n for i in range(n - 1, 3, -1): if i == 65536 or i == 256 or i == 16 or i == 4: z = curr while z != 1: l.append((curr, i)) z = (z + i - 1) // i curr = i else: l.append((i, curr)) l.append((3, 4)) l.append((4, 2)) l.append((4, 2)) print(len(l)) for i in l: print(i[0], i[1])
IMPORT ASSIGN 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 LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
import sys input = sys.stdin.buffer.readline def multiLineArrayOfArraysPrint(arr): print("\n".join([" ".join([str(x) for x in y]) for y in arr])) t = int(input()) for _ in range(t): n = int(input()) if n == 1 or n == 2: print(0) else: ans = [] top = n while top > 2: nex = int(top**0.5 + 0.999) for i in range(nex + 1, top): ans.append([i, top]) ans.append([top, nex]) ans.append([top, nex]) top = nex print(len(ans)) multiLineArrayOfArraysPrint(ans)
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR 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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def solve(): n = int(input()) num = n - 1 den = n ans = "" count = 0 while den > 2: while not (den / num <= num and den / (num - 1) > num - 1): ans += "\n" + str(num) + " " + str(den) count += 1 num -= 1 ans += "\n" + str(den) + " " + str(num) ans += "\n" + str(den) + " " + str(num) count += 2 den = num num -= 1 ans = str(count) + ans print(ans) def main(): T = int(input()) for c in range(T): solve() main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
def readLine(): return [int(s) for s in input().split(" ")] zbior = {2, 4, 16, 256, 65536} def solve(): n = int(input()) ans = [] maxi = 2 for i in range(2, n + 1): y = {i} if y.issubset(zbior): continue elif i < n: ans.append([i, n]) else: while maxi * maxi <= n: maxi = maxi * maxi ans.append([n, maxi]) ans.append([n, maxi]) while maxi * maxi <= n: maxi = maxi * maxi specjalne = [] cur = 2 while cur <= maxi: specjalne.append(cur) cur = cur * cur specjalne.reverse() p = 0 for cur in specjalne: if cur == 2: break pop = specjalne[p + 1] akt = specjalne[p] ans.append([akt, pop]) ans.append([akt, pop]) p = p + 1 print(len(ans)) for x in ans: print(x[0], x[1]) tt = int(input()) for x in range(tt): solve()
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
from sys import stdin, stdout T = int(stdin.readline().strip()) for caso in range(T): n = int(stdin.readline().strip()) ans = [] if n <= 15: for i in range(3, n): ans.append([i, i + 1]) x = n while x != 1: ans.append([n, 2]) x = (x + 1) // 2 else: for i in range(16, n): ans.append([i, i + 1]) x = n while x != 1: ans.append([n, 15]) c = 0 if x % 15 != 0: c = 1 x = x // 15 + c for i in range(3, 15): ans.append([i, i + 1]) x = 15 while x != 1: ans.append([15, 2]) x = (x + 1) // 2 stdout.write("%d\n" % len(ans)) for i in ans: stdout.write("%d %d\n" % (i[0], i[1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
for no_test in range(int(input())): k = int(input()) if k == 3: print("2\n3 2\n3 2") continue a5, a1, a3 = k, 1, 1 def ceil(x): if x > int(x): return int(x) + 1 else: return int(x) a3 = ceil(a5 ** (3 / 5)) a1 = ceil(a5 ** (1 / 5)) n1 = 0 if a1 > 2: a = a1 while a >= 2: a = ceil(a / 2) n1 += 1 if k > 32: print(k - 5 + 3 + 2 + n1) else: print(k - 4 + 3 + 2 + n1) for i in range(3, k): if i in [a1, a3, a5]: continue else: print(i, i + 1) for i in range(2): print(a5, a3) for i in range(3): print(a3, a1) for i in range(n1): print(a1, 2)
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 ASSIGN VAR VAR VAR VAR NUMBER NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) def chk(n): g = n c = 0 if n > 12: while n != 0: n = int(n / 12) c += 1 print(g + c) for i in range(g - 4): if i < 9: print(i + 3, g) else: print(i + 4, g) for i in range(c): print(g, 12) print(12, 2) print(12, 2) print(12, 2) print(12, 2) else: if n > 8 and n < 13: print(n + 1) elif n < 9 and n > 4: print(n) else: print(n - 1) for i in range(n - 3): print(i + 3, n) while n != 1: print(g, 2) n = n - int(n / 2) c += 1 l = [] for i in range(t): l.append(int(input())) for i in l: chk(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You have an array $a_1, a_2, \dots, a_n$ where $a_i = i$. In one step, you can choose two indices $x$ and $y$ ($x \neq y$) and set $a_x = \left\lceil \frac{a_x}{a_y} \right\rceil$ (ceiling function). Your goal is to make array $a$ consist of $n - 1$ ones and $1$ two in no more than $n + 5$ steps. Note that you don't have to minimize the number of steps. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) β€” the number of test cases. The first and only line of each test case contains the single integer $n$ ($3 \le n \le 2 \cdot 10^5$) β€” the length of array $a$. It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$. -----Output----- For each test case, print the sequence of operations that will make $a$ as $n - 1$ ones and $1$ two in the following format: firstly, print one integer $m$ ($m \le n + 5$) β€” the number of operations; next print $m$ pairs of integers $x$ and $y$ ($1 \le x, y \le n$; $x \neq y$) ($x$ may be greater or less than $y$) β€” the indices of the corresponding operation. It can be proven that for the given constraints it's always possible to find a correct sequence of operations. -----Examples----- Input 2 3 4 Output 2 3 2 3 2 3 3 4 4 2 4 2 -----Note----- In the first test case, you have array $a = [1, 2, 3]$. For example, you can do the following: choose $3$, $2$: $a_3 = \left\lceil \frac{a_3}{a_2} \right\rceil = 2$ and array $a = [1, 2, 2]$; choose $3$, $2$: $a_3 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1]$. You've got array with $2$ ones and $1$ two in $2$ steps. In the second test case, $a = [1, 2, 3, 4]$. For example, you can do the following: choose $3$, $4$: $a_3 = \left\lceil \frac{3}{4} \right\rceil = 1$ and array $a = [1, 2, 1, 4]$; choose $4$, $2$: $a_4 = \left\lceil \frac{4}{2} \right\rceil = 2$ and array $a = [1, 2, 1, 2]$; choose $4$, $2$: $a_4 = \left\lceil \frac{2}{2} \right\rceil = 1$ and array $a = [1, 2, 1, 1]$.
t = int(input()) while t: t += -1 n = int(input()) check = [0] * (n + 1) ans = [] tmp = [] a = n while a > 2: check[a] = 1 tmp.append(a) b = a**0.5 if b != int(b): b = int(b) + 1 a = int(b) for i in range(3, n + 1): if check[i] == 0: ans.append([i, n]) for i in range(0, len(tmp) - 1): ans.append([tmp[i], tmp[i + 1]]) ans.append([tmp[i], tmp[i + 1]]) n = len(tmp) ans.append([tmp[n - 1], 2]) ans.append([tmp[n - 1], 2]) print(len(ans)) for i in ans: print(*i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
The territory of Berland is represented by a rectangular field n Γ— m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king. Input The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀ n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m). Output On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time. Examples Input 2 2 Output 0 1 1 1 2 2 2 2 1 1 1 Input 3 3 Output 1 3 3 1 1 1 1 1 2 1 3 2 3 2 2 2 1 3 1 3 2 3 3 1 1
def d(a, b): print(a + 1, b) return a + 1, b def u(a, b): print(a - 1, b) return a - 1, b def l(a, b): print(a, b - 1) return a, b - 1 def r(a, b): print(a, b + 1) return a, b + 1 a, b = map(int, input().split(" ")) if a == 1: if b == 2: print(0) else: print(1) print(a, b, 1, 1) for i in range(1, b + 1): print(1, i) print(1, 1) quit() if b == 1: if a == 2: print(0) else: print(1) print(a, b, 1, 1) for i in range(1, a + 1): print(i, 1) print(1, 1) quit() if a % 2 == 1 and b % 2 == 1: print(1) print(a, b, 1, 1) for i in range(1, a + 1): if i % 2 == 1: for j in range(1, b + 1): print(i, j) else: for j in range(b, 0, -1): print(i, j) print(1, 1) quit() if a % 2 == 0 and b % 2 == 0: print(0) x, y = 1, 1 print(x, y) for i in range(a - 1): x, y = d(x, y) k = True while 1: if x == 2 and y == b: break if k: x, y = r(x, y) for i in range(a - 2): x, y = u(x, y) else: x, y = r(x, y) for i in range(a - 2): x, y = d(x, y) k = not k x, y = u(x, y) for i in range(b - 1): x, y = l(x, y) if a % 2 == 0 and b % 2 == 1: print(0) x, y = 1, 1 print(x, y) for i in range(a - 1): x, y = d(x, y) k = True while 1: if x == a and y == b - 2: break if k: x, y = r(x, y) for i in range(a - 2): x, y = u(x, y) else: x, y = r(x, y) for i in range(a - 2): x, y = d(x, y) k = not k x, y = r(x, y) k = True while 1: if x == 1 and y == b: break if k: x, y = r(x, y) x, y = u(x, y) else: x, y = l(x, y) x, y = u(x, y) k = not k for i in range(b - 1): x, y = l(x, y) if a % 2 == 1 and b % 2 == 0: print(0) x, y = 1, 1 print(x, y) for i in range(b - 1): x, y = r(x, y) k = True while 1: if x == a - 2 and y == b: break if k: x, y = d(x, y) for i in range(b - 2): x, y = l(x, y) else: x, y = d(x, y) for i in range(b - 2): x, y = r(x, y) k = not k x, y = d(x, y) k = True while 1: if x == a and y == 1: break if k: x, y = d(x, y) x, y = l(x, y) else: x, y = u(x, y) x, y = l(x, y) k = not k for i in range(a - 1): x, y = u(x, y)
FUNC_DEF EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR NUMBER VAR FUNC_DEF EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR NUMBER VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR NUMBER IF VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR
The territory of Berland is represented by a rectangular field n Γ— m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king. Input The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀ n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m). Output On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time. Examples Input 2 2 Output 0 1 1 1 2 2 2 2 1 1 1 Input 3 3 Output 1 3 3 1 1 1 1 1 2 1 3 2 3 2 2 2 1 3 1 3 2 3 3 1 1
from sys import stdin input_tokens = stdin.readline() tokens = [int(x) for x in input_tokens.split()] assert len(tokens) == 2 n, m = tokens[0], tokens[1] if n == 1 and m > 2: print(1) print(n, m, 1, 1) for i in range(1, m + 1): print(1, i) elif m == 1 and n > 2: print(1) print(n, m, 1, 1) for i in range(1, n + 1): print(i, 1) elif not (n % 2 != 0 and m % 2 != 0): print(0) if m % 2 == 0: for i in range(1, m): print(1, i) for i in range(1, n + 1): print(i, m) for i in range(m - 1, 0, -1): for j in range(n, 1, -1): if i % 2 == 1: print(j, i) else: print(n - j + 2, i) else: for i in range(1, m): print(1, i) for i in range(1, n + 1): print(i, m) for i in range(n, 1, -1): for j in range(m - 1, 0, -1): if i % 2 == 0: print(i, j) else: print(i, m - j) else: print(1) print(n, m, 1, 1) for i in range(1, n + 1): for j in range(1, m + 1): if i % 2 == 1: print(i, j) else: print(i, m - j + 1) print(1, 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
The territory of Berland is represented by a rectangular field n Γ— m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king. Input The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀ n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m). Output On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time. Examples Input 2 2 Output 0 1 1 1 2 2 2 2 1 1 1 Input 3 3 Output 1 3 3 1 1 1 1 1 2 1 3 2 3 2 2 2 1 3 1 3 2 3 3 1 1
def inRows(): print(0) row = 1 column = 1 print(row, column) while row <= n: if row % 2 == 1: column = 2 while column <= m: print(row, column) column += 1 else: column = m while column >= 2: print(row, column) column -= 1 row += 1 for x in range(n, 1, -1): print(x, 1) def inCol(): print(0) row = 1 column = 1 print(row, column) while column <= m: if column % 2 == 1: row = 2 while row <= n: print(row, column) row += 1 else: row = n while row >= 2: print(row, column) row -= 1 column += 1 for x in range(m, 1, -1): print(1, x) n, m = map(int, input().split()) if (n == 1 or m == 1) and m * n > 2: print(1) print(n, m, 1, 1) for i in range(1, n + 1): for j in range(1, m + 1): print(i, j) elif n == 1 or m == 1: print(0) if n >= m: for i in range(1, n + 1): print(i, 1) else: for i in range(1, m + 1): print(1, i) elif n * m % 2 == 0: if n % 2 == 1: inCol() else: inRows() else: print(1) print(n, m, 1, 1) row = 1 column = 1 while row <= n: if row % 2 == 1: column = 1 while column <= m: print(row, column) column += 1 else: column = m while column >= 1: print(row, column) column -= 1 row += 1 print(1, 1)
FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
The territory of Berland is represented by a rectangular field n Γ— m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited every square (except the capital) exactly one time. The king must visit the capital exactly two times, at the very beginning and at the very end of his journey. The king can only move to the side-neighboring squares. However, the royal advise said that the King possibly will not be able to do it. But there is a way out β€” one can build the system of one way teleporters between some squares so that the king could fulfill his plan. No more than one teleporter can be installed on one square, every teleporter can be used any number of times, however every time it is used, it transports to the same given for any single teleporter square. When the king reaches a square with an installed teleporter he chooses himself whether he is or is not going to use the teleport. What minimum number of teleporters should be installed for the king to complete the journey? You should also compose the journey path route for the king. Input The first line contains two space-separated integers n and m (1 ≀ n, m ≀ 100, 2 ≀ n Β· m) β€” the field size. The upper left square has coordinates (1, 1), and the lower right square has coordinates of (n, m). Output On the first line output integer k β€” the minimum number of teleporters. Then output k lines each containing 4 integers x1 y1 x2 y2 (1 ≀ x1, x2 ≀ n, 1 ≀ y1, y2 ≀ m) β€” the coordinates of the square where the teleporter is installed (x1, y1), and the coordinates of the square where the teleporter leads (x2, y2). Then print nm + 1 lines containing 2 numbers each β€” the coordinates of the squares in the order in which they are visited by the king. The travel path must start and end at (1, 1). The king can move to side-neighboring squares and to the squares where a teleporter leads. Besides, he also should visit the capital exactly two times and he should visit other squares exactly one time. Examples Input 2 2 Output 0 1 1 1 2 2 2 2 1 1 1 Input 3 3 Output 1 3 3 1 1 1 1 1 2 1 3 2 3 2 2 2 1 3 1 3 2 3 3 1 1
def p(a, b, swap): if swap: a, b = b, a print(a, b) n, m = [int(x) for x in input().split()] if (n == 1 or m == 1) and n * m > 2: print(1) print(n, m, 1, 1) for r in range(n): for c in range(m): print(r + 1, c + 1) print(1, 1) exit(0) if n * m % 2 == 0: print(0) print(1, 1) swap = m % 2 != 0 if swap: m, n = n, m for c in range(m): for r in range(n - 1): if c % 2 == 0: p(r + 2, c + 1, swap) else: p(n - r, c + 1, swap) for c in range(m): p(1, m - c, swap) else: print(1) print(n, m, 1, 1) for c in range(m): for r in range(n): if c % 2 == 0: print(r + 1, c + 1) else: print(n - r, c + 1) print(1, 1)
FUNC_DEF IF VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER
Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexter Murugan. Being very popular, he is flown from Marina to Miami, to serve idlis in the opening ceremony of icpc world finals ( which is happening right now ! ). There are N students and they are initially served with some idlis. Some of them are angry because they got less idlis than some other. Dexter decides to redistribute the idlis so they all get equal number of idlis finally. He recollects his father's code, "Son, if you ever want to redistribute idlis, follow this method. While there are two persons with unequal number of idlis, repeat the following step. Select two persons A and B, A having the maximum and B having the minimum number of idlis, currently. If there are multiple ways to select A (similarly B), select any one randomly. Let A and B have P and Q number of idlis respectively and R = ceil( ( P - Q ) / 2 ), Transfer R idlis from A to B." Given the initial number of idlis served to each student, find the number of times Dexter has to repeat the above step. If he can not distribute idlis equally by following the above method, print -1. ------ Notes ------ ceil(x) is the smallest integer that is not less than x. ------ Input ------ First line contains an integer T ( number of test cases, around 20 ). T cases follows. Each case starts with an integer N ( 1 ≀ N ≀ 3000 ). Next line contains an array A of N integers separated by spaces, the initial number of idlis served ( 0 ≀ A[i] ≀ N ) ------ Output ------ For each case, output the number of times Dexter has to repeat the given step to distribute idlis equally or -1 if its not possible. Note:There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted. Time limit on each test set is 3 sec ----- Sample Input 1 ------ 3 4 1 2 2 3 2 1 2 7 1 2 3 4 5 6 7 ----- Sample Output 1 ------ 1 -1 3 ----- explanation 1 ------ Case 1 : { 1, 2, 2, 3}. Maximum 3, Minimum 1. R = ceil((3-1)/2) = 1. Transfer 1 idli from person having 3 idlis to the person having 1 idli. Each of them has 2 idlis now, so just 1 step is enough. Case 2 : {1,2} R = ceil((2-1)/2) = 1. {1,2} -> {2,1} -> {1,2} .... they can never get equal idlis :( Case 3 : Sorted arrays, in the order encountered {1, 2, 3, 4, 5, 6, 7} -> {2, 3, 4, 4, 4, 5, 6} -> {3, 4, 4, 4, 4, 4, 5} -> {4, 4, 4, 4, 4, 4, 4}
for i in range(0, int(input())): n = int(input()) m = list(map(int, input().split())) m.sort() count = 0 s = 0 for i in range(0, len(m)): s = s + m[i] if s % len(m) != 0: print(-1) else: while m[-1] != m[0]: dif = m[-1] - m[0] if dif % 2 == 0: exchange = int(dif / 2) else: exchange = int(dif / 2) + 1 m[-1] = m[-1] - exchange m[0] = m[0] + exchange count = count + 1 m.sort() print(count)
FOR VAR FUNC_CALL VAR NUMBER 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexter Murugan. Being very popular, he is flown from Marina to Miami, to serve idlis in the opening ceremony of icpc world finals ( which is happening right now ! ). There are N students and they are initially served with some idlis. Some of them are angry because they got less idlis than some other. Dexter decides to redistribute the idlis so they all get equal number of idlis finally. He recollects his father's code, "Son, if you ever want to redistribute idlis, follow this method. While there are two persons with unequal number of idlis, repeat the following step. Select two persons A and B, A having the maximum and B having the minimum number of idlis, currently. If there are multiple ways to select A (similarly B), select any one randomly. Let A and B have P and Q number of idlis respectively and R = ceil( ( P - Q ) / 2 ), Transfer R idlis from A to B." Given the initial number of idlis served to each student, find the number of times Dexter has to repeat the above step. If he can not distribute idlis equally by following the above method, print -1. ------ Notes ------ ceil(x) is the smallest integer that is not less than x. ------ Input ------ First line contains an integer T ( number of test cases, around 20 ). T cases follows. Each case starts with an integer N ( 1 ≀ N ≀ 3000 ). Next line contains an array A of N integers separated by spaces, the initial number of idlis served ( 0 ≀ A[i] ≀ N ) ------ Output ------ For each case, output the number of times Dexter has to repeat the given step to distribute idlis equally or -1 if its not possible. Note:There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted. Time limit on each test set is 3 sec ----- Sample Input 1 ------ 3 4 1 2 2 3 2 1 2 7 1 2 3 4 5 6 7 ----- Sample Output 1 ------ 1 -1 3 ----- explanation 1 ------ Case 1 : { 1, 2, 2, 3}. Maximum 3, Minimum 1. R = ceil((3-1)/2) = 1. Transfer 1 idli from person having 3 idlis to the person having 1 idli. Each of them has 2 idlis now, so just 1 step is enough. Case 2 : {1,2} R = ceil((2-1)/2) = 1. {1,2} -> {2,1} -> {1,2} .... they can never get equal idlis :( Case 3 : Sorted arrays, in the order encountered {1, 2, 3, 4, 5, 6, 7} -> {2, 3, 4, 4, 4, 5, 6} -> {3, 4, 4, 4, 4, 4, 5} -> {4, 4, 4, 4, 4, 4, 4}
def solve(A, N): total = sum(A) if total % N != 0: print(-1) return ans = 0 while True: A.sort() maxx, minn = A[-1], A[0] if maxx == minn: break ans += 1 extra = (maxx - minn + 1) // 2 A = A[1:-1] A.append(maxx - extra) A.append(minn + extra) print(ans) T = int(input()) for _ in range(T): N = int(input()) A = list(map(int, input().split())) solve(A, N)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexter Murugan. Being very popular, he is flown from Marina to Miami, to serve idlis in the opening ceremony of icpc world finals ( which is happening right now ! ). There are N students and they are initially served with some idlis. Some of them are angry because they got less idlis than some other. Dexter decides to redistribute the idlis so they all get equal number of idlis finally. He recollects his father's code, "Son, if you ever want to redistribute idlis, follow this method. While there are two persons with unequal number of idlis, repeat the following step. Select two persons A and B, A having the maximum and B having the minimum number of idlis, currently. If there are multiple ways to select A (similarly B), select any one randomly. Let A and B have P and Q number of idlis respectively and R = ceil( ( P - Q ) / 2 ), Transfer R idlis from A to B." Given the initial number of idlis served to each student, find the number of times Dexter has to repeat the above step. If he can not distribute idlis equally by following the above method, print -1. ------ Notes ------ ceil(x) is the smallest integer that is not less than x. ------ Input ------ First line contains an integer T ( number of test cases, around 20 ). T cases follows. Each case starts with an integer N ( 1 ≀ N ≀ 3000 ). Next line contains an array A of N integers separated by spaces, the initial number of idlis served ( 0 ≀ A[i] ≀ N ) ------ Output ------ For each case, output the number of times Dexter has to repeat the given step to distribute idlis equally or -1 if its not possible. Note:There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted. Time limit on each test set is 3 sec ----- Sample Input 1 ------ 3 4 1 2 2 3 2 1 2 7 1 2 3 4 5 6 7 ----- Sample Output 1 ------ 1 -1 3 ----- explanation 1 ------ Case 1 : { 1, 2, 2, 3}. Maximum 3, Minimum 1. R = ceil((3-1)/2) = 1. Transfer 1 idli from person having 3 idlis to the person having 1 idli. Each of them has 2 idlis now, so just 1 step is enough. Case 2 : {1,2} R = ceil((2-1)/2) = 1. {1,2} -> {2,1} -> {1,2} .... they can never get equal idlis :( Case 3 : Sorted arrays, in the order encountered {1, 2, 3, 4, 5, 6, 7} -> {2, 3, 4, 4, 4, 5, 6} -> {3, 4, 4, 4, 4, 4, 5} -> {4, 4, 4, 4, 4, 4, 4}
for t in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] s = sum(a) if s % n != 0: print("-1") else: x = [0] * (n + 1) for e in a: x[e] += 1 i = 0 j = n c = 0 while i < j: while x[i] == 0: i += 1 while x[j] == 0: j -= 1 if i == j: break k = int((j - i) // 2) x[j] -= 1 x[i] -= 1 x[j - k] += 1 x[i + k] += 1 c += 1 print(c)
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 FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
fact = [1] * 1000007 for i in range(1, 1000007): fact[i] = i * fact[i - 1] % 1000000007 def nCr(n, r): a = fact[n] b = fact[r] * fact[n - r] % 1000000007 c = pow(b, 1000000005, 1000000007) return a * c % 1000000007 count = 0 a, b, n = map(int, input().split()) for i in range(n + 1): s = a * i + b * (n - i) if str(s).replace(str(a), "").replace(str(b), "") == "": count = (count + nCr(n, i)) % 1000000007 print(count)
ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING STRING ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
import sys inf = float("inf") mod, MOD = 1000000007, 998244353 def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() def is_beautiful(sum): if sum == 0: return 0 while sum: if sum % 10 != a: if sum % 10 != b: return 0 sum //= 10 return 1 def nCr(n, r): return fact[n] * invfact[r] * invfact[n - r] % mod fact = [0] * 1000005 invfact = [0] * 1000005 fact[0] = fact[1] = invfact[0] = invfact[1] = 1 for i in range(1, 1000003): fact[i] = fact[i - 1] % mod * i % mod % mod invfact[1000000] = pow(fact[1000000], mod - 2, mod) for i in range(999999, 0, -1): invfact[i] = invfact[i + 1] % mod * (i + 1) % mod % mod a, b, n = get_ints() if a == b: if is_beautiful(a * n): print(1) else: print(0) ans = 0 for i in range(n + 1): if is_beautiful(a * i + b * (n - i)): ans += nCr(n, i) ans %= mod print(ans)
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR IF VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
def ncr(n, r, p): num = den = 1 for i in range(r): num = num * (n - i) % p den = den * (i + 1) % p return num * pow(den, p - 2, p) % p a, b, n = map(int, input().split()) ans = 0 p = 10**9 + 7 num = 1 den = 1 for i in range(n + 1): s = a * i + b * (n - i) if i != 0: num = num * (n - i + 1) % p den = den * i % p am = True while s != 0: if s % 10 != a and s % 10 != b: am = False break s //= 10 if am: ans = (ans + num * pow(den, p - 2, p) % p) % p print(ans % p)
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
fact = [1] mod = 10**9 + 7 def factorial(n): global mod global fact fact = [1] mod = 10**9 + 7 for i in range(1, n + 1): fact.append(fact[-1] * i) fact[-1] %= mod def C(n, k): global mod return ( fact[n] * pow(fact[k], mod - 2, mod) % mod * pow(fact[n - k], mod - 2, mod) % mod ) def good(x, a, b): while x > 0: if x % 10 != a and x % 10 != b: return False x //= 10 return True for _ in range(1): ans = 0 a, b, n = map(int, input().split()) factorial(n) for i in range(n + 1): if good(i * a + (n - i) * b, a, b): ans += C(n, i) ans %= mod print(ans)
ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
ans = 0 mod = 1000000007 a, b, n = list(map(int, input().split())) s = set() for x in range(2, 1 << 8): z = 0 while x > 1: z = z * 10 + (a, b)[x & 1] x >>= 1 s.add(z) f = [1] * (n + 1) for i in range(1, n + 1): f[i] = f[i - 1] * i % mod for x in range(n + 1): if x * a + (n - x) * b in s: ans += pow(f[x] * f[n - x], mod - 2, mod) ans %= mod print(ans * f[n] % mod)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
fact = {} modulo = 1000000007 def check(val, a, b): while val: if val % 10 == a or val % 10 == b: val //= 10 else: return False return True def modpow(base, exp, mod): if exp == 0: return 1 if exp & 1: return modpow(base, exp - 1, mod) * base % mod res = modpow(base, exp >> 1, mod) return res * res % mod def getC(n, i): res = fact[n] div = fact[n - i] * fact[i] div %= modulo div = modpow(div, modulo - 2, modulo) return res * div % modulo a, b, n = [int(x) for x in input().split()] fact[0] = 1 for i in range(1, 1000005): fact[i] = fact[i - 1] * i fact[i] %= modulo ans = 0 for i in range(n + 1): expsum = a * i + b * (n - i) if check(expsum, a, b): ans += getC(n, i) ans %= modulo print(ans)
ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF WHILE VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
def power(x, y, m): if y == 0: return 1 p = power(x, y // 2, m) % m p = p * p % m if y % 2 == 0: return p else: return x * p % m def gcd(a, b): if a == 0: return b return gcd(b % a, a) a, b, n = map(int, input().split()) ans = 0 m = 1000000007 fct = [1] * (n + 1) fct[0] = 1 for i in range(1, n + 1): fct[i] = fct[i - 1] * i % m for i in range(n + 1): k = i * a + (n - i) * b k = str(k) ch1 = str(a) ch2 = str(b) a1 = k.count(ch2) a2 = k.count(ch1) if a1 + a2 == len(k): g = fct[n] j = power(fct[i], m - 2, m) % m j = (j * power(fct[n - i], m - 2, m) + m) % m j = (g * j + m) % m j = (j + m) % m ans = (ans + j) % m ans = (ans + m) % m print(ans)
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
MOD = 1000000007 MX = 1000000 fact = [1] * (MX + 1) for i in range(1, MX + 1): fact[i] = fact[i - 1] * i % MOD def power(a, b): res = 1 while b > 0: if b % 2 == 1: res = res * a % MOD a = a * a % MOD b //= 2 return res def inv(n): return power(n, MOD - 2) def choose(n, k): return fact[n] * inv(fact[n - k]) * inv(fact[k]) def is_good(n, g): while n > 0: if n % 10 not in g: return False n //= 10 return True a, b, n = map(int, input().split()) res = 0 for ca in range(n + 1): cb = n - ca if is_good(ca * a + cb * b, [a, b]): res += choose(n, ca) res %= MOD print(res)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR LIST VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
MOD = int(1000000000.0 + 7) def fast_power(b, e): res = 1 while e > 0: if e % 2 == 1: res = res * b % MOD b = b * b % MOD e //= 2 return res a, b, n = map(int, input().split()) s, res = set(), 0 for x in range(2, 1 << 8): z = 0 while x > 1: z = z * 10 + (a, b)[x & 1] x >>= 1 s.add(z) fact = [1] * (n + 1) for i in range(1, n + 1): fact[i] = fact[i - 1] * i % MOD for x in range(n + 1): if x * a + (n - x) * b in s: res = (res + fast_power(fact[x] * fact[n - x], MOD - 2)) % MOD print(res * fact[n] % MOD)
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
import sys a, b, n = map(int, input().split()) input = sys.stdin.readline p = 10**9 + 7 pri = p fac = [(1) for i in range(10**6 + 1)] for i in range(2, len(fac)): fac[i] = fac[i - 1] * (i % pri) % pri def modi(x): return pow(x, p - 2, p) % p def ncr(n, r): x = fac[n] * (modi(fac[r]) % p * (modi(fac[n - r]) % p)) % p % p return x ans = [] for i in range(n + 1): total = i * a + (n - i) * b s = str(total) if s.count(str(a)) + s.count(str(b)) == len(s): ans.append([i, n - i]) total = 0 for i in range(len(ans)): total += ncr(n, ans[i][0]) total %= pri print(total)
IMPORT ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
a, b, n = list(map(int, input().split())) m = 1000000007 fact = [1] for i in range(1, n + 1): fact.append(fact[-1] * i % m) ans = 0 for i in range(n + 1): su = a * i + b * (n - i) coef = 1 while su > 0: if su % 10 != a and su % 10 != b: coef = 0 su //= 10 if coef: ans += fact[n] * pow(fact[i] * fact[n - i], m - 2, m) ans = ans % m print(ans % m)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - b // a * y, y def modinv(a, m): g, x, y = egcd(a, m) return x % m a, b, n = map(int, input().split()) c = str(a) + str(b) f, mod, ans = [1], 1000000007, 0 for i in range(1, n + 1): f.append(f[-1] * i % mod) s = a * n for i in range(n + 1): if all(i in c for i in str(s)): ans += f[n] * modinv(f[i] * f[n - i], mod) % mod s += b - a print(ans % mod)
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
MOD = int(1000000000.0 + 7) fact = [1] for i in range(1, int(1000000.0) + 1, 1): fact.append(fact[i - 1] * i % MOD) A, B, N = list(map(int, input().split())) ans = 0 for i in range(N + 1): f = A * i + B * (N - i) ng = False while f: t = f % 10 if t != A and t != B: ng = True break f //= 10 if ng: continue ans = ( ans + fact[N] * pow(fact[i], MOD - 2, MOD) * pow(fact[N - i], MOD - 2, MOD) ) % MOD print(ans)
ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
N = 10**6 mod = 10**9 + 7 def checkgood(val, a, b): while val: if val % 10 != a and val % 10 != b: return False val //= 10 return True def power(x, a): if a == 0: return 1 z = power(x, a // 2) z = z**2 % mod if a % 2: z = z * x % mod return z fact = [(1) for _ in range(N + 1)] for no in range(2, N + 1): fact[no] = fact[no - 1] * no % mod [a, b, n] = list(map(int, input().split())) count = 0 val = (n + 1) * b - a for freq in range(n + 1): val += a - b if checkgood(val, a, b): count += ( fact[n] * power(fact[freq], mod - 2) % mod * power(fact[n - freq], mod - 2) % mod ) count %= mod print(count)
ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF WHILE VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR 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 BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
MOD = 10**9 + 7 p = 1000009 fact = [0] * p fact[0] = 1 for i in range(1, p): fact[i] = fact[i - 1] * i % MOD def MI(a, MOD): return pow(a, MOD - 2, MOD) def ncr(n, k, MOD): if n == k or k == 0: return 1 if n < k: return 0 return fact[n] * MI(fact[k], MOD) % MOD * MI(fact[n - k], MOD) % MOD % MOD a, b, n = map(int, input().split()) good = [a, b] j = -1 for i in range(10**5): j += 1 good.append(good[j] * 10 + a) good.append(good[j] * 10 + b) good.sort() good = [i for i in good if n * min(a, b) <= i <= n * max(a, b)] ans = 0 MOD = 10**9 + 7 for x in range(0, n + 1): if a * x + b * (n - x) in good: ans += ncr(n, x, MOD) ans %= MOD print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
MOD = 10**9 + 7 a, b, n = list(map(int, input().strip().split(" "))) def check(a, b, x): temp = x % 10 if temp != a and temp != b: return 0 while x > 0: temp = x % 10 if temp != a and temp != b: return 0 x = x // 10 return 1 fact = [1] infact = [1] temp = 1 intemp = 1 for i in range(1, n + 1): temp *= i temp %= MOD fact += [temp] def binom(a, b): MOD = 10**9 + 7 if b == 0: return 1 else: temp = pow(fact[a - b] * fact[b], MOD - 2, MOD) * fact[a] return temp % MOD total = 0 for i in range(n + 1): temp = i * a + (n - i) * b if check(a, b, temp) == 1: total += binom(n, i) total %= MOD print(total % MOD)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR LIST VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
N = 1000007 m = int(1000000000.0 + 7) sum = 0 ans = 0 fact = [(0) for i in range(0, 1000007)] def modularexponentiation(a: int, b: int, m: int): res = 1 a = a % m while b > 0: if b & 1: res = res * a % m a = a * a % m b = b // 2 return res def modinverse(a: int, m: int): return modularexponentiation(a, m - 2, m) a, b, n = [int(x) for x in input().split()] fact[0] = 1 for i in range(1, N): fact[i] = fact[i - 1] * i % m for i in range(0, n + 1): sum = a * i + b * (n - i) while sum > 0: if sum % 10 != a and sum % 10 != b: break sum = sum // 10 if sum == 0: ans = (ans + fact[n] * modinverse(fact[i] * fact[n - i] % m, m)) % m print(ans)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
def check(x): while x: if x % 10 != a and x % 10 != b: return False x //= 10 return True a, b, n = map(int, input().split()) factorial, ans = [1], 0 for i in range(1, n + 1): factorial.append(factorial[-1] * i % 1000000007) for i in range(n + 1): if check(a * i + b * (n - i)): ans += factorial[n] * pow( factorial[i] * factorial[n - i], 1000000005, 1000000007 ) ans %= 1000000007 print(ans % 1000000007)
FUNC_DEF WHILE VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
mxn = 10**6 + 10 fact = [1] * mxn mod = 10**9 + 7 for i in range(1, mxn): fact[i] = fact[i - 1] * i % mod def nck(n, k): return fact[n] * pow(fact[k] * fact[n - k], mod - 2, mod) % mod def log(n): ans = 0 while n: ans += 1 n //= 10 return ans a, b, n = map(int, input().split()) if a < b: a, b = b, a mn = b * n mx = a * n leng = [i for i in range(log(mn), log(mx) + 1)] ans = 0 def check(num): mx = n * a if (mx - num) % (a - b) != 0: return 0 l = n - (mx - num) // (a - b) r = n - l return nck(n, l) * nck(n - l, r) for l in leng: for mask in range(1 << l): num = 0 mul = 1 for bit in range(l): if mask & 1 << bit: num += mul * a else: num += mul * b mul *= 10 if mn <= num and num <= mx: ans += check(num) ans %= mod print(ans)
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
z = 1000000007 def modinv(p, q): res = 1 while q: if q % 2: res = res * p % z q -= 1 else: p = p * p % z q //= 2 return res a, b, n = map(int, input().split()) times = n s = 0 arr = [1] * (n + 1) p = 1 for i in range(1, n + 1): p = p * i % z arr[i] = p while times > -1: x = str(a * times + b * (n - times)) counta = countb = l = 0 for i in x: if i == str(a): counta += 1 elif i == str(b): countb += 1 l += 1 if counta + countb == l: s = (s + arr[-1] * modinv(arr[times] * arr[n - times] % z, z - 2)) % z times -= 1 print(s)
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
a, b, n = map(int, input().split()) dic = {(0): 1} m = 10**9 + 7 for i in range(1, n + 1): dic[i] = dic[i - 1] * i % m def modExp(a, n, m=10**9 + 7): if n == 0: return 1 elif n == 1: return a else: while n >= 2: if n % 2 == 0: n = n // 2 return modExp(a % m * (a % m) % m, n, m) else: n = (n - 1) // 2 return a % m * modExp(a % m * (a % m) % m, n, m) % m % m def nCr(n, r): return dic[n] * modExp(dic[n - r], m - 2) * modExp(dic[r], m - 2) % m out = 0 for i in range(n + 1): op = str(a * i + b * (n - i)) for j in op: if j != str(a) and j != str(b): break else: out += nCr(n, i) out = out % m print(out)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
def read(): return list(map(int, input().strip().split(" "))) MOD = 10**9 + 7 def fact(): N = 10**6 + 1 facto = [0] * (N + 1) facto[0] = 1 for i in range(1, N + 1): facto[i] = facto[i - 1] % MOD * i % MOD return facto facto = fact() def chk(n, a, b): s = 0 while n > 0: if not n % 10 in (a, b): return False n //= 10 return True def modInverse(a, m): m0 = m y = 0 x = 1 if m == 1: return 0 while a > 1: q = a // m t = m m = a % m a = t t = y y = x - q * y x = t if x < 0: x = x + m0 return x def solve(): a, b, n = read() ans = 0 for i in range(n + 1): x, y = i, n - i if chk(a * x + b * y, a, b): u = facto[n] d = modInverse(facto[x] % MOD * (facto[y] % MOD) % MOD, MOD) ans += u * d % MOD ans %= MOD print(ans) solve()
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR RETURN NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
mod = 1000000007 fact = [] def Beautiful_Numbers(a, b, n): result = 0 Factorial(n) comb = [] if n == 1: return 2 for m in range(0, n + 1): x = m * a + (n - m) * b if Es_Bueno(x, a, b): if m <= n // 2: c = Combinaciones(n, m) comb.append(c) result += c result %= mod elif comb[n - m] != -1: result += comb[n - m] result %= mod else: c = Combinaciones(n, m) comb[n - m] = c result += c result %= mod else: comb.append(-1) return result def Combinaciones(n, m): if m == 0 | m == n: return 1 else: tmp = fact[n - m] * fact[m] % mod tmp = binpow(tmp, mod - 2, mod) return fact[n] * tmp % mod def binpow(d, deg, mod): if not deg: return 1 % mod if deg & 1: return binpow(d, deg - 1, mod) * d % mod res = binpow(d, deg >> 1, mod) return res * res % mod def Factorial(n): fact.append(1) for i in range(1, n + 1): fact.append(fact[i - 1] * i % mod) def Es_Bueno(x, a, b): x_str = str(x) for i in range(0, len(x_str)): if x_str[i] != str(a) and x_str[i] != str(b): return False return True _input = [int(x) for x in input().split()] a = _input[0] b = _input[1] n = _input[2] print(Beautiful_Numbers(a, b, n))
ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR FUNC_DEF IF VAR BIN_OP NUMBER VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF IF VAR RETURN BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
def egcd(a, b): if b == 0: return a, 1, 0 g, x1, y1 = egcd(b, a % b) x = y1 y = x1 - y1 * (a // b) return g, x, y def mod_inv(a, b): return (egcd(a, b)[1] % b + b) % b def gud(a, b, x): a = str(a) b = str(b) x = set(str(x)) if len(x) > 2: return False elif len(x) == 2: if a in x and b in x: return True else: return False elif a in x or b in x: return True else: return False a, b, n = map(int, input().split()) d = {(0): 1} m = 10**9 + 7 for i in range(1, n + 1): d[i] = d[i - 1] * i % m ans = 0 for i in range(n + 1): x = a * i + b * (n - i) if gud(a, b, x): ans += d[n] % m * mod_inv(d[i], m) * mod_inv(d[n - i], m) % m print(ans % m)
FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR RETURN VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
a, b, n = [int(x) for x in input().split()] m = 1000000007 fact = [1] def helper(a, b, n): while n: curr = n % 10 if curr != a and curr != b: return False n = n // 10 return True for i in range(1, n + 1): fact.append(fact[-1] * i % m) s = b * n ans = 0 for i in range(n + 1): if helper(a, b, s): ans += fact[n] * pow(fact[i] * fact[n - i], m - 2, m) ans %= m s -= b s += a print(ans % (10**9 + 7))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
import sys M = 1000000007 def alele(): return list(map(int, sys.stdin.readline().strip().split())) def ilele(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() a, b, n = ilele() Ans = 0 fact = [1] * (n + 1) for i in range(1, n + 1): fact[i] = fact[i - 1] * i % M for i in range(n + 1): s = str(a * i + b * (n - i)) Noa = 0 Nob = 0 for j in s: if int(j) == a: Noa += 1 elif int(j) == b: Nob += 1 if Noa + Nob == len(s): Ans = (Ans + pow(fact[n - i] * fact[i], M - 2, M)) % M print(Ans * fact[n] % M)
IMPORT ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
a, b, n = list(map(int, input().split())) def ok(s): while s: if s % 10 != a and s % 10 != b: return False s = int(s / 10) return True ans = 0 p = int(1000000000.0 + 7) A = [1] for i in range(1, n + 1): A.append(int(i * A[i - 1] % p)) for x in range(0, n + 1): y = n - x if ok(a * x + b * y): ans += A[n] * pow(A[x], p - 2, p) % p * pow(A[y], p - 2, p) % p ans %= p print(int(ans))
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF WHILE VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≀ a < b ≀ 9, 1 ≀ n ≀ 10^6). -----Output----- Print a single integer β€” the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165
f = [0] * (10**6 + 1) f[0] = f[1] = 1 mod = 10**9 + 7 for i in range(2, 10**6 + 1): f[i] = f[i - 1] * i % mod def comb(n, r): return f[n] * pow(f[n - r] * f[r], mod - 2, mod) % mod a, b, n = map(int, input().split()) ans = 0 def is_good(x, a, b): x = str(x) a = str(a) b = str(b) flag = True for xx in x: if xx != a and xx != b: flag = False return flag for k in range(n + 1): s = a * k + b * (n - k) if is_good(s, a, b): ans += comb(n, k) ans %= mod print(ans % mod)
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Tug of war is a sport that directly puts two teams against each other in a test of strength. During school days, both Chef Shifu and Chef Po were champions of tug of war. On behalf of restaurant's anniversary, Chef Shifu and Chef Po have decided to conduct a tug of war game for their customers. Master Chef Oogway has decided the following rules for the game. Let N be the number of players participating in the game. All of these players would stand in a circle in clock wise direction. There are an infinite number of long ropes available. When a rope is held by exactly two players, it is termed as bonding. At least one bonding is necessary to conduct a game. A player can play against multiple people simultaneously i.e he can have more than one bonding at the same time. Both members of a pair of players that have a bonding must have the same number of total bondings. That is, if the player A makes bonding with the player B, then the number of total bondings of the player A must be the same as that of the player B. Bondings should be created in such a fashion that ropes must not intersect each other. The number of bondings of every player must be no more than K. Now Master Chef Oogway asked Chef Shifu and Chef Po to find out the number of possible games. Your task is to help them find this number. As this number might become huge, you've to find it modulo (10^{14}+7). Two games are different iff there is some bonding that is present in only of them. ------ Input ------ First line contains T, the number of test cases. Each of T lines contain 2 positive integers N and K separated by a space. ------ Output ------ For each test case, output the number of ways to conduct the game modulo 100000000000007 (10^{14}+7) in one line. ------ Example ------ Input: 3 3 2 4 0 2 1 Output: 4 0 1 Explanation: For the 1st case, there are 3 players. Let's call them p1, p2, p3. Different games possible are: Game 1: p1-p2 (numbers of bondings of p1, p2 are 1 ≀ K = 2) Game 2: p1-p3 (numbers of bondings of p1, p3 are 1 ≀ K = 2) Game 3: p2-p3 (numbers of bondings of p2, p3 are 1 ≀ K = 2) Game 4: p1-p2, p1-p3, p2-p3 (numbers of bondings of p1, p2, p3 are 2 ≀ K = 2) For the 2nd test case, we cannot form the game, because K = 0 and hence no player is allowed to make any bonding. As any game must have atleast one bonding, no game is possible here. For the 3rd case, only possible game is: Game 1: p1-p2 (number of bondings in p1, p2 are 1) ------ Constraints ------ 1 ≀ T ≀ 10000 0 ≀ N ≀ 10000 0 ≀ K ≀ N
import sys mod = 100000000000007 motzkin = [1, 0] catalan = [1, 1, 2] for i in range(1, 10009): motzkin.append(0) for j in range(0, 10006): catalan.append(0) for i in range(2, 10006): motzkin[i] = (i - 1) * (2 * motzkin[i - 1] + 3 * motzkin[i - 2]) motzkin[i] = motzkin[i] // (i + 1) for i in range(10003): motzkin[i] = (motzkin[i] + motzkin[i + 1]) % mod for i in range(2, 10001): catalan[i + 1] = (4 * i + 2) * catalan[i] // (i + 2) for i in range(int(input())): n, k = [int(x) for x in input().split()] if k == 0: print(0) elif k == 1: print((motzkin[n] - 1) % mod) else: print((catalan[n] - 1) % mod)
IMPORT ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR
Tug of war is a sport that directly puts two teams against each other in a test of strength. During school days, both Chef Shifu and Chef Po were champions of tug of war. On behalf of restaurant's anniversary, Chef Shifu and Chef Po have decided to conduct a tug of war game for their customers. Master Chef Oogway has decided the following rules for the game. Let N be the number of players participating in the game. All of these players would stand in a circle in clock wise direction. There are an infinite number of long ropes available. When a rope is held by exactly two players, it is termed as bonding. At least one bonding is necessary to conduct a game. A player can play against multiple people simultaneously i.e he can have more than one bonding at the same time. Both members of a pair of players that have a bonding must have the same number of total bondings. That is, if the player A makes bonding with the player B, then the number of total bondings of the player A must be the same as that of the player B. Bondings should be created in such a fashion that ropes must not intersect each other. The number of bondings of every player must be no more than K. Now Master Chef Oogway asked Chef Shifu and Chef Po to find out the number of possible games. Your task is to help them find this number. As this number might become huge, you've to find it modulo (10^{14}+7). Two games are different iff there is some bonding that is present in only of them. ------ Input ------ First line contains T, the number of test cases. Each of T lines contain 2 positive integers N and K separated by a space. ------ Output ------ For each test case, output the number of ways to conduct the game modulo 100000000000007 (10^{14}+7) in one line. ------ Example ------ Input: 3 3 2 4 0 2 1 Output: 4 0 1 Explanation: For the 1st case, there are 3 players. Let's call them p1, p2, p3. Different games possible are: Game 1: p1-p2 (numbers of bondings of p1, p2 are 1 ≀ K = 2) Game 2: p1-p3 (numbers of bondings of p1, p3 are 1 ≀ K = 2) Game 3: p2-p3 (numbers of bondings of p2, p3 are 1 ≀ K = 2) Game 4: p1-p2, p1-p3, p2-p3 (numbers of bondings of p1, p2, p3 are 2 ≀ K = 2) For the 2nd test case, we cannot form the game, because K = 0 and hence no player is allowed to make any bonding. As any game must have atleast one bonding, no game is possible here. For the 3rd case, only possible game is: Game 1: p1-p2 (number of bondings in p1, p2 are 1) ------ Constraints ------ 1 ≀ T ≀ 10000 0 ≀ N ≀ 10000 0 ≀ K ≀ N
import sys dp1 = [1, 1] dp2 = [1, 1] N = 10010 M = 100000000000007 for i in range(2, N): dp1.append((3 * (i - 1) * dp1[i - 2] + (2 * i + 1) * dp1[i - 1]) // (i + 2)) dp2.append(2 * (2 * i - 1) * dp2[i - 1] // (i + 1)) t = int(input()) while t: t = t - 1 n, k = input().split() if int(k) == 0: print("0") elif int(k) == 1: print((dp1[int(n)] - 1 + M) % M) else: print((dp2[int(n)] - 1 + M) % M)
IMPORT ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR VAR
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
k = int(input()) p = [2] for i in range(3, 102): t = True for j in range(2, i): if i % j == 0: t = False break if t: p.append(i) for _ in range(k): n = int(input()) lst = [int(i) for i in input().split()] e = sum([(1) for i in lst if i % 2 == 0]) o = len(lst) - e if len(lst) != len(list(set(lst))): print("NO") else: t = True for j in p: f = [0] * j for i, el in enumerate(lst): f[el % j] += 1 if min(f) >= 2: t = False break if t: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
t = int(input()) count = [([0] * 51) for _ in range(51)] while t > 0: for i in range(51): for j in range(51): count[i][j] = 0 n = int(input()) A = list(map(int, input().split())) ans = True for i in range(n): for j in range(i + 1, n): if A[j] == A[i]: ans = False break if ans == False: break if ans: for i in A: for j in range(2, 51): count[j][i % j] += 1 if ans: for i in range(2, 51): ans = False for j in range(i): if count[i][j] < 2: ans = True break if ans == False: break if ans: print("YES") else: print("NO") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER IF VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) wefucked = "YES" for i in range(2, n): cnt = [0] * i for j in range(n): cnt[a[j] % i] += 1 if min(cnt) >= 2: wefucked = "NO" break for i in range(n): for l in range(i + 1, n): if a[i] == a[l]: wefucked = "NO" break print(wefucked)
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 STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] for s in [*open(0)][2::2]: a = [*map(int, s.split())] if len(a) != len({*a}): print("NO") continue for p in P: cnt = [0] * p for x in a: cnt[x % p] += 1 if min(cnt) >= 2: print("NO") break else: print("YES")
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
tests = int(input()) for i in range(tests): length = int(input()) arr = list(map(int, input().split())) ans = "YES" if length != len(set(arr)): ans = "NO" else: for j in range(2, length // 2 + 1): freq = [0] * j for k in arr: rem = k % j freq[rem] += 1 if min(freq) >= 2: ans = "NO" print(ans)
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 STRING IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
for _ in range(int(input())): x = int(input()) y = list(map(int, input().split())) z = set(y) primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, ] countodd = 0 counteven = 0 for element in y: if element % 2 == 0: counteven += 1 else: countodd += 1 if min(countodd, counteven) == 2 or len(y) != len(z): print("NO") else: flag = False for p in primes: if flag: break L = [0] * p for element in y: rem = element % p L[rem] += 1 alpha = min(L) if alpha >= 2: flag = True if flag: print("NO") else: print("YES")
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 FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if len(set(a)) != len(a): print("NO") continue cnt = {p: {} for p in primes} for x in a: for p in primes: if x % p not in cnt[p]: cnt[p][x % p] = 0 cnt[p][x % p] += 1 for p in primes: if len(cnt[p]) == p and all(x > 1 for x in cnt[p].values()): print("NO") break else: print("YES")
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR DICT VAR VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
T = int(input()) for _ in range(T): n = int(input()) a = sorted(list(map(int, input().split()))) isSuccess = True for i in range(1, n): if a[i - 1] == a[i]: print("NO") isSuccess = False break if not isSuccess: continue for x in range(2, int(n // 2) + 1): cnt = [(0) for i in range(x)] for i in range(n): cnt[a[i] % x] += 1 isLowThan2 = False for i in range(x): if cnt[i] < 2: isLowThan2 = True if not isLowThan2: print("NO") isSuccess = False break if isSuccess: print("YES")
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
from itertools import groupby print( *map( lambda a: ["NO", "YES"][ len(a) == len({*a}) and all( sum(1 for _, v in groupby(sorted(x % p for x in a)) if len([*v]) > 1) < p for p in ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ) ) ], map(lambda s: [*map(int, s.split())], [*open(0)][2::2]), ), sep="\n" )
EXPR FUNC_CALL VAR FUNC_CALL VAR LIST STRING STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR LIST VAR NUMBER VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
import sys T = int(sys.stdin.readline().strip()) for t in range(0, T): n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().strip().split())) ans = True if len(set(a)) != n: ans = False for i in range(2, n): c = set() d = set() for x in a: if x % i in c: d.add(x % i) c.add(x % i) if len(d) == i: ans = False if ans: print("YES") else: print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
M = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] def g(X): for j in X: if j < 2: return False return True def f(L, n): x = 0 while x < 25 and M[x] <= n // 2 + 1: x += 1 for i in range(x): c = M[i] S = [0] * c for b in L: v = b % c S[v] += 1 if g(S): return "NO" L.sort() for i in range(n - 1): if L[i] == L[i + 1]: return "NO" return "YES" n = int(input()) for i in range(n): x = int(input()) L = list(map(int, input().split())) print(f(L, x))
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING RETURN STRING 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 FUNC_CALL VAR VAR VAR
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
T = int(input()) prime = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ] for t in range(T): n = int(input()) a = list(map(int, input().split())) cnt = {} flag = True for k in prime: cnt[k] = set() for i in range(n - 1): for j in range(i + 1, n): if (a[i] - a[j]) % k == 0: cnt[k].add(a[i] % k) if len(cnt[k]) == k: flag = False if len(set(a)) == n and flag: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
import sys def fn(a, l): repeat_check = set(a) if len(repeat_check) != l: return "NO" for i in range(2, l): mask = [0] * i for item in a: mask[item % i] += 1 if min(mask) >= 2: return "NO" return "YES" input = sys.stdin.readlines() for i in range(int(input[0].strip("\n"))): l = int(input[2 * i + 1].strip("\n")) a = [int(x) for x in input[2 * i + 2].strip("\n").split(" ")] print(fn(a, l))
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER STRING STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
def prime(x): return all(x % i for i in range(2, min(x, int(x**0.5) + 5))) pr = [x for x in range(2, 1001) if prime(x)] for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = sorted(a) if any(b[i] == b[i + 1] for i in range(n - 1)): print("NO") continue ok = True for x in pr: if x > n: break rm = [False] * x for t in a: rm[t % x] += 1 if all(y > 1 for y in rm): ok = False break print("YES" if ok else "NO")
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
def solve(a, n): a = sorted(a) for j in range(n - 1): if a[j] == a[j + 1]: print("NO") return for m in range(2, int(n / 2) + 3): mod = [0] * m for a_i in a: mod[a_i % m] += 1 if min(mod) > 1: print("NO") return print("YES") T = int(input()) for t in range(T): s = input() n = int(s) a = [int(si) for si in input().split()] solve(a, n)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if len(set(a)) != n: print("NO") else: flag = False for i in range(2, n // 2 + 1): ost = [0] * i for j in a: ost[j % i] += 1 ans = 0 for j in ost: if j > 1: ans += 1 if ans == i: flag = True break if flag: print("NO") else: print("YES")
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 IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
T = int(input()) for _ in range(T): n = int(input()) a = list(map(int, input().split())) if len(a) != len({*a}): print("NO") continue ans = True for i in range(2, 55): cnt = [0] * i for x in a: cnt[x % i] += 1 if min(cnt) >= 2: ans = False print("YES" if ans else "NO")
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 IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
Joi has an array $a$ of $n$ positive integers. Koxia wants you to determine whether there exists a positive integer $x > 0$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$. Here $\gcd(y, z)$ denotes the greatest common divisor (GCD) of integers $y$ and $z$. -----Input----- Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) β€” the number of test cases. The description of test cases follows. The first line of each test case contains an integer $n$ ($2 \leq n \leq 100$) β€” the size of the array. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq {10}^{18}$). It is guaranteed that the sum of $n$ over all test cases does not exceed $1000$. -----Output----- For each test case, output "YES" (without quotes) if there exists a positive integer $x$ such that $\gcd(a_i+x,a_j+x)=1$ for all $1 \leq i < j \leq n$, and "NO" (without quotes) otherwise. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. -----Examples----- Input 2 3 5 7 10 3 3 3 4 Output YES NO -----Note----- In the first test case, we can set $x = 4$. This is valid because: When $i=1$ and $j=2$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$. When $i=1$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$. When $i=2$ and $j=3$, $\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$. In the second test case, any choice of $x$ makes $\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$. Therefore, no such $x$ exists.
t = int(input("")) mx = 0 inputs = [] arrays = [] for _ in range(t): n = int(input("")) a = [int(x) for x in input("").split(" ")] inputs.append(n) arrays.append(a) mx = max(mx, n // 2) p = [1] * (mx + 1) p[0] = 0 p[1] = 0 i = 2 while i * i <= mx: if p[i]: j = i * i while j <= mx: p[j] = 0 j += i i += 1 v = [0] * (mx + 1) for s in range(t): n = inputs[s] a = arrays[s] h = set(a) good1 = len(h) == len(a) good2 = True for i in range(n // 2 + 1): if p[i]: for x in a: v[x % i] += 1 good3 = False for x in range(i): if v[x % i] <= 1: good3 = True break for x in a: v[x % i] -= 1 if not good3: good2 = False break print(["NO", "YES"][good1 and good2])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN 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 ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR FOR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR VAR