exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
sequencelengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
e87664b3ae2f7dd2d428338d82c991b2
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws Exception { // write your code here // System.out.println("ashik"); // out.write("helooo"); int test = sc.nextInt(); while (test-->0){ solution(); } } static void solution() { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } if(a[0]%2 == 0){ System.out.println("NO"); return; } boolean ispossible = true; for(int i=0;i<n;i++){ boolean flag = false; for(int j = i+2;j>=2;j--){ if(a[i]%j !=0){ flag = true; break; } } ispossible = ispossible & flag; } if(ispossible) System.out.println("YES"); else System.out.println("NO"); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
b5ac11ab82558ced2a9b8b881c7f10ea
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t!=0){ t--; int n = sc.nextInt(); boolean ok = true; for(int i=1;i<=n;i++){ boolean found = false; int x = sc.nextInt(); for(int j=i+1;j>=2;j--){ if(x%j!=0){ found = true; break; } } ok &= found; } if(ok){System.out.println("YES");}else System.out.println("NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
a520e963432e6ff45fa06e43a6d618a5
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class DivisibleConf { //only have to check the first 22 digits. If the first 22 digits are erasable, the rest of the >= 23 digits are all erasable. public static void main(String[] args) throws Exception { CustomScanner sc = new CustomScanner(); CustomPrinter cp = new CustomPrinter(); int T = sc.nextInt(); for (int t =0; t < T; t++){ int n = sc.nextInt(); boolean valid = true; for (int i = 1; i <= n; i++){ int x = sc.nextInt(); boolean found = false; for(int j = i+1;j>=2;j--){ if (x%j!=0){ // if undivisable by any of the numbers from 1 to i, it means we can erase it. found = true; break; } } valid = valid & found; } if(valid){ cp.print("YES\n"); }else{ cp.print("NO\n"); } } cp.close(); } static class CustomScanner { private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public CustomScanner(InputStream in) { this.in = in; } public CustomScanner() { this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b))); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b))); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)); } n = n * 10 + digit; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(int length) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map) { long[] array = new long[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = this.nextInt(); return array; } public int[][] nextIntArrayMulti(int length, int width) { int[][] arrays = new int[width][length]; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) arrays[j][i] = this.nextInt(); } return arrays; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map) { int[] array = new int[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map) { double[] array = new double[length]; for (int i = 0; i < length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width) { long[][] mat = new long[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width) { int[][] mat = new int[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width) { double[][] mat = new double[height][width]; for (int h = 0; h < height; h++) for (int w = 0; w < width; w++) { mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width) { char[][] mat = new char[height][width]; for (int h = 0; h < height; h++) { String s = this.next(); for (int w = 0; w < width; w++) { mat[h][w] = s.charAt(w); } } return mat; } } static class CustomPrinter extends PrintWriter { public CustomPrinter(PrintStream stream) { super(stream); } public CustomPrinter() { super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if (x < 0) { sb.append('-'); x = -x; } x += Math.pow(10, -n) / 2; sb.append((long) x); sb.append("."); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; sb.append((int) x); x -= (int) x; } return sb.toString(); } @Override public void print(float f) { super.print(dtos(f, 20)); } @Override public void println(float f) { super.println(dtos(f, 20)); } @Override public void print(double d) { super.print(dtos(d, 20)); } @Override public void println(double d) { super.println(dtos(d, 20)); } public void printArray(int[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(int[] array) { this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n - 1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map) { this.printArray(array, " ", map); } public void printArray(long[] array, String separator) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(array[i]); super.print(separator); } super.println(array[n - 1]); } public void printArray(long[] array) { this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map) { int n = array.length; for (int i = 0; i < n - 1; i++) { super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n - 1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map) { this.printArray(array, " ", map); } } public static void safeSort(int[] array) { Integer[] temp = new Integer[array.length]; for (int n = 0; n < array.length; n++) { temp[n] = array[n]; } Arrays.sort(temp); for (int n = 0; n < array.length; n++) { array[n] = temp[n]; } } public static void safeSort(long[] array) { Long[] temp = new Long[array.length]; for (int n = 0; n < array.length; n++) { temp[n] = array[n]; } Arrays.sort(temp); for (int n = 0; n < array.length; n++) { array[n] = temp[n]; } } public static void safeSort(double[] array) { Double[] temp = new Double[array.length]; for (int n = 0; n < array.length; n++) { temp[n] = array[n]; } Arrays.sort(temp); for (int n = 0; n < array.length; n++) { array[n] = temp[n]; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
cc07bf9030d0a426235f1b9b5f12f6b9
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class F { public static void main(String[] args) { while (N-- > 0) { solve(); } out.close(); } public static void solve() { int M = sc.nextInt(); int[] a = new int[M + 1]; for (int i = 1; i <= M; i++) { a[i] = sc.nextInt(); } int div = 2; for (int i = 1; i <= M; i++) { if (a[i] % div == 0) { out.println("NO"); return; } div *= (i + 2) / gcd(div, i + 2); } out.println("YES"); } private static int gcd(int a, int b) { if (a < b) { int tmp = a; a = b; b = tmp; } while (b != 0) { a %= b; int tmp = a; a = b; b = tmp; } return a; } private static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); private static MyScanner sc = new MyScanner(); private static int N = sc.nextInt(); @SuppressWarnings("unused") private static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
04d5be1f05f1b5b31b3926e2f8d36db5
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* Rating: 1367 Date: 24-11-2021 Time: 22-19-26 Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class A_Di_visible_Confusion { public static void s() { int n = sc.nextInt(); int[] arr = sc.readArray(n); for(int i=0; i<arr.length; i++) { int div = i+2; boolean check = false; for(int j=0; j<=i; j++) { if(arr[i]%(div - j) != 0) { check = true; break; } } if(!check) { p.writeln("NO"); return; } } p.writeln("YES"); } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long[] a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int[] a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { char c = ' '; strb.append(str).append(c); } public void writeln(Object str) { char c = '\n'; strb.append(str).append(c); } public void writeln() { char c = '\n'; strb.append(c); } public void writes(int[] arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long[] arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int[] arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = new String(); try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1252e295d5a18a5622bee77d3c744461
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* Rating: 1367 Date: 24-11-2021 Time: 22-19-26 Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class A_Di_visible_Confusion { public static void s() { int n = sc.nextInt(); int[] arr = sc.readArray(n); for(int i=0; i<arr.length; i++) { int div = i+2; boolean check = false; for(int j=0; j<=i; j++) { if(arr[i]%(div - j) != 0) { check = true; break; } } if(!check) { p.writeln("NO"); return; } } p.writeln("YES"); } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long[] a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int[] a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { char c = ' '; strb.append(str).append(c); } public void writeln(Object str) { char c = '\n'; strb.append(str).append(c); } public void writeln() { char c = '\n'; strb.append(c); } public void writes(int[] arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long[] arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int[] arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = new String(); try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d591387b4c6ffebe5785c5f695d33f91
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* Rating: 1367 Date: 24-11-2021 Time: 22-19-26 Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class A_Di_visible_Confusion { public static void s() { int n = sc.nextInt(); int[] arr = sc.readArray(n); int x = 0; for(int i=0; i<arr.length; i++) { int div = i+2; boolean check = false; for(int j=0; j<=x; j++) { if(arr[i]%(div - j) != 0) { x++; check = true; break; } } if(!check) { p.writeln("NO"); return; } } p.writeln("YES"); } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long[] a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int[] a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { char c = ' '; strb.append(str).append(c); } public void writeln(Object str) { char c = '\n'; strb.append(str).append(c); } public void writeln() { char c = '\n'; strb.append(c); } public void writes(int[] arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long[] arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int[] arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = new String(); try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
076854bb1de3d875e5b1471909655c13
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; public class P1603A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0) { //O(n^2) I think, hope this works int n = s.nextInt(); boolean ans = true; for(int i = 1; i<=n; i++) { int cur = s.nextInt(); boolean temp = false; for(int j = i+1; j>=2; j--) { if(cur%j!=0) { temp = !temp; break; } } ans = ans&temp; } System.out.println((ans)?"YES":"NO"); } s.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
bea15e1e7169a06e341c719443d992bc
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
// nuber theorey // if the given ai is not divisible by any of the given i(1<+i<=21) ie because of the constraint // that ai<10riseto9 so if the number is not divisible from 1till22 then it has to be greater than // 10,9 as lcm(2,...23)>10,9 . therefore only chech for the first 21 indices . import java.util.Scanner; public class DivisibleConfusion1603A { static Scanner sc; static void solve() { int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } boolean res=true; for(int i=0;i<Math.min(21,a.length);i++) { boolean ok = false; for(int j=2;j<=i+2;j++) { if(a[i]%j!=0) { ok=true; break; } } res=(res&&ok); } if(res) { System.out.println("YES"); } else { System.out.println("NO"); } } public static void main(String[] args) { sc = new Scanner(System.in); int test = sc.nextInt(); while (test-->0) solve(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
08ff33baf11f8bf2b632d7d95637cbc9
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
//( ̄﹏ ̄;) //(*  ̄︿ ̄) import java.util.*; import java.io.*; public class Main { private static FS sc = new FS(); private static class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } private static class extra { static int[] intArr(int size) { int[] a = new int[size]; for(int i = 0; i < size; i++) a[i] = sc.nextInt(); return a; } static long[] longArr(int size) { long[] a = new long[size]; for(int i = 0; i < size; i++) a[i] = sc.nextLong(); return a; } static long intSum(int[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static long longSum(long[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static LinkedList[] graphD(int vertices, int edges) { LinkedList<Integer>[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); } return temp; } static LinkedList[] graphUD(int vertices, int edges) { LinkedList<Integer>[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); temp[y].add(x); } return temp; } static void printG(LinkedList[] temp) { for(LinkedList<Integer> aa:temp) System.out.println(aa); } static long cal(long val, long pow, long mod) { if(pow == 0) return 1; long res = cal(val, pow/2, mod); long ret = (res*res)%mod; if(pow%2 == 0) return ret; return (val*ret)%mod; } static long gcd(long a, long b) { return b == 0 ? a:gcd(b, a%b); } } static int mod = (int) 1e9 + 7; static LinkedList<String>[] temp, temp2; static int inf = (int) 1e9; // static long inf = Long.MAX_VALUE; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(), bigflag = 0; int[] a = extra.intArr(n); for(int i = 0; i < n; i++) { int val = 1; while(a[i]%val == 0) val++; if(val > i+2) { bigflag = 1; break; } } ret.append(bigflag == 1 ? "NO\n":"YES\n"); } System.out.println(ret); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
8e560bc9ab43b19c5085e0a4abb4f5e0
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class solutioncode { static long mod=1000000007; static boolean ans; public static void main(String[] args) { // Scanner s = new Scanner(System.in); MyScanner s = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int testcases=s.nextInt(); while(testcases-->0) { int n=s.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=s.nextInt(); } boolean ans=true; for(int i=0;i<n;i++){ int j=0; for(j=2;j<=i+2;j++) { if(arr[i]%j!=0) { break; } } if(j>i+2) { ans=false; break; } } if(ans)out.println("YES"); else out.println("NO"); } out.close(); } // } static long gcd(long a, long b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a-b, b); return gcd(a, b-a); } public static PrintWriter out; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1d5bd9041cc9bf5117b06c6a3c93a1b2
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class _752 { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); long [] a = new long[n + 1]; for (int i = 1; i <= n; i++) a[i] = sc.nextLong(); boolean ok = false; for (int i = 1; i <= Math.min(n, 25); i++) { boolean div = true; for (int j = 1; j <= i; j++) div = div && a[i] % (j + 1) == 0; ok = ok || div; } out.println(ok ? "NO" : "YES"); } out.close(); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
97996a8667298f1d6d52f77b83a5fc70
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class SolutionA extends Thread { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static final FastReader scanner = new FastReader(); private static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { new Thread(null, new SolutionA(), "Main", 1 << 28).start(); } public void run() { int t = scanner.nextInt(); for (int i = 0; i < t; i++) { solve(); } out.close(); } private static void solve() { int n = scanner.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scanner.nextInt(); } long lcm = 1; for (int i = 0; i < n; i++) { if (lcm <= 1_000_000_000) { lcm = lcm(lcm, i + 2); } if (a[i] % lcm == 0) { out.println("NO"); return; } } out.println("YES"); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
091ce8929526f5dada33df96bb146cb4
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.net.Inet4Address; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class Main { static long M = (long) (1e9 + 7); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if (st.hasMoreTokens()) { str = st.nextToken("\n"); } else { str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } public static void swap(int[] a, long i, long j) { long temp = a[(int) i]; a[(int) i] = a[(int) j]; a[(int) j] = (int) temp; } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static int lcm(long a, long b) { return (int) (a * b / gcd(a, b)); } public static String sortString(String inputString) { char[] tempArray = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static boolean isSquare(int n) { int v = (int) Math.sqrt(n); return v * v == n; } static boolean PowerOfTwo(int n) { if (n == 0) return false; return (int) (Math.ceil((Math.log(n) / Math.log(2)))) == (int) (Math.floor(((Math.log(n) / Math.log(2))))); } static int power(long a, long b) { long res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = ((a * a) % M); b = b / 2; } return (int) res; } public static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) { return false; } return true; } static long computeXOR(long n) { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } static long binaryToInteger(String binary) { char[] numbers = binary.toCharArray(); long result = 0; for (int i = numbers.length - 1; i >= 0; i--) if (numbers[i] == '1') result += Math.pow(2, (numbers.length - i - 1)); return result; } static String reverseString(String str) { char ch[] = str.toCharArray(); String rev = ""; for (int i = ch.length - 1; i >= 0; i--) { rev += ch[i]; } return rev; } static int countFreq(int[] arr, int n) { HashMap<Integer, Integer> map = new HashMap<>(); int x = 0; for (int i = 0; i < n; i++) { map.put(arr[i], map.getOrDefault(arr[i], 0) + 1); } for (int i = 0; i < n; i++) { if (map.get(arr[i]) == 1) x++; } return x; } static void reverse(int[] arr, int l, int r) { int d = (r - l + 1) / 2; for (int i = 0; i < d; i++) { int t = arr[l + i]; arr[l + i] = arr[r - i]; arr[r - i] = t; } } static void sort(String[] s, int n) { for (int i = 1; i < n; i++) { String temp = s[i]; int j = i - 1; while (j >= 0 && temp.length() < s[j].length()) { s[j + 1] = s[j]; j--; } s[j + 1] = temp; } } static int sqr(int n) { double x = Math.sqrt(n); if ((int) x == x) return (int) x; else return (int) (x + 1); } static int set_bits_count(int num) { int count = 0; while (num > 0) { num &= (num - 1); count++; } return count; } static double factorial(double n) { double f = 1; for (int i = 1; i <= n; i++) { f = f * i; } return f; } static boolean palindrome(int arr[], int n) { boolean flag = true; for (int i = 0; i <= n / 2 && n != 0; i++) { if (arr[i] != arr[n - i - 1]) { flag = false; break; } } return flag; } public static boolean isSorted(int[] a) { if (a == null || a.length <= 1) { return true; } for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } public static boolean Consecutive(List<Integer> a, int[] b, int n, int m) { int i = 0, j = 0; while (i < n && j < m) { if (Objects.equals(a.get(i), b[j])) { i++; j++; if (j == m) return true; } else { i = i - j + 1; j = 0; } } return false; } static class Pair { int l; int r; public Pair(int l, int r) { this.l = l; this.r = r; } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); FastReader sc = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- != 0) { int n = sc.nextInt(); boolean ans = true; for(int i = 1; i<=n; i++) { int cur = sc.nextInt(); boolean temp = false; for(int j = i+1; j>=2; j--) { if(cur%j!=0) { temp = !temp; break; } } ans = ans&temp; } System.out.println((ans)?"YES":"NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
3d55587ce05ab1915a51e602eb2f570b
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class divisibleconfusion { static Scanner sc=new Scanner(System.in); static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { long t=sc.nextLong(); while(t-->0){ solve(); } out.close(); } private static void solve() { int n=sc.nextInt();; int prev=0; boolean flag=true; for(int i=1;i<=n;i++){ int x=sc.nextInt(); boolean found=false; for(int j=i+1;j>=2;j--){ if(x%j!=0){ found=true; break; } } flag&=found; } // for(int i=1;i<=n;i++){ // int x=sc.nextInt(); // if(x%(i+1)!=0) prev++; // else{ // flag=false; // for(int j=1;j<=prev;j++){ // if(x%(i+1-j)!=0){ // flag=true; // prev++; // break; // } // } // } // } if(flag){ out.println("yes"); } else out.println("no"); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
a5cf13260dd6a032b517a1c5d0c57fc8
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class CF_1603A { PrintWriter out; StringTokenizer st; BufferedReader br; final int imax = Integer.MAX_VALUE, imin = Integer.MIN_VALUE; final int mod = 1000000007; void solve() throws Exception { int t = 1; t = ni(); precompute(); // print(lcm); for (int ii = 0; ii < t; ii++) { int n = ni(); int[] arr = ni(n, 1); // print(arr); boolean ans = true; for (int i = 1; i < arr.length && ans; i++) { if (arr[i] % lcm[i] == 0) ans = false; } print(ans); } } long[] lcm = new long[100000+2]; private void precompute() { Map<Long, Integer> curr = new HashMap<>(); for (int i = 1; i < 100001; i++) { Map<Long, Integer> map = primeFactorization(i+1); merge(curr, map); lcm[i] = calculate(curr); } } private long calculate(Map<Long, Integer> curr) { long lcm = 1l; for (long key: curr.keySet()) { lcm *= binExp(key, curr.get(key)); if (lcm > imax) return imax; } return lcm; } private void merge(Map<Long, Integer> curr, Map<Long, Integer> map) { for(long key: map.keySet()) { curr.put(key, Math.max(curr.getOrDefault(key, 0), map.get(key))); } } private Map<Long, Integer> primeFactorization ( long n){ Map<Long, Integer> map = new HashMap<>(); while (n % 2 == 0) { map.put(2l, map.getOrDefault(2l, 0) + 1); n >>= 1; } for (long i = 3; i <= Math.sqrt(n); i += 2) { while (n % i == 0) { map.put(i, map.getOrDefault(i * 1l, 0) + 1); n /= i; } } if (n > 1) map.put(n, map.getOrDefault(n, 0) + 1); return map; } public static void main(String[] args) throws Exception { new CF_1603A().run(); } void run() throws Exception { if (System.getProperty("ONLINE_JUDGE") == null) { File file = new File("./input.txt"); br = new BufferedReader(new FileReader(file)); out = new PrintWriter("./output.txt"); } else { out = new PrintWriter(System.out); br = new BufferedReader(new InputStreamReader(System.in)); } long ss = System.currentTimeMillis(); st = new StringTokenizer(""); while (true) { try { solve(); } catch (Exception e) { e.printStackTrace(out); } catch (StackOverflowError e) { e.printStackTrace(out); } String s = br.readLine(); if (s == null) break; else st = new StringTokenizer(s); } //out.println(System.currentTimeMillis()-ss+"ms"); out.flush(); } void read() throws Exception { st = new StringTokenizer(br.readLine()); } int ni() throws Exception { if (!st.hasMoreTokens()) read(); return Integer.parseInt(st.nextToken()); } char nc() throws Exception { if (!st.hasMoreTokens()) read(); return st.nextToken().charAt(0); } String nw() throws Exception { if (!st.hasMoreTokens()) read(); return st.nextToken(); } long nl() throws Exception { if (!st.hasMoreTokens()) read(); return Long.parseLong(st.nextToken()); } int[] ni(int n) throws Exception { int[] ret = new int[n]; for (int i = 0; i < n; i++) ret[i] = ni(); return ret; } int[] ni(int n, int index) throws Exception { int[] ret = new int[n + index]; for (int i = index; i < n + index; i++) ret[i] = ni(); return ret; } long[] nl(int n) throws Exception { long[] ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = nl(); return ret; } double nd() throws Exception { if (!st.hasMoreTokens()) read(); return Double.parseDouble(st.nextToken()); } String ns() throws Exception { String s = br.readLine(); return s.length() == 0 ? br.readLine() : s; } void print(int[] arr) { for (int i : arr) out.print(i + " "); out.println(); } void print(long[] arr) { for (long i : arr) out.print(i + " "); out.println(); } void print(int[][] arr) { for (int[] i : arr) { for (int j : i) out.print(j + " "); out.println(); } } void print(long[][] arr) { for (long[] i : arr) { for (long j : i) out.print(j + " "); out.println(); } } long add(long a, long b) { if (a + b >= mod) return (a + b) - mod; else return a + b >= 0 ? a + b : a + b + mod; } long mul(long a, long b) { return (a * b) % mod; } void print(boolean b) { if (b) out.println("YES"); else out.println("NO"); } long binExp(long base, long power) { long res = 1l; while (power != 0) { if ((power & 1) == 1) res = mul(res, base); base = mul(base, base); power >>= 1; } return res; } long gcd(long a, long b) { if (b == 0) return a; else return gcd(b, a % b); } // strictly smaller on left void stack_l(int[] arr, int[] left) { Stack<Integer> stack = new Stack<>(); for (int i = 0; i < arr.length; i++) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) stack.pop(); if (stack.isEmpty()) left[i] = -1; else left[i] = stack.peek(); stack.push(i); } } // strictly smaller on right void stack_r(int[] arr, int[] right) { Stack<Integer> stack = new Stack<>(); for (int i = arr.length - 1; i >= 0; i--) { while (!stack.isEmpty() && arr[stack.peek()] >= arr[i]) stack.pop(); if (stack.isEmpty()) right[i] = arr.length; else right[i] = stack.peek(); stack.push(i); } } private void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i : arr) list.add(i); Collections.sort(list); for (int i = 0; i < arr.length; i++) arr[i] = list.get(i); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
dd5eed517a42f644cb3c2e03b566052d
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class JavaApplication1 { static ArrayList<String> arr = new ArrayList<>(); static int num = 0; static long mod = (long) 1e9 + 7; public static void main(String[] args) throws IOException { BufferedWriter print = new BufferedWriter(new OutputStreamWriter(System.out)); fast in = new fast(); int t = in.nextInt(); while (t-- != 0) { int n = in.nextInt(); boolean done = false; int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); } for (int i = 0; i < n; i++) { done = false; for (int j = 2; j <= i + 2; j++) { if (arr[i] % j != 0) { done = true; break; } } if (!done) { break; } } if (done) { System.out.println("YES"); } else { System.out.println("NO"); } } } public static long fastPower(long x, long y) { long result = 1; while (y > 0) { if ((y & 1) == 0) { x *= x; y >>>= 1; } else { result *= x; y--; } } return result; } public static long binpow(long a, long b) { a %= mod; long out = 1; while (b > 0) { if ((b & 1) != 1) { } else { out = (out * a % mod); } a = (a * a % mod); b >>= 1; } return out; } static long LowerBound(long a[], long x) { long l = -1, r = a.length; while (l + 1 < r) { long m = (l + r) >>> 1; if (a[(int) m] >= x) { r = m; } else { l = m; } } return r; } public static boolean isPrime(long num) { if (num <= 1) { return false; } else { long sq = (long) Math.sqrt(num) + 1; for (long i = 2; i < sq; i++) { if (num % i == 0) { return false; } } return true; } } public static boolean checkPalindrome(String x) { String temp = ""; if (x.length() % 2 == 0) { for (int i = x.subSequence(x.length() / 2, x.length()).length() - 1; i >= 0; i--) { temp += x.subSequence(x.length() / 2, x.length()).charAt(i); } return x.substring(0, x.length() / 2).equals(temp); } else { for (int i = x.subSequence(x.length() / 2, x.length()).length() - 1; i > 0; i--) { temp += x.subSequence(x.length() / 2, x.length()).charAt(i); } return x.substring(0, x.length() / 2).equals(temp); } } public static boolean isVowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') { return true; } else { return false; } } public static void sub(String s, String ans) { if (s.length() == 0) { arr.add(ans); return; } sub(s.substring(1), ans + s.charAt(0)); sub(s.substring(1), ans); } public static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } public static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static class fast { BufferedReader br; StringTokenizer st; public fast() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } double nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
82310a7d9fd6efea0ad35a92c152dfbd
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces{ static long mod = 1000000007L; // map.put(a[i],map.getOrDefault(a[i],0)+1); // map.putIfAbsent; static MyScanner sc = new MyScanner(); //<----------------------------------------------WRITE HERE-------------------------------------------> static void solve(){ int n = sc.nextInt(); int[] a = sc.readIntArray(n); for(int i=1;i<=n;i++) { int temp = a[i-1]; boolean flag = true; for(int j = i+1;j>=2;j--) { if(temp%j != 0) { flag = false; break; } } if(flag) { out.println("NO"); return; } } out.println("YES"); } //<----------------------------------------------WRITE HERE-------------------------------------------> static void swap(int[] a,int i,int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static int LowerBound(int a[], int x) { int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static int UpperBound(int a[], int x) { int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static boolean isPali(String str){ int i = 0; int j = str.length()-1; while(i<j){ if(str.charAt(i)!=str.charAt(j)){ return false; } i++; j--; } return true; } static void priArr(int[] a) { for(int i=0;i<a.length;i++) { out.print(a[i] + " "); } out.println(); } static long gcd(long a,long b){ if(b==0) return a; return gcd(b,a%b); } static String reverse(String str){ char arr[] = str.toCharArray(); int i = 0; int j = arr.length-1; while(i<j){ char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } String st = new String(arr); return st; } static void reverse(int[] arr){ int i = 0; int j = arr.length-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } } static boolean isprime(int n){ if(n==1) return false; if(n==3 || n==2) return true; if(n%2==0 || n%3==0) return false; for(int i = 5;i*i<=n;i+= 6){ if(n%i== 0 || n%(i+2)==0){ return false; } } return true; } static class Pair implements Comparable<Pair>{ int val; int ind; Pair(int v,int f){ val = v; ind = f; } public int compareTo(Pair p){ if(this.val != p.val) return this.val-p.val; return this.ind - p.ind; } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i=0; i<arr.length; i++){ list.add(arr[i]); } Collections.sort(list); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
dba61f4bfc9f23411525e10bda101681
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static long mod = (int)1e9+7; static PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out)); public static void main (String[] args) throws java.lang.Exception { FastReader sc =new FastReader(); int t=sc.nextInt(); // int t=1; O : while(t-->0) { int n = sc.nextInt(); int a[] = sc.readArray(n); for (int i = 0; i < n; i++) { boolean find = false; for (int j = 2; j <= i + 2; j++) { if (a[i] % j != 0) { find = true; break; } } if (!find) { out.println("NO"); continue O; } } out.println("YES"); } out.flush(); } static void printN() { System.out.println("NO"); } static void printY() { System.out.println("YES"); } static int findfrequencies(int a[],int n) { int count=0; for(int i=0;i<a.length;i++) { if(a[i]==n) { count++; } } return count; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } static int[] EvenOddArragement(int nums[]) { int i1=0,i2=nums.length-1; while(i1<i2){ while(nums[i1]%2==0 && i1<i2){ i1++; } while(nums[i2]%2!=0 && i2>i1){ i2--; } int temp=nums[i1]; nums[i1]=nums[i2]; nums[i2]=temp; } return nums; } static int gcd(int a, int b) { while (b != 0) { int t = a; a = b; b = t % b; } return a; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static int DigitSum(int n) { int r=0,sum=0; while(n>=0) { r=n%10; sum=sum+r; n=n/10; } return sum; } static boolean checkPerfectSquare(int number) { double sqrt=Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean isPowerOfTwo(int n) { if(n==0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static boolean isPrime2(int n) { if (n <= 1) { return false; } if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (int i = 3; i <= Math.sqrt(n) + 1; i = i + 2) { if (n % i == 0) { return false; } } return true; } static String minLexRotation(String str) { int n = str.length(); String arr[] = new String[n]; String concat = str + str; for(int i=0;i<n;i++) { arr[i] = concat.substring(i, i + n); } Arrays.sort(arr); return arr[0]; } static String maxLexRotation(String str) { int n = str.length(); String arr[] = new String[n]; String concat = str + str; for (int i = 0; i < n; i++) { arr[i] = concat.substring(i, i + n); } Arrays.sort(arr); return arr[arr.length-1]; } static class P implements Comparable<P> { int i, j; public P(int i, int j) { this.i=i; this.j=j; } public int compareTo(P o) { return Integer.compare(i, o.i); } } static class pair{ int i,j; pair(int x,int y){ i=x; j=y; } } static int binary_search(int a[],int value) { int start=0; int end=a.length-1; int mid=start+(end-start)/2; while(start<=end) { if(a[mid]==value) { return mid; } if(a[mid]>value) { end=mid-1; } else { start=mid+1; } mid=start+(end-start)/2; } return -1; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d4d2cf180982133a4729bf9d070d9afc
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
//package Practise_problems; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class Lcm { public static void main(String []args) { FastScanner fs=new FastScanner(); int t=fs.nextInt(); for(int t1=0;t1<t;t1++) { int n=fs.nextInt(); int []arr=new int[n]; arr=fs.readArray(n); boolean flag=true; for(int i=1;i<=n;i++) { if(i<=23) { long val=findLcm(i+1); //System.out.println(val); if(arr[i-1]%val==0) { flag=false; break; } } else break; } if(flag) System.out.println("YES"); else System.out.println("NO"); } } public static long findLcm(int limit) { long lcm=1; for(int i=2;i<=limit;i++) { lcm=getlcm(i,lcm); } return lcm; } public static long getlcm(long a,long b) { return (a*b)/gcd(a,b); } public static long gcd(long l,long s) { if(s==0) return l; else return gcd(s,l%s); } static final Random random=new Random(); static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
c41b2f9b6de5a34912c6b844fe92727d
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.sort; public class Round12 { public static void main(String[] args) { FastReader fastReader = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = fastReader.nextInt(); while (t-- > 0) { int n = fastReader.nextInt(); int a[] = fastReader.ria(n); boolean ans = true; for (int i = 0; i < n; i++) { int j = 1; while (true) { if (a[i] % j != 0) break; j++; } if (j > i + 2) ans = false; } out.println(ans ? "YES" : "NO"); } out.close(); } // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final long LMAX = 9223372036854775807L; static Random __r = new Random(); // math util static int minof(int a, int b, int c) { return min(a, min(b, c)); } static int minof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } static long minof(long a, long b, long c) { return min(a, min(b, c)); } static long minof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } static int maxof(int a, int b, int c) { return max(a, max(b, c)); } static int maxof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } static long maxof(long a, long b, long c) { return max(a, max(b, c)); } static long maxof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } static int powi(int a, int b) { if (a == 0) return 0; int ans = 1; while (b > 0) { if ((b & 1) > 0) ans *= a; a *= a; b >>= 1; } return ans; } static long powl(long a, int b) { if (a == 0) return 0; long ans = 1; while (b > 0) { if ((b & 1) > 0) ans *= a; a *= a; b >>= 1; } return ans; } static int fli(double d) { return (int) d; } static int cei(double d) { return (int) ceil(d); } static long fll(double d) { return (long) d; } static long cel(double d) { return (long) ceil(d); } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static int[] exgcd(int a, int b) { if (b == 0) return new int[]{1, 0}; int[] y = exgcd(b, a % b); return new int[]{y[1], y[0] - y[1] * (a / b)}; } static long[] exgcd(long a, long b) { if (b == 0) return new long[]{1, 0}; long[] y = exgcd(b, a % b); return new long[]{y[1], y[0] - y[1] * (a / b)}; } static int randInt(int min, int max) { return __r.nextInt(max - min + 1) + min; } static long mix(long x) { x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31); } public static boolean[] findPrimes(int limit) { assert limit >= 2; final boolean[] nonPrimes = new boolean[limit]; nonPrimes[0] = true; nonPrimes[1] = true; int sqrt = (int) Math.sqrt(limit); for (int i = 2; i <= sqrt; i++) { if (nonPrimes[i]) continue; for (int j = i; j < limit; j += i) { if (!nonPrimes[j] && i != j) nonPrimes[j] = true; } } return nonPrimes; } // array util static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } static void rsort(int[] a) { shuffle(a); sort(a); } static void rsort(long[] a) { shuffle(a); sort(a); } static void rsort(double[] a) { shuffle(a); sort(a); } static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] ria(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer.parseInt(next()); return a; } long nextLong() { return Long.parseLong(next()); } long[] rla(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = Long.parseLong(next()); return a; } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
abf5edf1d61a0342cbd28902617e1e63
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. *******************************************************************************/ import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0){ int n = scn.nextInt(); int [] arr = new int[n+1]; for(int i = 1;i<=n;i++) arr[i] = scn.nextInt(); boolean flag2 = false; for(int i =1 ;i<=n;i++){ int val = arr[i]; boolean flag = false; for(int j = 1;j<=i;j++){ if(val % (j+1) != 0){ flag = true; break; } } if(flag == false){ flag2 = true; break; } } if(flag2){ System.out.println("NO"); } else{ System.out.println("YES"); } } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
4171c29e405a307d54d55c80bdc90310
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
// Created on: 8:53:04 PM | 11-Apr-2022 import java.util.*; import java.io.*; import java.math.*; import java.lang.*; public class Solution { static InputStream is; static PrintWriter out; static String INPUT = ""; static void solve() { int caseNo = 1; for (int T = sc.nextInt(); T > 0; T--, caseNo++) { solveIt(caseNo); } } // Solution static void solveIt(int t) { int n = sc.nextInt(); int a[] = sc.readIntArray(n); if (a[0] % 2 == 0) { System.out.println("NO"); return; } int c = 0; for (int i = 0; i < n; i++) { int ind = i + 2; boolean x = true; for (int j = 0; j <= c; j++) { if (a[i] % (ind - j) != 0) { x = false; break; } } if (x) { System.out.println("NO"); return; } c++; } System.out.println("YES"); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static void revArray(int a[], int i, int j) { while (i <= j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; i++; j--; } } static boolean isSorted(int a[], int s, int e, boolean strict) { for (int i = s + 1; i <= e; i++) { if (strict && a[i - 1] >= a[i]) return false; if (!strict && a[i - 1] > a[i]) return false; } return true; } static class DSU { int rank[]; int parent[]; DSU(int n) { rank = new int[n + 1]; parent = new int[n + 1]; for (int i = 1; i <= n; i++) { parent[i] = i; } } int findParent(int node) { if (parent[node] == node) return node; return parent[node] = findParent(parent[node]); } boolean union(int x, int y) { int px = findParent(x); int py = findParent(y); if (px == py) return false; if (rank[px] < rank[py]) { parent[px] = py; } else if (rank[px] > rank[py]) { parent[py] = px; } else { parent[px] = py; rank[py]++; } return true; } } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static boolean[] seiveOfEratosthenes(int n) { boolean[] isPrime = new boolean[n + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n; i++) { for (int j = i * i; j <= n; j += i) { isPrime[j] = false; } } return isPrime; } public static int[] seiveOnlyPrimes(int n) { if (n <= 32) { int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }; for (int i = 0; i < primes.length; i++) { if (n < primes[i]) { return Arrays.copyOf(primes, i); } } return primes; } int u = n + 32; double lu = Math.log(u); int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)]; ret[0] = 2; int pos = 1; int[] isp = new int[(n + 1) / 32 / 2 + 1]; int sup = (n + 1) / 32 / 2 + 1; int[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 }; for (int tp : tprimes) { ret[pos++] = tp; int[] ptn = new int[tp]; for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31); for (int i = 0; i < tp; i++) { for (int j = i; j < sup; j += tp) isp[j] |= ptn[i]; } } int[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 }; int h = n / 2; for (int i = 0; i < sup; i++) { for (int j = ~isp[i]; j != 0; j &= j - 1) { int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27]; int p = 2 * pp + 3; if (p > n) break; ret[pos++] = p; for (int q = pp; q <= h; q += p) isp[q >> 5] |= 1 << (q & 31); } } return Arrays.copyOf(ret, pos); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static boolean isPrime(long n) { if (n < 2) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); long G = System.currentTimeMillis(); sc.tr(G - S + "ms"); } static class sc { private static boolean endOfFile() { if (bufferLength == -1) return true; int lptr = ptrbuf; while (lptr < bufferLength) if (!isThisTheSpaceCharacter(inputBufffferBigBoi[lptr++])) return false; try { is.mark(1000); while (true) { int b = is.read(); if (b == -1) { is.reset(); return true; } else if (!isThisTheSpaceCharacter(b)) { is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inputBufffferBigBoi = new byte[1024]; static int bufferLength = 0, ptrbuf = 0; private static int justReadTheByte() { if (bufferLength == -1) throw new InputMismatchException(); if (ptrbuf >= bufferLength) { ptrbuf = 0; try { bufferLength = is.read(inputBufffferBigBoi); } catch (IOException e) { throw new InputMismatchException(); } if (bufferLength <= 0) return -1; } return inputBufffferBigBoi[ptrbuf++]; } private static boolean isThisTheSpaceCharacter(int c) { return !(c >= 33 && c <= 126); } private static int skipItBishhhhhhh() { int b; while ((b = justReadTheByte()) != -1 && isThisTheSpaceCharacter(b)) ; return b; } private static double nextDouble() { return Double.parseDouble(next()); } private static char nextChar() { return (char) skipItBishhhhhhh(); } private static String next() { int b = skipItBishhhhhhh(); StringBuilder sb = new StringBuilder(); while (!(isThisTheSpaceCharacter(b))) { sb.appendCodePoint(b); b = justReadTheByte(); } return sb.toString(); } private static char[] readCharArray(int n) { char[] buf = new char[n]; int b = skipItBishhhhhhh(), p = 0; while (p < n && !(isThisTheSpaceCharacter(b))) { buf[p++] = (char) b; b = justReadTheByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] readCharMatrix(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = readCharArray(m); return map; } private static int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } private static long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } private static int nextInt() { int num = 0, b; boolean minus = false; while ((b = justReadTheByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = justReadTheByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = justReadTheByte(); } } private static long nextLong() { long num = 0; int b; boolean minus = false; while ((b = justReadTheByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = justReadTheByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = justReadTheByte(); } } private static void tr(Object... o) { if (INPUT.length() != 0) System.out.println(Arrays.deepToString(o)); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
cc87db01f997520440e1fd37ed2e895e
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; public class DivisibleConfusion { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt();boolean yes=true,yo; int[] arr=new int[n+1]; for(int i=1;i<=n;i++) { arr[i]=sc.nextInt();yo=false; for(int j=i+1;j>=2;j--) { if(arr[i]%j!=0) { yo=true; break; } } yes&=yo; } System.out.println(yes?"YES":"NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1c5db8fa7afbe6c0799149fdb7d79a00
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
//package practice; import java.io.*;import java.util.*; public class Main { static boolean fun(long a[]) { for(int i=0;i<a.length;i++) { for(int j=0;j<=i;j++) { if(a[i]%(j+2)!=0) { break; } if(j==i) return false; } } return true; } public static void main(String[] args) throws IOException { FastReader fr=new FastReader(); int tt=1; tt=fr.nextInt(); while(tt-->0) { int n=fr.nextInt(); long a[]=new long[n]; for(int i=0;i<n;i++) { a[i]=fr.nextLong(); } if(fun(a)) { System.out.println("YES"); } else { System.out.println("NO"); } } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
b267a779b2323f1ab7104a68306f8908
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class cp { static int mod=(int)1e9+7; // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); static int[] sp; static int size=(int)1e6; static int[] arInt; static long[] arLong; public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // print_int(pre); // primeSet=new HashSet<>(); // primeCnt=new int[(int)1e9]; // sieveOfEratosthenes((int)1e9); while(tc-->0) { int n=sc.nextInt(); boolean flag=true; for(int i=1;i<=n;i++) { int x=sc.nextInt(); boolean temp=false; for(int j=i+1;j>=2;j--) { if(x%j!=0) { temp=true; break; } } flag&=temp; } printYesNo(flag); } out.flush(); out.close(); System.gc(); } /* ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE... */ static class Node{ int x; int y; ArrayList<Integer> edges; public Node(int x,int y) { // TODO Auto-generated constructor stub this.x=x; this.y=y; this.edges=new ArrayList<>(); } } static int lis(int arr[],int n) { int ans=0; int dp[]=new int[n+1]; Arrays.fill(dp, int_max); dp[0]=int_min; for(int i=0;i<n;i++) { int j=UpperBound(dp,arr[i]); if(dp[j-1]<=arr[i] && arr[i]<dp[j]) dp[j]=arr[i]; } for(int i=0;i<=n;i++) { if(dp[i]<int_max) ans=i; } return ans; } static long get(long n) { return n*(n+1)/2L; } static boolean go(ArrayList<Pair> caves,int k) { for(Pair each:caves) { if(k<=each.x) return false; k+=each.y; } return true; } static String revString(String s) { char arr[]=s.toCharArray(); int n=s.length(); for(int i=0;i<n/2;i++) { char temp=arr[i]; arr[i]=arr[n-i-1]; arr[n-i-1]=temp; } return String.valueOf(arr); } static void dfs(Graph gp,boolean[] vis,int node,int[] dp) { vis[node]=true; dp[node]=0; for(Integer child:gp.list[node]) { if(!vis[child]) { dfs(gp, vis, child, dp); } dp[node]=Math.max(dp[node], 1+dp[child]); } } // Fuction return the number of set bits in n static int SetBits(int n) { int cnt=0; while(n>0) { if((n&1)==1) { cnt++; } n=n>>1; } return cnt; } static boolean isPowerOfTwo(int n) { return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static void arrInt(int n) throws IOException { arInt=new int[n]; for (int i = 0; i < arInt.length; i++) { arInt[i]=sc.nextInt(); } } static void arrLong(int n) throws IOException { arLong=new long[n]; for (int i = 0; i < arLong.length; i++) { arLong[i]=sc.nextLong(); } } static ArrayList<Integer> add(int id,int c) { ArrayList<Integer> newArr=new ArrayList<>(); for(int i=0;i<id;i++) newArr.add(arInt[i]); newArr.add(c); for(int i=id;i<arInt.length;i++) { newArr.add(arInt[i]); } return newArr; } // function to find first index >= y static int upper(ArrayList<Integer> arr, int n, int x) { int l = 0, h = n - 1; while (h-l>1) { int mid = (l + h) / 2; if (arr.get(mid) <= x) l=mid+1; else { h=mid; } } if(arr.get(l)>x) { return l; } if(arr.get(h)>x) return h; return -1; } static int upper(ArrayList<Long> arr, int n, long x) { int l = 0, h = n - 1; while (h-l>1) { int mid = (l + h) / 2; if (arr.get(mid) <= x) l=mid+1; else { h=mid; } } if(arr.get(l)>x) { return l; } if(arr.get(h)>x) return h; return -1; } static int lower(ArrayList<Integer> arr, int n, int x) { int l = 0, h = n - 1; while (h-l>1) { int mid = (l + h) / 2; if (arr.get(mid) < x) l=mid+1; else { h=mid; } } if(arr.get(l)>=x) { return l; } if(arr.get(h)>=x) return h; return -1; } static int N = 501; // Array to store inverse of 1 to N static long[] factorialNumInverse = new long[N + 1]; // Array to precompute inverse of 1! to N! static long[] naturalNumInverse = new long[N + 1]; // Array to store factorial of first N numbers static long[] fact = new long[N + 1]; // Function to precompute inverse of numbers public static void InverseofNumber(int p) { naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i <= N; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse[0] = factorialNumInverse[1] = 1; // Precompute inverse of natural numbers for(int i = 2; i <= N; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to N public static void factorial(int p) { fact[0] = 1; // Precompute factorials for(int i = 1; i <= N; i++) { fact[i] = (fact[i - 1] * (long)i) % p; } } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R, int p) { // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; return ans; } static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList<Integer> ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList<Integer> temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList<Integer> commDiv(int a, int b) { // find gcd of a, b int n = gcd(a, b); // Count divisors of n. ArrayList<Integer> Div=new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { // if 'i' is factor of n if (n % i == 0) { // check if divisors are equal if (n / i == i) Div.add(i); else { Div.add(i); Div.add(n/i); } } } return Div; } static HashSet<Integer> factors(int x) { HashSet<Integer> a=new HashSet<Integer>(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static void primeFactors(int n,HashSet<Integer> factors) { // Print the number of 2s that divide n while (n%2==0) { factors.add(2); n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { factors.add(i); n /= i; } } // This condition is to handle the case when // n is a prime number greater than 2 if (n > 2) factors.add(n); } // static class Node // { // int vertex; // HashSet<Node> adj; // int deg; // Node(int ver) // { // vertex=ver; // deg=0; // adj=new HashSet<Node>(); // } // @Override // public String toString() // { // return vertex+" "; // } // } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap<Long,Long> findFactors(long n2) { HashMap<Long,Long> ans=new HashMap<>(); if(n2%2==0) { ans.put(2L, 0L); // cnt++; while((n2&1)==0) { n2=n2>>1; ans.put(2L, ans.get(2L)+1); // } } for(long i=3;i*i<=n2;i+=2) { if(n2%i==0) { ans.put((long)i, 0L); // cnt++; while(n2%i==0) { n2=n2/i; ans.put((long)i, ans.get((long)i)+1); } } } if(n2!=1) { ans.put(n2, ans.getOrDefault(n2, (long) 0)+1); } return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i<n;i++) out.print(getSum(i)+" "); out.println(); } } static class sparseTable{ int n; long[][]dp; int log2[]; int P; void buildTable(long[] arr) { n=arr.length; P=(int)Math.floor(Math.log(n)/Math.log(2)); log2=new int[n+1]; log2[0]=log2[1]=0; for(int i=2;i<=n;i++) { log2[i]=log2[i/2]+1; } dp=new long[P+1][n]; for(int i=0;i<n;i++) { dp[0][i]=arr[i]; } for(int p=1;p<=P;p++) { for(int i=0;i+(1<<p)<=n;i++) { long left=dp[p-1][i]; long right=dp[p-1][i+(1<<(p-1))]; dp[p][i]=gcd(left, right); } } } long maxQuery(int l,int r) { int len=r-l+1; int p=(int)Math.floor(log2[len]); long left=dp[p][l]; long right=dp[p][r-(1<<p)+1]; return gcd(left, right); } } //Function to find number of set bits static int setBitNumber(long n) { if (n == 0) return 0; int msb = 0; n = n / 2; while (n != 0) { n = n / 2; msb++; } return msb; } static int getFirstSetBitPos(long n) { return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1; } static ArrayList<Integer> primes; static HashSet<Integer> primeSet; static boolean prime[]; static int primeCnt[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeCnt[i]=primeCnt[i-1]+1; } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? "YES" : "NO"); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print_int(ArrayList<Integer> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void print_long(ArrayList<Long> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void printYesNo(boolean condition) { if (condition) { out.println("YES"); } else { out.println("NO"); } } static int LowerBound(int a[], int x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l<=h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid -1 ; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i<n;i++) { if(parent[i]==i) cnt++; } return cnt; } } static class Graph { int v; ArrayList<Integer> list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList<Integer>(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static class GraphMap{ // Map<String,ArrayList<String>> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap<String,ArrayList<String>>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet<String> vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } static double sum[]; static long cnt; // static void DFS(Graph g, boolean[] visited, int u) // { // visited[u]=true; // // for(int i=0;i<g.list[u].size();i++) // { // int v=g.list[u].get(i); // // if(!visited[v]) // { // cnt1=cnt1*2; // DFS(g, visited, v); // // } // // } // // // } static class Pair implements Comparable<Pair> { int x; int y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static class PairC implements Comparable<PairC> { char x; int y; PairC(char x,int y) { this.x=x; this.y=y; } @Override public int compareTo(PairC o) { // TODO Auto-generated method stub return o.y-this.y; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static long sum_array(long a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse_array(int a[]) { int n=a.length; int i,t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static void reverse_array(long a[]) { int n=a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static long power(long x, long y) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static int power(int x, int y) { int res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1cedf4eb3fc6ad74988800326fa46865
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.InputMismatchException; /** * Provide prove of correctness before implementation. Implementation can cost a lot of time. * Anti test that prove that it's wrong. * <p> * Do not confuse i j k g indexes, upTo and length. Do extra methods!!! Write more informative names to simulation * <p> * Will program ever exceed limit? * Try all approaches with prove of correctness if task is not obvious. * If you are given formula/rule: Try to play with it. * Analytic solution/Hardcoded solution/Constructive/Greedy/DP/Math/Brute force/Symmetric data * Number theory * Game theory (optimal play) that consider local and global strategy. */ public class MS_1_G { private void solveOne() { int n = nextInt(); int[] a = nextIntArr(n); //1 = 1_000_000_000; //[X, X, X ... X, X, X] //for any a[i] let's say do we have index j that: //i <= j && a[i] % (j + 2) != 0 //Time complexity O(23*n) int cnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { if(a[i] % (j + 2) != 0) { cnt++; break; } } } System.out.println(cnt == n ? "YES" : "NO"); } private void solve() { int t = System.in.readInt(); for (int tt = 0; tt < t; tt++) { solveOne(); } } private void simulationTest() { //2*3*5*7*11*13*17*19*21 > 1_000_000_000 int max = 0; for(int i = 1; i <= 1_000_000_000; i++) { int j = 2; for (; j <= i; j++) { if(i % j != 0) { break; } } max = Math.max(max, j); } System.out.println(max); } class AssertionRuntimeException extends RuntimeException { AssertionRuntimeException(Object expected, Object actual, Object... input) { super("expected = " + expected + ",\n actual = " + actual + ",\n " + Arrays.deepToString(input)); } } private int nextInt() { return System.in.readInt(); } private long nextLong() { return System.in.readLong(); } private String nextString() { return System.in.readString(); } private int[] nextIntArr(int n) { return System.in.readIntArray(n); } private long[] nextLongArr(int n) { return System.in.readLongArray(n); } public static void main(String[] args) { new MS_1_G().run(); } static class System { private static FastInputStream in; private static FastPrintStream out; } private void run() { System.in = new FastInputStream(java.lang.System.in); System.out = new FastPrintStream(java.lang.System.out); solve(); // simulationTest(); System.out.flush(); } private static class FastPrintStream { private static final int BUF_SIZE = 8192; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastPrintStream() { this(java.lang.System.out); } public FastPrintStream(OutputStream os) { this.out = os; } public FastPrintStream(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastPrintStream print(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastPrintStream print(char c) { return print((byte) c); } public FastPrintStream print(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastPrintStream print(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } //can be optimized public FastPrintStream print0(char[] s) { if (ptr + s.length < BUF_SIZE) { for (char c : s) { buf[ptr++] = (byte) c; } } else { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } } return this; } //can be optimized public FastPrintStream print0(String s) { if (ptr + s.length() < BUF_SIZE) { for (int i = 0; i < s.length(); i++) { buf[ptr++] = (byte) s.charAt(i); } } else { for (int i = 0; i < s.length(); i++) { buf[ptr++] = (byte) s.charAt(i); if (ptr == BUF_SIZE) innerflush(); } } return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastPrintStream print(int x) { if (x == Integer.MIN_VALUE) { return print((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { print((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastPrintStream print(long x) { if (x == Long.MIN_VALUE) { return print("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { print((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastPrintStream print(double x, int precision) { if (x < 0) { print('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } print((long) x).print("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; print((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastPrintStream println(int[] a, int from, int upTo, char separator) { for (int i = from; i < upTo; i++) { print(a[i]); print(separator); } print('\n'); return this; } public FastPrintStream println(int[] a) { return println(a, 0, a.length, ' '); } public FastPrintStream println(char c) { return print(c).println(); } public FastPrintStream println(int x) { return print(x).println(); } public FastPrintStream println(long x) { return print(x).println(); } public FastPrintStream println(String x) { return print(x).println(); } public FastPrintStream println(double x, int precision) { return print(x, precision).println(); } public FastPrintStream println() { return print((byte) '\n'); } public FastPrintStream printf(String format, Object... args) { return print(String.format(format, args)); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } } private static class FastInputStream { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastInputStream(InputStream stream) { this.stream = stream; } public double[] readDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = readDouble(); } return array; } public String[] readStringArray(int size) { String[] array = new String[size]; for (int i = 0; i < size; i++) { array[i] = readString(); } return array; } public char[] readCharArray(int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) { array[i] = readCharacter(); } return array; } public void readIntArrays(int[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readInt(); } } } public void readLongArrays(long[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readLong(); } } } public void readDoubleArrays(double[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readDouble(); } } } public char[][] readTable(int rowCount, int columnCount) { char[][] table = new char[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = this.readCharArray(columnCount); } return table; } public int[][] readIntTable(int rowCount, int columnCount) { int[][] table = new int[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = readIntArray(columnCount); } return table; } public double[][] readDoubleTable(int rowCount, int columnCount) { double[][] table = new double[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = this.readDoubleArray(columnCount); } return table; } public long[][] readLongTable(int rowCount, int columnCount) { long[][] table = new long[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = readLongArray(columnCount); } return table; } public String[][] readStringTable(int rowCount, int columnCount) { String[][] table = new String[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = this.readStringArray(columnCount); } return table; } public String readText() { StringBuilder result = new StringBuilder(); while (true) { int character = read(); if (character == '\r') { continue; } if (character == -1) { break; } result.append((char) character); } return result.toString(); } public void readStringArrays(String[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readString(); } } } public long[] readLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = readLong(); } return array; } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = readInt(); } return array; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int peekNonWhitespace() { while (isWhitespace(peek())) { read(); } return peek(); } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return readString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
55649fbb1ea3a2bc2286c34dbf0c246b
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Solution { static PrintWriter out; public static void main(String[] args) { FastReader in = new FastReader(); out = new PrintWriter(System.out); long t = in.nextLong(); long test = 1; while (test <= t) { //out.println("Case #" + test + ": " + solve(in)); solve(in); test++; } out.close(); } /*--------------------------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------------------------*/ private static void solve(FastReader in) { int n = in.nextInt(); int[] a = in.readArray(n); for (int i = 0; i < n; i++) { boolean find = false; for (int j = 2; j <= i + 2; j++) { assert j <= 30; if (a[i] % j != 0) { find = true; break; } } if (!find) { out.println("NO"); return; } } out.println("YES"); } /*--------------------------------------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------------------------------------*/ static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } private static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o) { return this.x == o.x ? this.y - o.y : this.x - o.x; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
5febf23482f6260b7deddf5d884e1fdd
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; ++i) { a[i] = sc.nextInt(); } System.out.println(solve(a) ? "YES" : "NO"); } sc.close(); } static boolean solve(int[] a) { List<Integer> rest = Arrays.stream(a).boxed().collect(Collectors.toList()); while (!rest.isEmpty()) { int index = rest.size() - 1; while (index != -1 && rest.get(index) % (index + 2) == 0) { --index; } if (index == -1) { return false; } rest.remove(index); } return true; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
3c54b9a04325fde8d208ffdfcf64e713
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); boolean ok = true; for (int i = 1; i <=n; i++) { boolean flag = false; int x = sc.nextInt(); for (int j = i + 1; j >= 2; j--) { if (x % j != 0) { flag = true; break; } } ok &= flag; } if (ok == true) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
7015a4cc902ee9707dc175f99b9db604
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; import java.util.ArrayList; public class divisible { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int b = s.nextInt(); for (int a = 0; a < b; a++) { ArrayList<Integer> nums = new ArrayList<Integer>(); int c = s.nextInt(); for (int i = 0; i < c; i++) { nums.add(s.nextInt()); } int lastsize = -1; while (!(nums.size() == lastsize) && lastsize != 0) { lastsize = nums.size(); for (int i = nums.size() - 1; i >= 0; i--) { if (nums.get(i) % (i + 2) != 0) { nums.remove(i); i=-1; } } } if (nums.size() == 0) { System.out.print("YES" + "\n"); } else { System.out.print("NO" + "\n"); } } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
0034bec7162714c71fceaba91cdd303a
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class A{ static FastScanner in; static PrintWriter out; public static void main(String[] args) { in = new FastScanner(); out = new PrintWriter(System.out); int t = in.nextInt(); while(t-- > 0) solve(); out.println(); out.close(); } static void solve() { int n = in.nextInt(); boolean passes = true; for(int i = 1; i <= n;i++) { int ix = in.nextInt(); boolean found = false; for(int j = i+1; j >= 2; j--) { if(ix%j != 0) { found = true; break; } } passes &= found; } if(passes) out.println("YES"); if(!passes) out.println("NO"); } static void Sort(int[] a) { ArrayList<Integer> ar = new ArrayList<>(); for(Integer i : a)ar.add(i); Collections.sort(ar); for(int i = 0; i < ar.size();i++ ) a[i] = ar.get(i); } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while(!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); }catch(IOException e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
861d2903e5df092c113ee02c9d32367a
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* بسم الله الرحمن الرحيم /$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ |__ $$ /$$__ $$ |$$ |$$ /$$__ $$ | $$| $$ \ $$| $$|$$| $$ \ $$ | $$| $$$$$$$$| $$ / $$/| $$$$$$$$ / $$ | $$| $$__ $$ \ $$ $$/ | $$__ $$ | $$ | $$| $$ | $$ \ $$$/ | $$ | $$ | $$$$$$/| $$ | $$ \ $/ | $$ | $$ \______/ |__/ |__/ \_/ |__/ |__/ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$ /$$$$$$$$ /$$$$$$$ | $$__ $$| $$__ $$ /$$__ $$ /$$__ $$| $$__ $$ /$$__ $$| $$$ /$$$| $$$ /$$$| $$_____/| $$__ $$ | $$ \ $$| $$ \ $$| $$ \ $$| $$ \__/| $$ \ $$| $$ \ $$| $$$$ /$$$$| $$$$ /$$$$| $$ | $$ \ $$ | $$$$$$$/| $$$$$$$/| $$ | $$| $$ /$$$$| $$$$$$$/| $$$$$$$$| $$ $$/$$ $$| $$ $$/$$ $$| $$$$$ | $$$$$$$/ | $$____/ | $$__ $$| $$ | $$| $$|_ $$| $$__ $$| $$__ $$| $$ $$$| $$| $$ $$$| $$| $$__/ | $$__ $$ | $$ | $$ \ $$| $$ | $$| $$ \ $$| $$ \ $$| $$ | $$| $$\ $ | $$| $$\ $ | $$| $$ | $$ \ $$ | $$ | $$ | $$| $$$$$$/| $$$$$$/| $$ | $$| $$ | $$| $$ \/ | $$| $$ \/ | $$| $$$$$$$$| $$ | $$ |__/ |__/ |__/ \______/ \______/ |__/ |__/|__/ |__/|__/ |__/|__/ |__/|________/|__/ |__/ */ import java.util.*; import java.lang.*; import java.io.*; public class DivisibleConfusion { public static void main(String[] args) throws java.lang.Exception { // your code goes here try { // Scanner sc=new Scanner(System.in); FastReader sc = new FastReader(); int t =sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } boolean pos=true; for(int i=0;i<n;i++){ int cnt=22; boolean done=true; for(int j=i+2;j>=2 && cnt>=0;j--,cnt--){ if(arr[i]%j!=0){ done=false; break; } } if(done){ pos=false; break; } } if(pos)System.out.println("YES"); else System.out.println("NO"); /*long[] arr=new long[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextLong(); }*/ } } catch (Exception e) { return; } } public static class pair{ int ff; int ss; pair(int ff,int ss){ this.ff=ff; this.ss=ss; } } static int BS(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] == element) { return low; } else if (arr[high] == element) { return high; } return -1; } static int lower_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] < element) { low = mid + 1; } else { high = mid; } } if (arr[low] >= element) { return low; } else if (arr[high] >= element) { return high; } return -1; } static int upper_bound(int[] arr, int l, int r, int element) { int low = l; int high = r; while (high - low > 1) { int mid = low + (high - low) / 2; if (arr[mid] <= element) { low = mid + 1; } else { high = mid; } } if (arr[low] > element) { return low; } else if (arr[high] > element) { return high; } return -1; } public static long gcd_long(long a,long b){ //a/b,a-> dividant b-> divisor if(b==0)return a; return gcd_long(b, a%b); } public static int gcd_int(int a,int b){ //a/b,a-> dividant b-> divisor if(b==0)return a; return gcd_int(b, a%b); } public static int lcm(int a,int b){ int gcd=gcd_int(a, b); return (a*b)/gcd; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() { String s = ""; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } Long nextLong() { return Long.parseLong(next()); } } /*JAVA STRING CONTAINS METHOD--------->str1.contains(str2)-->if(str2 is present in str1){ return true; } else return false; */ public static boolean contains(String main, String Substring) { boolean flag=false; if(main==null && main.trim().equals("")) { return flag; } if(Substring==null) { return flag; } char fullstring[]=main.toCharArray(); char sub[]=Substring.toCharArray(); int counter=0; if(sub.length==0) { flag=true; return flag; } for(int i=0;i<fullstring.length;i++) { if(fullstring[i]==sub[counter]) { counter++; } else { counter=0; } if(counter==sub.length) { flag=true; return flag; } } return flag; } } /* * public static boolean lie(int n,int m,int k){ if(n==1 && m==1 && k==0){ * return true; } if(n<1 || m<1 || k<0){ return false; } boolean * tc=lie(n-1,m,k-m); boolean lc=lie(n,m-1,k-n); if(tc || lc){ return true; } * return false; } */
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
bf6799422d02af6d021a99f2fe0f8f5a
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.io.UncheckedIOException; import java.io.Closeable; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) throws Exception { Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29); thread.start(); thread.join(); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput(inputStream); FastOutput out = new FastOutput(outputStream); ADiVisibleConfusion solver = new ADiVisibleConfusion(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } } static class ADiVisibleConfusion { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.ri(); int[] a = in.ri(n); for (int i = 0; i < n; i++) { boolean find = false; for (int j = 2; j <= i + 2; j++) { assert j <= 30; if (a[i] % j != 0) { find = true; break; } } if (!find) { out.println("NO"); return; } } out.println("YES"); } } static class FastInput { private final InputStream is; private StringBuilder defaultStringBuf = new StringBuilder(1 << 13); private byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastInput(InputStream is) { this.is = is; } public void populate(int[] data) { for (int i = 0; i < data.length; i++) { data[i] = readInt(); } } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { bufLen = -1; } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public String next() { return readString(); } public int ri() { return readInt(); } public int[] ri(int n) { int[] ans = new int[n]; populate(ans); return ans; } public int readInt() { boolean rev = false; skipBlank(); if (next == '+' || next == '-') { rev = next == '-'; next = read(); } int val = 0; while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } return rev ? val : -val; } public String readString(StringBuilder builder) { skipBlank(); while (next > 32) { builder.append((char) next); next = read(); } return builder.toString(); } public String readString() { defaultStringBuf.setLength(0); return readString(defaultStringBuf); } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 32 << 10; private OutputStream writer; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); private static Field stringBuilderValueField; private char[] charBuf = new char[THRESHOLD * 2]; private byte[] byteBuf = new byte[THRESHOLD * 2]; static { try { stringBuilderValueField = StringBuilder.class.getSuperclass().getDeclaredField("value"); stringBuilderValueField.setAccessible(true); } catch (Exception e) { stringBuilderValueField = null; } stringBuilderValueField = null; } public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(OutputStream writer) { this.writer = writer; } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(String c) { cache.append(c); afterWrite(); return this; } public FastOutput println(String c) { return append(c).println(); } public FastOutput println() { return append('\n'); } public FastOutput flush() { try { if (stringBuilderValueField != null) { try { byte[] value = (byte[]) stringBuilderValueField.get(cache); writer.write(value, 0, cache.length()); } catch (Exception e) { stringBuilderValueField = null; } } if (stringBuilderValueField == null) { int n = cache.length(); if (n > byteBuf.length) { //slow writer.write(cache.toString().getBytes(StandardCharsets.UTF_8)); // writer.append(cache); } else { cache.getChars(0, n, charBuf, 0); for (int i = 0; i < n; i++) { byteBuf[i] = (byte) charBuf[i]; } writer.write(byteBuf, 0, n); } } writer.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { writer.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
ce7a255616f6a6968ead89ebb8d73f81
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* _oo0oo_ o8888888o 88" . "88 (| -_- |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' */ import java.util.*; import java.math.*; import java.io.*; import java.lang.Math.*; public class KickStart2020 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static class Pair implements Comparable<Pair> { public int index; public int value; public Pair(int index,int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { // multiplied to -3 as the author need descending sort order if(other.index < this.index) return 3; if(other.index > this.index) return -3; else return 0; } @Override public String toString() { return this.index + " " + this.value; } } static boolean isPrime(long d) { if (d == 3) return false; for (int i = 2; i <= (long) Math.sqrt(d); i++) { if (d % i == 0) return false; } return true; } static void decimalTob(int n, int k, Stack<Integer> ss) { int x = n % k; int y = n / k; ss.push(x); if(y > 0) { decimalTob(y, k, ss); } } static long powermod(long x, long y, long mod) { long ans = 1; x = x % mod; if (x == 0) return 0; int i = 1; while (y > 0) { if ((y & 1) != 0) ans = (ans * x) % mod; y = y >> 1; x = (x * x) % mod; } return ans; } static long power(long x, long y) { long res = 1; while (y > 0) { if ((y & 1) != 0) res = res * x; y = y >> 1; x = x * x; } return res; } public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); outerloop: while(t-- > 0) { int n = sc.nextInt(); int arr[] = new int[n]; for(int i = 0; i < n; i++) arr[i] = sc.nextInt(); for(int i = 1; i <= n; i++) { boolean hachu = false; for(int j = i + 1; j >= 2; j--) { if(arr[i - 1] % j != 0) { hachu = true; break; } } if(!hachu) { out.println("NO"); continue outerloop; } } out.println("YES"); } out.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1c113db4f4a89d3c414ad46f34699f2b
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; /** * * @author M1ME * */ public class C { public static void main(String[] args) { FastScanner fs = new FastScanner(); int t = fs.nextInt(); for (int tt = 0; tt < t; tt++) { int n = fs.nextInt(); boolean ok = true; for (int i = 0; i < n; i++) { int m = fs.nextInt(); if (i < 200) { boolean ok2 = false; for (int j = 2; j <= i + 2; j++) { if (gcd(j, m) != j) { ok2 = true; break; } } if (ok2 == false) ok = false; } } if (ok) System.out.println("YES"); else System.out.println("NO"); } } public static long gcd(long a, long b) { if (b > a) { return gcd(b, a); } if (b == 0) { return a; } if (a % b == 0) { return b; } else { return gcd(b, a % b); } } static void sort(int[] a) { ArrayList<Integer> al = new ArrayList<>(); for (int i : a) al.add(i); Collections.sort(al); for (int i = 0; i < a.length; i++) a[i] = al.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
db747eac72668736e0e9fe9d1dbfe183
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class cf1603a { public static void main(String[] args) throws IOException { int t = ri(); next: while (t --> 0) { int n = ri(), a[] = ria(n), moves[] = new int[n], cnt = 0; for (int i = 0; i < n; ++i) { moves[i] = n; for (int j = i + 2; j > 1; --j) { if (a[i] % j != 0) { moves[i] = (i + 2) - j; break; } } if (moves[i] <= cnt) { ++cnt; } else { break; } } prYN(cnt == n); } close(); } static BufferedReader __i = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter __o = new PrintWriter(new OutputStreamWriter(System.out)); static StringTokenizer input; static Random __r = new Random(); // references // IBIG = 1e9 + 7 // IMAX ~= 2e9 // LMAX ~= 9e18 // constants static final int IBIG = 1000000007; static final int IMAX = 2147483647; static final long LMAX = 9223372036854775807L; // math util static int minof(int a, int b, int c) {return min(a, min(b, c));} static int minof(int... x) {if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min;} static long minof(long a, long b, long c) {return min(a, min(b, c));} static long minof(long... x) {if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min;} static int maxof(int a, int b, int c) {return max(a, max(b, c));} static int maxof(int... x) {if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max;} static long maxof(long a, long b, long c) {return max(a, max(b, c));} static long maxof(long... x) {if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max;} static int powi(int a, int b) {if (a == 0) return 0; int ans = 1; while (b > 0) {if ((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static long powl(long a, int b) {if (a == 0) return 0; long ans = 1; while (b > 0) {if ((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;} static int fli(double d) {return (int) d;} static int cei(double d) {return (int) ceil(d);} static long fll(double d) {return (long) d;} static long cel(double d) {return (long) ceil(d);} static int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);} static long gcd(long a, long b) {return b == 0 ? a : gcd(b, a % b);} static int[] exgcd(int a, int b) {if (b == 0) return new int[] {1, 0}; int[] y = exgcd(b, a % b); return new int[] {y[1], y[0] - y[1] * (a / b)};} static long[] exgcd(long a, long b) {if (b == 0) return new long[] {1, 0}; long[] y = exgcd(b, a % b); return new long[] {y[1], y[0] - y[1] * (a / b)};} static int randInt(int min, int max) {return __r.nextInt(max - min + 1) + min;} static long mix(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);} // array util static void reverse(int[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(long[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(double[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void reverse(char[] a) {for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}} static void shuffle(int[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(long[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void shuffle(double[] a) {int n = a.length - 1; for (int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}} static void rsort(int[] a) {shuffle(a); sort(a);} static void rsort(long[] a) {shuffle(a); sort(a);} static void rsort(double[] a) {shuffle(a); sort(a);} static int[] copy(int[] a) {int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} static long[] copy(long[] a) {long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} static double[] copy(double[] a) {double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} static char[] copy(char[] a) {char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;} // input static void r() throws IOException {input = new StringTokenizer(rline());} static int ri() throws IOException {return Integer.parseInt(rline());} static long rl() throws IOException {return Long.parseLong(rline());} static double rd() throws IOException {return Double.parseDouble(rline());} static int[] ria(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni(); return a;} static void ria(int[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = ni();} static int[] riam1(int n) throws IOException {int[] a = new int[n]; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1; return a;} static void riam1(int[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = ni() - 1;} static long[] rla(int n) throws IOException {long[] a = new long[n]; r(); for (int i = 0; i < n; ++i) a[i] = nl(); return a;} static void rla(long[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = nl();} static double[] rda(int n) throws IOException {double[] a = new double[n]; r(); for (int i = 0; i < n; ++i) a[i] = nd(); return a;} static void rda(double[] a) throws IOException {int n = a.length; r(); for (int i = 0; i < n; ++i) a[i] = nd();} static char[] rcha() throws IOException {return rline().toCharArray();} static void rcha(char[] a) throws IOException {int n = a.length, i = 0; for (char c : rline().toCharArray()) a[i++] = c;} static String rline() throws IOException {return __i.readLine();} static String n() {return input.nextToken();} static int rni() throws IOException {r(); return ni();} static int ni() {return Integer.parseInt(n());} static long rnl() throws IOException {r(); return nl();} static long nl() {return Long.parseLong(n());} static double rnd() throws IOException {r(); return nd();} static double nd() {return Double.parseDouble(n());} // output static void pr(int i) {__o.print(i);} static void prln(int i) {__o.println(i);} static void pr(long l) {__o.print(l);} static void prln(long l) {__o.println(l);} static void pr(double d) {__o.print(d);} static void prln(double d) {__o.println(d);} static void pr(char c) {__o.print(c);} static void prln(char c) {__o.println(c);} static void pr(char[] s) {__o.print(new String(s));} static void prln(char[] s) {__o.println(new String(s));} static void pr(String s) {__o.print(s);} static void prln(String s) {__o.println(s);} static void pr(Object o) {__o.print(o);} static void prln(Object o) {__o.println(o);} static void prln() {__o.println();} static void pryes() {prln("yes");} static void pry() {prln("Yes");} static void prY() {prln("YES");} static void prno() {prln("no");} static void prn() {prln("No");} static void prN() {prln("NO");} static boolean pryesno(boolean b) {prln(b ? "yes" : "no"); return b;}; static boolean pryn(boolean b) {prln(b ? "Yes" : "No"); return b;} static boolean prYN(boolean b) {prln(b ? "YES" : "NO"); return b;} static void prln(int... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();} static void prln(long... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();} static void prln(double... a) {for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i); if (a.length > 0) prln(a[a.length - 1]); else prln();} static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i); if (n >= 0) prln(iter.next()); else prln();} static void h() {prln("hlfd"); flush();} static void flush() {__o.flush();} static void close() {__o.close();} }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
898ab0fd2718d494884ebc81d1e5a212
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; import java.text.*; public class CF_1603_A{ //SOLUTION BEGIN void pre() throws Exception{} void solve(int TC) throws Exception{ int N = ni(); long[] A = new long[1+N]; for(int i = 1; i<= N; i++)A[i] = nl(); int del = 0; for(int i = 1; i<= N; i++){ long v = A[i]; boolean good = v%(i+1) != 0; for(int x = 1; x <= del && !good; x++)if(A[i]%(i+1-x) != 0)good = true; if(good)del++; } pn(del == N?"YES":"NO"); } //SOLUTION END void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");} void exit(boolean b){if(!b)System.exit(0);} static void dbg(Object... o){System.err.println(Arrays.deepToString(o));} final long IINF = (long)1e17; final int INF = (int)1e9+2; DecimalFormat df = new DecimalFormat("0.00000000000"); double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8; static boolean multipleTC = true, memory = true, fileIO = false; FastReader in;PrintWriter out; void run() throws Exception{ long ct = System.currentTimeMillis(); if (fileIO) { in = new FastReader(""); out = new PrintWriter(""); } else { in = new FastReader(); out = new PrintWriter(System.out); } //Solution Credits: Taranpreet Singh int T = multipleTC? ni():1; pre(); for (int t = 1; t <= T; t++) solve(t); out.flush(); out.close(); System.err.println(System.currentTimeMillis() - ct); } public static void main(String[] args) throws Exception{ if(memory)new Thread(null, new Runnable() {public void run(){try{new CF_1603_A().run();}catch(Exception e){e.printStackTrace();System.exit(1);}}}, "1", 1 << 28).start(); else new CF_1603_A().run(); } int[][] make(int n, int e, int[] from, int[] to, boolean f){ int[][] g = new int[n][];int[]cnt = new int[n]; for(int i = 0; i< e; i++){ cnt[from[i]]++; if(f)cnt[to[i]]++; } for(int i = 0; i< n; i++)g[i] = new int[cnt[i]]; for(int i = 0; i< e; i++){ g[from[i]][--cnt[from[i]]] = to[i]; if(f)g[to[i]][--cnt[to[i]]] = from[i]; } return g; } int[][][] makeS(int n, int e, int[] from, int[] to, boolean f){ int[][][] g = new int[n][][];int[]cnt = new int[n]; for(int i = 0; i< e; i++){ cnt[from[i]]++; if(f)cnt[to[i]]++; } for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][]; for(int i = 0; i< e; i++){ g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0}; if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1}; } return g; } int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));} int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;} long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));} void p(Object... o){for(Object oo:o)out.print(oo+" ");} void pn(Object... o){for(int i = 0; i< o.length; i++)out.print(o[i]+(i+1 < o.length?" ":"\n"));} void pni(Object... o){for(Object oo:o)out.print(oo+" ");out.println();out.flush();} String n()throws Exception{return in.next();} String nln()throws Exception{return in.nextLine();} int ni()throws Exception{return Integer.parseInt(in.next());} long nl()throws Exception{return Long.parseLong(in.next());} double nd()throws Exception{return Double.parseDouble(in.next());} class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next() throws Exception{ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ throw new Exception(e.toString()); } } return st.nextToken(); } String nextLine() throws Exception{ String str; try{ str = br.readLine(); }catch (IOException e){ throw new Exception(e.toString()); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 11
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
bd71c644c9ec329d5f568836d8854f9e
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; public class Di_visible_Confusion { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int tc = Integer.parseInt(scanner.next()); while(tc-- > 0) { int n = Integer.parseInt(scanner.next()); int[] a = new int[n+1]; int k = 0; for(int i = 1 ; i <= n ; i++) { a[i] = Integer.parseInt(scanner.next()); if(k==1)continue; boolean flag = false; for(int j = 2 ; j <= i+1 ; j++) { if(a[i] % j != 0) {flag = true;break;} } if(!flag)k = 1; } if(k==1)System.out.println("NO"); else System.out.println("YES"); } scanner.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
110508c89ff68325a924b202e71c7efa
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; public class Main { static int N = 100010; static int[] a = new int[N]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while (T-- > 0) { int n = sc.nextInt(); for (int i = 1; i <= n; i++) { a[i] = sc.nextInt(); } boolean flag = true; for (int i = 1; i <= n; i++) { boolean st = false; for (int j = 2; j <= i + 1; j++) { if (a[i] % j != 0) { st = true; break; } } if (!st) { flag = false; break; } } if (!flag) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
b7f786e31401b2563bfbe8928d0e89e7
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class Practice1 { static long[] sort(long[] arr) { int n=arr.length; ArrayList<Long> al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(arr[i]); } Collections.sort(al); for(int i=0;i<n;i++) { arr[i]=al.get(i); } return arr; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long nCr(int n, int r) { // int x=1000000007; long dp[][]=new long[2][r+1]; for(int i=0;i<=n;i++){ for(int j=0;j<=i&&j<=r;j++){ if(i==0||j==0||i==j){ dp[i%2][j]=1; }else { // dp[i%2][j]=(dp[(i-1)%2][j]+dp[(i-1)%2][j-1])%x; dp[i%2][j]=(dp[(i-1)%2][j]+dp[(i-1)%2][j-1]); } } } return dp[n%2][r]; } public static class UnionFind { private final int[] p; public UnionFind(int n) { p = new int[n]; for (int i = 0; i < n; i++) { p[i] = i; } } public int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); } public void union(int x, int y) { x = find(x); y = find(y); if (x != y) { p[x] = y; } } } public static boolean ispalin(String str) { int n=str.length(); for(int i=0;i<n/2;i++) { if(str.charAt(i)!=str.charAt(n-i-1)) { return false; } } return true; } static class Pair{ int val; int pos; Pair(int val,int pos){ this.val=val; this.pos=pos; } } static long power(long N,long R) { long x=1000000007; if(R==0) return 1; if(R==1) return N; long temp= power(N,R/2)%x; // (a*b)%p = (a%p*b%p)*p temp=(temp*temp)%x; if(R%2==0){ return temp%x; }else{ return (N*temp)%x; } } public static String binary(int n) { StringBuffer ans=new StringBuffer(); int a=4; while(a-->0) { int temp=(n&1); if(temp!=0) { ans.append('1'); }else { ans.append('0'); } n =n>>1; } ans=ans.reverse(); return ans.toString(); } public static int find(String[][] arr,boolean[][] vis,int dir,int i,int j) { if(i<0||i>=arr.length||j<0||j>=arr[0].length) return 0; if(vis[i][j]==true) return 0; if(dir==1&&arr[i][j].charAt(0)=='1') return 0; if(dir==2&&arr[i][j].charAt(1)=='1') return 0; if(dir==3&&arr[i][j].charAt(2)=='1') return 0; if(dir==4&&arr[i][j].charAt(3)=='1') return 0; vis[i][j]=true; int a=find(arr,vis,1,i+1,j); int b=find(arr,vis,2,i-1,j); int c=find(arr,vis,3,i,j+1); int d=find(arr,vis,4,i,j-1); return 1+a+b+c+d; } static ArrayList<Integer> allDivisors(int n) { ArrayList<Integer> al=new ArrayList<>(); int i=2; while(i*i<=n) { if(n%i==0) al.add(i); if(n%i==0&&i*i!=n) al.add(n/i); i++; } return al; } static int[] sort(int[] arr) { int n=arr.length; ArrayList<Integer> al=new ArrayList<>(); for(int i=0;i<n;i++) { al.add(arr[i]); } Collections.sort(al); for(int i=0;i<n;i++) { arr[i]=al.get(i); } return arr; } public static void main (String[] args) { PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); // out.print(); //out.println(); FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } boolean bol=true; for(int i=1;i<=n;i++) { boolean flag=false; for(int j=i+1;j>1;j--) { if(arr[i-1]%j!=0) { flag=true; break; } } if(flag==false) bol=false; } if(bol==true) { out.println("YES"); }else { out.println("NO"); } } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
8163f69e09b4845f88a746681a036560
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class DivisibleConfusion { public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out)); int t = fr.nextInt(); while (t-- > 0) { int n = fr.nextInt(); boolean possible = true; for (int i = 1; i <= n; i++) { // brute int a = fr.nextInt(); // lcm (2..21) <= 10^9, thus everything above i=22 will have a value that // divides into it boolean found = false; for (int j = Math.min(24, i+1); j >= 2; j--) { if (a % j != 0) { found = true; break; } } possible &= found; } if (possible) { pr.println("YES"); } else { pr.println("NO"); } } pr.close(); } static class Pair { int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static int toInt(String s) { return Integer.parseInt(s); } // MERGE SORT IMPLEMENTATION void sort(int[] arr, int l, int r) { if (l < r) { int m = l + (r - l) / 2; sort(arr, l, m); sort(arr, m + 1, r); // call merge merge(arr, l, m, r); } } void merge(int[] arr, int l, int m, int r) { // find sizes int len1 = m - l + 1; int len2 = r - m; int[] L = new int[len1]; int[] R = new int[len2]; // push to copies for (int i = 0; i < L.length; i++) L[i] = arr[l + i]; for (int i = 0; i < R.length; i++) { R[i] = arr[m + 1 + i]; } // fill in new array int i = 0, j = 0; int k = l; while (i < len1 && j < len2) { if (L[i] < R[i]) { arr[k] = L[i]; i++; } else { arr[k] = R[i]; j++; } k++; } // add remaining elements while (i < len1) { arr[k] = L[i]; i++; k++; } while (j < len2) { arr[k] = R[j]; j++; k++; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
da00d46ddb2b57c416619250a7b10685
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class DivisibleConfusion { public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out)); int t = fr.nextInt(); while (t-- > 0) { int n = fr.nextInt(); boolean possible = true; for (int i = 1; i <= n; i++) { // brute int a = fr.nextInt(); // lcm (2..21) <= 10^9, thus everything above i=22 will have a value that // divides into it boolean found = false; for (int j = i + 1; j >= 2; j--) { if (a % j != 0) { found = true; break; } } possible &= found; } if (possible) { pr.println("YES"); } else { pr.println("NO"); } } pr.close(); } static class Pair { int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static int toInt(String s) { return Integer.parseInt(s); } // MERGE SORT IMPLEMENTATION void sort(int[] arr, int l, int r) { if (l < r) { int m = l + (r - l) / 2; sort(arr, l, m); sort(arr, m + 1, r); // call merge merge(arr, l, m, r); } } void merge(int[] arr, int l, int m, int r) { // find sizes int len1 = m - l + 1; int len2 = r - m; int[] L = new int[len1]; int[] R = new int[len2]; // push to copies for (int i = 0; i < L.length; i++) L[i] = arr[l + i]; for (int i = 0; i < R.length; i++) { R[i] = arr[m + 1 + i]; } // fill in new array int i = 0, j = 0; int k = l; while (i < len1 && j < len2) { if (L[i] < R[i]) { arr[k] = L[i]; i++; } else { arr[k] = R[i]; j++; } k++; } // add remaining elements while (i < len1) { arr[k] = L[i]; i++; k++; } while (j < len2) { arr[k] = R[j]; j++; k++; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
cc092b0d62632a0102b874a153d88396
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.lang.reflect.Array; import java.util.*; import java.io.*; //import static com.sun.tools.javac.jvm.ByteCodes.swap; public class fastTemp { static FastScanner ps = null; public static void main(String[] args) { ps = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = ps.nextInt(); while(t-->0) { int n = ps.nextInt(); int arr[] = new int[n]; boolean f = false; String ans = "YES"; for(int i=0;i<n;i++){ arr[i] = ps.nextInt(); } for(int i=0;i<n;i++){ int a = -1; for(int pos = i+2;pos>=2;pos--){ if(arr[i]%pos!=0){ a = pos; break; } } if(a == -1){ ans = "NO"; break; } } System.out.println(ans); } out.close(); } public static long[] sort(long arr[]) { List<Long> list = new ArrayList<>(); for(long i:arr) list.add(i); Collections.sort(list); for(int i = 0;i<list.size();i++) { arr[i] = list.get(i); } return arr; } static long power(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more than or // equal to p x = x % p; while (y > 0) { // If y is odd, multiply x // with result if (y % 2 == 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p static long modInverse(long n, long p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's // little theorem. static long nCrModPFermat(long n, long r, long p) { if (n<r) return 0; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r long[] fac = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[(int)n] * modInverse(fac[(int)r], p) % p * modInverse(fac[(int)n - (int)r], p) % p) % p; } //public static int dijkstra(int src , int dist[] ){ // //PriorityQueue<Pair> q = new PriorityQueue<>(); //q.add(new Pair(1,0)); // //while(q.size()>0){ // // Pair rem = q.remove(); // for(Pair x:graph[rem.y]){ // if(dist[x.y]>dist[rem.y]+x.wt){ // dist[x.y] = dist[rem.y] + x.wt; // q.add(new Pair(x.y,dist[x.y])); // } // } // //} // //return dist[dist.length-1]; // //} // T --> O(n) && S--> O(d) public static long lower(long arr[], long key) { int l = 0, r = arr.length-1; long ans = -1; while(l<=r) { int mid = l +(r-l)/2; if(arr[mid]<=key) { ans = arr[mid]; l = mid+1; } else { r = mid-1; } } return ans; } public static long upper(long arr[], long key) { int l = 0, r = arr.length-1; long ans = -1; while(l<=r) { int mid = l +(r-l)/2; if(arr[mid] >= key) { ans = arr[mid]; r = mid-1; } else { l = mid+1; } } return ans; } public static class String1 implements Comparable<String1>{ String str; int id; String1(String str , int id){ this.str = str; this.id = id; } public int compareTo(String1 o){ int i=0; while(i<str.length() && str.charAt(i)==o.str.charAt(i)){ i++; } if(i<str.length()){ if(i%2==1){ return o.str.compareTo(str); // descending order }else{ return str.compareTo(o.str); // ascending order } } return str.compareTo(o.str); } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } // ------------------------------------------swap---------------------------------------------------------------------- static void swap(int arr[],int i,int j) { int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } //-------------------------------------------seiveOfEratosthenes---------------------------------------------------- static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers // for (int i = 2; i <= n; i++) // { // if (prime[i] == true) // System.out.print(i + " "); // } } //------------------------------------------- power------------------------------------------------------------------ public static long power(int a , int b) { if (b == 0) { return 1; } else if (b == 1) { return a; } else { long R = power(a, b / 2); if (b % 2 != 0) { return (((power(a, b / 2))) * a * ((power(a, b / 2)))); } else { return ((power(a, b / 2))) * ((power(a, b / 2))); } } } public static int log2(int x) { return (int) (Math.log(x) / Math.log(2)); } //---------------------------------------EXTENDED EUCLID ALGO-------------------------------------------------------- // public static class Pair{ // int x; // int y; // public Pair(int x,int y){ // this.x = x; // this.y = y ; // } // } // public static Pair Euclid(int a,int b){ // // if(b==0){ // return new Pair(1,0); // answer of x and y // } // // Pair dash = Euclid(b,a%b); // // return new Pair(dash.y , dash.x - (a/b)*dash.y); // // // } //--------------------------------GCD------------------GCD-----------GCD-------------------------------------------- public static long gcd(long a,long b){ if(b==0){ return a; } return gcd(b,a%b); } public static void BFS(ArrayList<Integer>[] graph) { } // This is an extension of method 2. Instead of moving one by one, divide the array in different sets //where number of sets is equal to GCD of n and d and move the elements within sets. //If GCD is 1 as is for the above example array (n = 7 and d =2), then elements will be moved within one set only, we just start with temp = arr[0] and keep moving arr[I+d] to arr[I] and finally store temp at the right place. //Here is an example for n =12 and d = 3. GCD is 3 and // void leftRotate(int arr[], int d, int n) // { // /* To handle if d >= n */ // d = d % n; // int i, j, k, temp; // int g_c_d = gcd(d, n); // for (i = 0; i < g_c_d; i++) { // /* move i-th values of blocks */ // temp = arr[i]; // j = i; // while (true) { // k = j + d; // if (k >= n) // k = k - n; // if (k == i) // break; // arr[j] = arr[k]; // j = k; // } // arr[j] = temp; // } // } } // Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n);
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
82c946462d82b9789d53d2f2f60fbf4d
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); while (t-- > 0) { int n = Integer.parseInt(reader.readLine()); LinkedList<Integer> list = new LinkedList<>(); String[] line = reader.readLine().split(" "); for (int i = 0; i < n; ++i) { list.add(Integer.parseInt(line[i])); } boolean ans = true; while (list.size() > 0) { if (list.getLast() % (list.size() + 1) != 0) { list.removeLast(); continue; } Stack<Integer> stack = new Stack<>(); while (list.size() > 0 && list.getLast() % (list.size() + 1) == 0) { int x = list.removeLast(); stack.add(x); } if (list.size() == 0) { ans = false; } else { list.removeLast(); while (stack.size() > 0) { list.add(stack.pop()); } } } if (ans) System.out.println("YES"); else System.out.println("NO"); } reader.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
f25750f4a3a6ad7dec269c37e9e4ed20
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; public class A { static void merge(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } static void sort(int arr[], int l, int r) { if (l < r) { int m = (l+r)/2; sort(arr, l, m); sort(arr , m+1, r); merge(arr, l, m, r); } } static void revOrder(int[] arr) { int[] a = new int[arr.length]; for(int i=0;i<arr.length;i++) { a[i] = arr[arr.length-i-1]; } for(int i=0;i<arr.length;i++) arr[i] = a[i]; } static int next(long target, long[] arr) { int start = 0, end = arr.length - 1; int ans = -1; while (start < end) { int mid = start + (end-start) / 2; if (arr[mid] <=target) { start = mid + 1; ans = mid; } else { end = mid - 1; } } return ans; } static void pf(int n, ArrayList<Integer> al) { for (int i=1; i<=Math.sqrt(n); i++) { if (n%i==0) { if (n/i == i) { al.add(i); } else{ al.add(i); al.add(n/i); } } } } static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if((y & 1)==1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static int gcd(int a, int b) { if (a == 0) return b; if (b == 0) return a; int k; for (k = 0; ((a | b) & 1) == 0; ++k) { a >>= 1; b >>= 1; } while ((a & 1) == 0) a >>= 1; do { while ((b & 1) == 0) b >>= 1; if (a > b) { int temp = a; a = b; b = temp; } b = (b - a); } while (b != 0); return a << k; } static long inv(long a, long m){ return power(a, m-2, m); } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static DecimalFormat df = new DecimalFormat("0.0000000000"); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { BufferInput in = new BufferInput(); try { int t = in.nextInt(); while(t-->0) { int n = in.nextInt(); int arr[] = new int[n + 1]; boolean ans = true; for (int i = 1; i <= n; ++i) { arr[i] = in.nextInt(); boolean flag = true; for (int p = i; p >= 1 && flag; --p) if (arr[i]%(p + 1) != 0) flag = false; if (flag) ans = false; } if (ans) out.println("YES"); else out.println("NO"); } out.close(); }catch(Exception e) {} } static class Pair implements Comparable<Pair> { int x;int y; Pair(int i,int o) { x=i;y=o; } public int compareTo(Pair n) { if(this.x!=n.x) return this.x-n.x; return this.y-n.y; } } static class BufferInput { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public BufferInput() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public BufferInput(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public String nextString() throws IOException{ byte c = read(); while(Character.isWhitespace(c)){ c = read(); } StringBuilder builder = new StringBuilder(); builder.append((char)c); c = read(); while(!Character.isWhitespace(c)){ builder.append((char)c); c = read(); } return builder.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public int[] nextIntArray(int n) throws IOException { int arr[] = new int[n]; for(int i = 0; i < n; i++){ arr[i] = nextInt(); } return arr; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long[] nextLongArray(int n) throws IOException { long arr[] = new long[n]; for(int i = 0; i < n; i++){ arr[i] = nextLong(); } return arr; } public char nextChar() throws IOException{ byte c = read(); while(Character.isWhitespace(c)){ c = read(); } return (char) c; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } public double[] nextDoubleArray(int n) throws IOException { double arr[] = new double[n]; for(int i = 0; i < n; i++){ arr[i] = nextDouble(); } return arr; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
de0eea377f8b73b62216fb22d15c2eb6
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; public class solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } boolean flag=true; for(int i=0;i<n;i++) { if(arr[i]%(i+2)==0) { boolean check=solve(arr[i],i+2); if(!check) { System.out.println("NO");flag=false; break; } } } if(flag) System.out.println("YES"); } } public static boolean solve(int val,int ind) { for(int i=2;i<ind;i++ ) { if(val%i!=0 ) return true; } return false; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
6a0b11937e0e73b10e3e93edcc5a208b
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class Sort { static BufferedReader bf; static PrintWriter out; static Scanner sc; static StringTokenizer st; static long mod = (long)(1e9+7); static long mod2 = 998244353; static long fact[] = new long[1001]; static long inverse[] = new long[1001]; public static void main (String[] args)throws IOException { bf = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); sc = new Scanner(System.in); // fact[0] = 1; // inverse[0] = 1; // for(int i = 1;i<fact.length;i++){ // fact[i] = (fact[i-1] * i)%mod; // inverse[i] = binaryExpo(fact[i], mod-2); // } int t = nextInt(); while(t-->0){ solve(); } out.flush(); } public static void solve() throws IOException{ int n = nextInt(); int[]arr = new int[n]; for(int i = 0;i<n;i++){ arr[i] = nextInt(); } long num = 1; for(int i =0 ;i<n;i++){ num = lcm(num , i + 2); if(arr[i]%num == 0){ out.println("NO"); return; } } out.println("YES"); } public static void req(int l,int r){ out.println("? " + l + " " + r); out.flush(); } public static int[] bringSame(int u,int v ,int parent[][],int[]depth){ if(depth[u] < depth[v]){ int temp = u; u = v; v = temp; } int k = depth[u] - depth[v]; for(int i = 0;i<=18;i++){ if((k & (1<<i)) != 0){ u = parent[u][i]; } } return new int[]{u,v}; } public static void findDepth(List<List<Integer>>list,int cur,int parent,int[]depth,int[][]p){ List<Integer>temp = list.get(cur); p[cur][0] = parent; for(int i = 0;i<temp.size();i++){ int next = temp.get(i); if(next != parent){ depth[next] = depth[cur]+1; findDepth(list,next,cur,depth,p); } } } public static int lca(int u, int v,int[][]parent){ if(u == v)return u; for(int i = 18;i>=0;i--){ if(parent[u][i] != parent[v][i]){ u = parent[u][i]; v = parent[v][i]; } } return parent[u][0]; } public static void plus(int node,int low,int high,int tlow,int thigh,int[]tree){ if(low >= tlow && high <= thigh){ tree[node]++; return; } if(high < tlow || low > thigh)return; int mid = (low + high)/2; plus(node*2,low,mid,tlow,thigh,tree); plus(node*2 + 1 , mid + 1, high,tlow, thigh,tree); } public static boolean allEqual(int[]arr,int x){ for(int i = 0;i<arr.length;i++){ if(arr[i] != x)return false; } return true; } public static long helper(StringBuilder sb){ return Long.parseLong(sb.toString()); } public static int min(int node,int low,int high,int tlow,int thigh,int[][]tree){ if(low >= tlow&& high <= thigh)return tree[node][0]; if(high < tlow || low > thigh)return Integer.MAX_VALUE; int mid = (low + high)/2; // println(low+" "+high+" "+tlow+" "+thigh); return Math.min(min(node*2,low,mid,tlow,thigh,tree) ,min(node*2+1,mid+1,high,tlow,thigh,tree)); } public static int max(int node,int low,int high,int tlow,int thigh,int[][]tree){ if(low >= tlow && high <= thigh)return tree[node][1]; if(high < tlow || low > thigh)return Integer.MIN_VALUE; int mid = (low + high)/2; return Math.max(max(node*2,low,mid,tlow,thigh,tree) ,max(node*2+1,mid+1,high,tlow,thigh,tree)); } public static long[] help(List<List<Integer>>list,int[][]range,int cur){ List<Integer>temp = list.get(cur); if(temp.size() == 0)return new long[]{range[cur][1],1}; long sum = 0; long count = 0; for(int i = 0;i<temp.size();i++){ long []arr = help(list,range,temp.get(i)); sum += arr[0]; count += arr[1]; } if(sum < range[cur][0]){ count++; sum = range[cur][1]; } return new long[]{sum,count}; } public static long findSum(int node,int low, int high,int tlow,int thigh,long[]tree,long mod){ if(low >= tlow && high <= thigh)return tree[node]%mod; if(low > thigh || high < tlow)return 0; int mid = (low + high)/2; return((findSum(node*2,low,mid,tlow,thigh,tree,mod) % mod) + (findSum(node*2+1,mid+1,high,tlow,thigh,tree,mod)))%mod; } public static boolean allzero(long[]arr){ for(int i =0 ;i<arr.length;i++){ if(arr[i]!=0)return false; } return true; } public static long count(long[][]dp,int i,int[]arr,int drank,long sum){ if(i == arr.length)return 0; if(dp[i][drank]!=-1 && arr[i]+sum >=0)return dp[i][drank]; if(sum + arr[i] >= 0){ long count1 = 1 + count(dp,i+1,arr,drank+1,sum+arr[i]); long count2 = count(dp,i+1,arr,drank,sum); return dp[i][drank] = Math.max(count1,count2); } return dp[i][drank] = count(dp,i+1,arr,drank,sum); } public static void help(int[]arr,char[]signs,int l,int r){ if( l < r){ int mid = (l+r)/2; help(arr,signs,l,mid); help(arr,signs,mid+1,r); merge(arr,signs,l,mid,r); } } public static void merge(int[]arr,char[]signs,int l,int mid,int r){ int n1 = mid - l + 1; int n2 = r - mid; int[]a = new int[n1]; int []b = new int[n2]; char[]asigns = new char[n1]; char[]bsigns = new char[n2]; for(int i = 0;i<n1;i++){ a[i] = arr[i+l]; asigns[i] = signs[i+l]; } for(int i = 0;i<n2;i++){ b[i] = arr[i+mid+1]; bsigns[i] = signs[i+mid+1]; } int i = 0; int j = 0; int k = l; boolean opp = false; while(i<n1 && j<n2){ if(a[i] <= b[j]){ arr[k] = a[i]; if(opp){ if(asigns[i] == 'R'){ signs[k] = 'L'; } else{ signs[k] = 'R'; } } else{ signs[k] = asigns[i]; } i++; k++; } else{ arr[k] = b[j]; int times = n1 - i; if(times%2 == 1){ if(bsigns[j] == 'R'){ signs[k] = 'L'; } else{ signs[k] = 'R'; } } else{ signs[k] = bsigns[j]; } j++; opp = !opp; k++; } } while(i<n1){ arr[k] = a[i]; if(opp){ if(asigns[i] == 'R'){ signs[k] = 'L'; } else{ signs[k] = 'R'; } } else{ signs[k] = asigns[i]; } i++; k++; } while(j<n2){ arr[k] = b[j]; signs[k] = bsigns[j]; j++; k++; } } public static long nck(int n,int k){ return ((fact[n] * (inverse[n-k])%mod) * inverse[k])%mod; } public static long binaryExpo(long base,long expo){ if(expo == 0)return 1; long val; if(expo%2 == 1){ val = (binaryExpo(base, expo/2)); val = (val * val)%mod; val = (val * base)%mod; } else{ val = binaryExpo(base, expo/2); val = (val*val)%mod; } return (val%mod); } public static boolean isSorted(int[]arr){ for(int i =1;i<arr.length;i++){ if(arr[i] < arr[i-1]){ return false; } } return true; } //function to find the topological sort of the a DAG public static boolean hasCycle(int[]indegree,List<List<Integer>>list,int n,List<Integer>topo){ Queue<Integer>q = new LinkedList<>(); for(int i =1;i<indegree.length;i++){ if(indegree[i] == 0){ q.add(i); topo.add(i); } } while(!q.isEmpty()){ int cur = q.poll(); List<Integer>l = list.get(cur); for(int i = 0;i<l.size();i++){ indegree[l.get(i)]--; if(indegree[l.get(i)] == 0){ q.add(l.get(i)); topo.add(l.get(i)); } } } if(topo.size() == n)return false; return true; } // function to find the parent of any given node with path compression in DSU public static int find(int val,int[]parent){ if(val == parent[val])return val; return parent[val] = find(parent[val],parent); } // function to connect two components public static void union(int[]rank,int[]parent,int u,int v){ int a = find(u,parent); int b= find(v,parent); if(a == b)return; if(rank[a] == rank[b]){ parent[b] = a; rank[a]++; } else{ if(rank[a] > rank[b]){ parent[b] = a; } else{ parent[a] = b; } } } // public static int findN(int n){ int num = 1; while(num < n){ num *=2; } return num; } // code for input public static void print(String s ){ System.out.print(s); } public static void print(int num ){ System.out.print(num); } public static void print(long num ){ System.out.print(num); } public static void println(String s){ System.out.println(s); } public static void println(int num){ System.out.println(num); } public static void println(long num){ System.out.println(num); } public static void println(){ System.out.println(); } public static int Int(String s){ return Integer.parseInt(s); } public static long Long(String s){ return Long.parseLong(s); } public static String[] nextStringArray()throws IOException{ return bf.readLine().split(" "); } public static String nextString()throws IOException{ return bf.readLine(); } public static long[] nextLongArray(int n)throws IOException{ String[]str = bf.readLine().split(" "); long[]arr = new long[n]; for(int i =0;i<n;i++){ arr[i] = Long.parseLong(str[i]); } return arr; } public static int[][] newIntMatrix(int r,int c)throws IOException{ int[][]arr = new int[r][c]; for(int i =0;i<r;i++){ String[]str = bf.readLine().split(" "); for(int j =0;j<c;j++){ arr[i][j] = Integer.parseInt(str[j]); } } return arr; } public static long[][] newLongMatrix(int r,int c)throws IOException{ long[][]arr = new long[r][c]; for(int i =0;i<r;i++){ String[]str = bf.readLine().split(" "); for(int j =0;j<c;j++){ arr[i][j] = Long.parseLong(str[j]); } } return arr; } static class pair{ int one; int two; pair(int one,int two){ this.one = one ; this.two =two; } } public static long gcd(long a,long b){ if(b == 0)return a; return gcd(b,a%b); } public static long lcm(long a,long b){ return (a*b)/(gcd(a,b)); } public static boolean isPalindrome(String s){ int i = 0; int j = s.length()-1; while(i<=j){ if(s.charAt(i) != s.charAt(j)){ return false; } i++; j--; } return true; } // these functions are to calculate the number of smaller elements after self public static void sort(int[]arr,int l,int r){ if(l < r){ int mid = (l+r)/2; sort(arr,l,mid); sort(arr,mid+1,r); smallerNumberAfterSelf(arr, l, mid, r); } } public static void smallerNumberAfterSelf(int[]arr,int l,int mid,int r){ int n1 = mid - l +1; int n2 = r - mid; int []a = new int[n1]; int[]b = new int[n2]; for(int i = 0;i<n1;i++){ a[i] = arr[l+i]; } for(int i =0;i<n2;i++){ b[i] = arr[mid+i+1]; } int i = 0; int j =0; int k = l; while(i<n1 && j < n2){ if(a[i] < b[j]){ arr[k++] = a[i++]; } else{ arr[k++] = b[j++]; } } while(i<n1){ arr[k++] = a[i++]; } while(j<n2){ arr[k++] = b[j++]; } } public static String next(){ while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bf.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static String nextLine(){ String str = ""; try { str = bf.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // use some math tricks it might help // sometimes just try to think in straightforward plan in A and B problems don't always complecate the questions with thinking too much differently // always use long number to do 10^9+7 modulo // if a problem is related to binary string it could also be related to parenthesis // *****try to use binary search(it is a very beautiful thing it can work in some of the very unexpected problems ) in the question it might work****** // try sorting // try to think in opposite direction of question it might work in your way // if a problem is related to maths try to relate some of the continuous subarray with variables like - > a+b+c+d or a,b,c,d in general // if the question is to much related to left and/or right side of any element in an array then try monotonic stack it could work. // in range query sums try to do binary search it could work // analyse the time complexity of program thoroughly // anylyse the test cases properly // if we divide any number by 2 till it gets 1 then there will be (number - 1) operation required // try to do the opposite operation of what is given in the problem //think about the base cases properly //If a question is related to numbers try prime factorisation or something related to number theory // keep in mind unique strings //you can calculate the number of inversion in O(n log n) // in a matrix you could sometimes think about row and cols indenpendentaly. // Try to think in more constructive(means a way to look through various cases of a problem) way. // observe the problem carefully the answer could be hidden in the given test cases itself. (A, B , C); // when we have equations like (a+b = N) and we have to find the max of (a*b) then the values near to the N/2 must be chosen as (a and b); // give emphasis to the number of occurences of elements it might help. // if a number is even then we can find the pair for each and every number in that range whose bitwise AND is zero. // if a you find a problem related to the graph make a graph // There is atleast one prime number between the interval [n , 3n/2]; // If a problem is related to maths then try to form an mathematical equation.
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
acf46477be0f83ff648dff82b57b70e5
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Queue; import java.util.StringTokenizer; public class cf { static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } static int n,m,k,x; static int arr[]; static int con=32768; static HashSet<Integer> div; static int dp[]; public static void main(String[] args) { FastScanner s= new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=s.nextInt(); while(t-->0) { n=s.nextInt(); arr=new int[n+1]; String ans="YES"; for(int i=1;i<=n;i++)arr[i]=s.nextInt(); for(int i=1;i<=n;i++) { int a=arr[i]; boolean f=false; for(int j=2;j<=i+1;j++) { if(a%j!=0) { f=true; break; } } if(!f) { ans="NO"; break; } } System.out.println(ans); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d60d0053df31885b5b1242b6ab1eb6b3
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; import java.util.*; import static java.lang.System.out; import static java.lang.Math.*; public class pre212 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class MultiSet<K> { TreeMap<K, Integer> map; MultiSet() { map = new TreeMap<>(); } void add(K a) { map.put(a, map.getOrDefault(a, 0) + 1); } boolean contains(K a) { return map.containsKey(a); } void remove(K a) { map.put(a, map.get(a) - 1); if (map.get(a) == 0) map.remove(a); } int occrence(K a) { return map.get(a); } K floor(K a) { return map.floorKey(a); } K ceil(K a) { return map.ceilingKey(a); } @Override public String toString() { ArrayList<K> set = new ArrayList<>(); for (Map.Entry<K, Integer> i : map.entrySet()) { for (int j = 1; j <= i.getValue(); j++) set.add(i.getKey()); } return set.toString(); } } static class Pair<K, V> { K value1; V value2; Pair(K a, V b) { value1 = a; value2 = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair<?, ?> p = (Pair<?, ?>) o; return Objects.equals(this.value1, p.value1) && Objects.equals(this.value2, p.value2); } @Override public int hashCode() { int result = this.value1.hashCode(); result = 31 * result + this.value2.hashCode(); return result; } @Override public String toString() { return ("[" + value1 + " <=> " + value2 + "]"); } } static ArrayList<Integer> primes; static void setPrimes(int n) { boolean p[] = new boolean[n]; Arrays.fill(p, true); for (int i = 2; i < p.length; i++) { if (p[i]) { primes.add(i); for (int j = i * 2; j < p.length; j += i) p[j] = false; } } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } public static void main(String args[]) { FastReader obj = new FastReader(); int tc = obj.nextInt(); while(tc--!=0){ int n = obj.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); for(int i=0;i<n;i++) arr.add(obj.nextInt()); int size = arr.size(); boolean ans = true; while(arr.size()>0){ int idx = 0; for(int i=arr.size()-1;i>=0;i--){ if(arr.get(i)%(i+2)!=0){ arr.remove(i); break; } } if(size==arr.size()){ ans = false; break; }else size = arr.size(); } ans &= arr.size()==0; out.println(ans?"YES":"NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
748e57118fdbe5f50e1318de8304e422
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; public class Di_visible_Confusion { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int tc = Integer.parseInt(scanner.next()); while(tc-- > 0) { int n = Integer.parseInt(scanner.next()); int[] a = new int[n+1]; int k = 0; for(int i = 1 ; i <= n ; i++) { a[i] = Integer.parseInt(scanner.next()); if(k==1)continue; boolean flag = false; for(int j = 2 ; j <= i+1 ; j++) { if(a[i] % j != 0) {flag = true;break;} } if(!flag)k = 1; } if(k==1)System.out.println("NO"); else System.out.println("YES"); } scanner.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
70dab6a4e494d6d710a83b33be12f5ab
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class _1603A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); int ok=0; for(int i=0;i<n;i++){ ok=0; for(int j=2;j<=i+2;j++) { if (arr[i] % j != 0) { ok = 1; break; } } if(ok==1) continue; break; } System.out.println(ok==1?"YES":"NO"); } } static class FastIO { InputStream dis; byte[] buffer = new byte[1 << 17]; int pointer = 0; public FastIO(String fileName) throws Exception { dis = new FileInputStream(fileName); } public FastIO(InputStream is) throws Exception { dis = is; } int nextInt() throws Exception { int ret = 0; byte b; do { b = nextByte(); } while (b <= ' '); boolean negative = false; if (b == '-') { negative = true; b = nextByte(); } while (b >= '0' && b <= '9') { ret = 10 * ret + b - '0'; b = nextByte(); } return (negative) ? -ret : ret; } long nextLong() throws Exception { long ret = 0; byte b; do { b = nextByte(); } while (b <= ' '); boolean negative = false; if (b == '-') { negative = true; b = nextByte(); } while (b >= '0' && b <= '9') { ret = 10 * ret + b - '0'; b = nextByte(); } return (negative) ? -ret : ret; } byte nextByte() throws Exception { if (pointer == buffer.length) { dis.read(buffer, 0, buffer.length); pointer = 0; } return buffer[pointer++]; } String next() throws Exception { StringBuffer ret = new StringBuffer(); byte b; do { b = nextByte(); } while (b <= ' '); while (b > ' ') { ret.appendCodePoint(b); b = nextByte(); } return ret.toString(); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
c60cd9759e8a1c04b5b85a89fe195809
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
// package faltu; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Map.Entry; public class Main { static long LowerBound(long[] a2, long x) { // x is the target value or key int l=-1,r=a2.length; while(l+1<r) { int m=(l+r)>>>1; if(a2[m]>=x) r=m; else l=m; } return r; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } public static long getClosest(long val1, long val2,long target) { if (target - val1 >= val2 - target) return val2; else return val1; } static void ruffleSort(long[] a) { int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { long oi=r.nextInt(n), temp=a[i]; a[i]=a[(int)oi]; a[(int)oi]=temp; } Arrays.sort(a); } static void ruffleSort(int[] a){ int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } int ceilIndex(int input[], int T[], int end, int s){ int start = 0; int middle; int len = end; while(start <= end){ middle = (start + end)/2; if(middle < len && input[T[middle]] < s && s <= input[T[middle+1]]){ return middle+1; }else if(input[T[middle]] < s){ start = middle+1; }else{ end = middle-1; } } return -1; } public static int findIndex(long arr[], long t) { if (arr == null) { return -1; } int len = arr.length; int i = 0; while (i < len) { if (arr[i] == t) { return i; } else { i = i + 1; } } return -1; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a,long b) { return (a / gcd(a, b)) * b; } public static int[] swap(int a[], int left, int right) { int temp = a[left]; a[left] = a[right]; a[right] = temp; return a; } public static void swap(long x,long max1) { long temp=x; x=max1; max1=temp; } public static int[] reverse(int a[], int left, int right) { // Reverse the sub-array while (left < right) { int temp = a[left]; a[left++] = a[right]; a[right--] = temp; } return a; } static int lowerLimitBinarySearch(ArrayList<Integer> A,int B) { int n =A.size(); int first = 0,second = n; while(first <second) { int mid = first + (second-first)/2; if(A.get(mid) > B) { second = mid; }else { first = mid+1; } } if(first < n && A.get(first) < B) { first++; } return first; //1 index } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // *******----segement tree implement---***** // -------------START-------------------------- void buildTree (int[] arr,int[] tree,int start,int end,int treeNode) { if(start==end) { tree[treeNode]=arr[start]; return; } buildTree(arr,tree,start,end,2*treeNode); buildTree(arr,tree,start,end,2*treeNode+1); tree[treeNode]=tree[treeNode*2]+tree[2*treeNode+1]; } void updateTree(int[] arr,int[] tree,int start,int end,int treeNode,int idx,int value) { if(start==end) { arr[idx]=value; tree[treeNode]=value; return; } int mid=(start+end)/2; if(idx>mid) { updateTree(arr,tree,mid+1,end,2*treeNode+1,idx,value); } else { updateTree(arr,tree,start,mid,2*treeNode,idx,value); } tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1]; } // disjoint set implementation --start static void makeSet(int n) { parent=new int[n]; rank=new int[n]; for(int i=0;i<n;i++) { parent[i]=i; rank[i]=0; } } static void union(int u,int v) { u=findpar(u); v=findpar(v); if(rank[u]<rank[v])parent[u]=v; else if(rank[v]<rank[u])parent[v]=u; else { parent[v]=u; rank[u]++; } } private static int findpar(int node) { if(node==parent[node])return node; return parent[node]=findpar(parent[node]); } static int parent[]; static int rank[]; // *************end static void presumbit(int[][]prebitsum) { for(int i=1;i<=200000;i++) { int z=i; int j=0; while(z>0) { if((z&1)==1) { prebitsum[i][j]+=(prebitsum[i-1][j]+1); }else { prebitsum[i][j]=prebitsum[i-1][j]; } z=z>>1; j++; } } } static boolean coprime(int a, long l){ return (gcd(a, l) == 1); } static Long MOD=(long) (1e9+7); static int prebitsum[][]; static ArrayList<Integer>arr; static boolean[] vis; static ArrayList<ArrayList<Integer>>adj; public static void main(String[] args) throws IOException { // sieve(); // prebitsum=new int[200001][18]; // presumbit(prebitsum); ArrayList<Long>lcma=new ArrayList<Long>(); lcma.add((long) 1); for(long i=1;i<=1e5+5;i++) { lcma.add(lcm(lcma.get(lcma.size()-1),i)); } FastReader s = new FastReader(); long tt = s.nextLong(); while(tt-->0) { int n=s.nextInt(); ArrayList<Long>a=new ArrayList<Long>(); for(int i=0;i<n;i++)a.add(s.nextLong()); boolean f=true; for(int i=0;i<n;i++) { if(a.get(i)%lcma.get(i+2)==0)f=false; } if(!f)System.out.println("NO"); else System.out.println("YES"); } } static void DFSUtil(int v, boolean[] visited) { visited[v] = true; Iterator<Integer> it = adj.get(v).iterator(); while (it.hasNext()) { int n = it.next(); if (!visited[n]) DFSUtil(n, visited); } } static long DFS(int n) { boolean[] visited = new boolean[n+1]; long cnt=0; for (int i = 1; i <= n; i++) { if (!visited[i]) { DFSUtil(i, visited); cnt++; } } return cnt; } public static String revStr(String str){ String input = str; StringBuilder input1 = new StringBuilder(); input1.append(input); input1.reverse(); return input1.toString(); } public static String sortString(String inputString){ char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static long myPow(long n, long i){ if(i==0) return 1; if(i%2==0) return (myPow(n,i/2)%MOD * myPow(n,i/2)%MOD)%MOD; return (n%MOD* myPow(n,i-i)%MOD)%MOD; } static void palindromeSubStrs(String str) { HashSet<String>set=new HashSet<>(); char[]a =str.toCharArray(); int n=str.length(); int[][]dp=new int[n][n]; for(int g=0;g<n;g++){ for(int i=0,j=g;j<n;j++,i++){ if(!set.contains(str.substring(i,i+1))&&g==0) { dp[i][j]=1; set.add(str.substring(i,i+1)); } else { if(!set.contains(str.substring(i,j+1))&&isPalindrome(str,i,j)) { dp[i][j]=1; set.add(str.substring(i,j+1)); } } } } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { System.out.print(dp[i][j]+" "); if(dp[i][j]==1)ans++; } System.out.println(); } System.out.println(ans); } static boolean isPalindrome(String str,int i,int j) { while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static boolean sign(long num) { return num>0; } static boolean isSquare(long x){ if(x==1)return true; long y=(long) Math.sqrt(x); return y*y==x; } static long power1(long a,long b) { if(b == 0){ return 1; } long ans = power(a,b/2); ans *= ans; if(b % 2!=0){ ans *= a; } return ans; } static void swap(StringBuilder sb,int l,int r) { char temp = sb.charAt(l); sb.setCharAt(l,sb.charAt(r)); sb.setCharAt(r,temp); } // function to reverse the string between index l and r static void reverse(StringBuilder sb,int l,int r) { while(l < r) { swap(sb,l,r); l++; r--; } } // function to search a character lying between index l and r // which is closest greater (just greater) than val // and return it's index static int binarySearch(StringBuilder sb,int l,int r,char val) { int index = -1; while (l <= r) { int mid = (l+r)/2; if (sb.charAt(mid) <= val) { r = mid - 1; } else { l = mid + 1; if (index == -1 || sb.charAt(index) >= sb.charAt(mid)) index = mid; } } return index; } // this function generates next permutation (if there exists any such permutation) from the given string // and returns True // Else returns false static boolean nextPermutation(StringBuilder sb) { int len = sb.length(); int i = len-2; while (i >= 0 && sb.charAt(i) >= sb.charAt(i+1)) i--; if (i < 0) return false; else { int index = binarySearch(sb,i+1,len-1,sb.charAt(i)); swap(sb,i,index); reverse(sb,i+1,len-1); return true; } } private static int lps(int m ,int n,String s1,String s2,int[][]mat) { for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(s1.charAt(i-1)==s2.charAt(j-1))mat[i][j]=1+mat[i-1][j-1]; else mat[i][j]=Math.max(mat[i-1][j],mat[i][j-1]); } } return mat[m][n]; } static String lcs(String X, String Y, int m, int n) { int[][] L = new int[m+1][n+1]; // Following steps build L[m+1][n+1] in bottom up fashion. Note // that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] for (int i=0; i<=m; i++) { for (int j=0; j<=n; j++) { if (i == 0 || j == 0) L[i][j] = 0; else if (X.charAt(i-1) == Y.charAt(j-1)) L[i][j] = L[i-1][j-1] + 1; else L[i][j] = Math.max(L[i-1][j], L[i][j-1]); } } // Following code is used to print LCS int index = L[m][n]; int temp = index; // Create a character array to store the lcs string char[] lcs = new char[index+1]; lcs[index] = '\u0000'; // Set the terminating character // Start from the right-most-bottom-most corner and // one by one store characters in lcs[] int i = m; int j = n; while (i > 0 && j > 0) { // If current character in X[] and Y are same, then // current character is part of LCS if (X.charAt(i-1) == Y.charAt(j-1)) { // Put current character in result lcs[index-1] = X.charAt(i-1); // reduce values of i, j and index i--; j--; index--; } // If not same, then find the larger of two and // go in the direction of larger value else if (L[i-1][j] > L[i][j-1]) i--; else j--; } return String.valueOf(lcs); // Print the lcs // System.out.print("LCS of "+X+" and "+Y+" is "); // for(int k=0;k<=temp;k++) // System.out.print(lcs[k]); } static long lis(long[] aa2, int n) { long lis[] = new long[n]; int i, j; long max = 0; for (i = 0; i < n; i++) lis[i] = 1; for (i = 1; i < n; i++) for (j = 0; j < i; j++) if (aa2[i] >= aa2[j] && lis[i] <= lis[j] + 1) lis[i] = lis[j] + 1; for (i = 0; i < n; i++) if (max < lis[i]) max = lis[i]; return max; } static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) { if (str.charAt(i) != str.charAt(j)) return false; i++; j--; } return true; } static boolean issafe(int i, int j, int r,int c, char ch) { if (i < 0 || j < 0 || i >= r || j >= c|| ch!= '1')return false; else return true; } static long power(long a, long b) { a %=MOD; long out = 1; while (b > 0) { if((b&1)!=0)out = out * a % MOD; a = a * a % MOD; b >>= 1; a*=a; } return out; } static long[] sieve; public static void sieve() { int nnn=(int) 1e6+1; long nn=(int) 1e6; sieve=new long[(int) nnn]; int[] freq=new int[(int) nnn]; sieve[0]=0; sieve[1]=1; for(int i=2;i<=nn;i++) { sieve[i]=1; freq[i]=1; } for(int i=2;i*i<=nn;i++) { if(sieve[i]==1) { for(int j=i*i;j<=nn;j+=i) { if(sieve[j]==1) { sieve[j]=0; } } } } } } class decrease implements Comparator<Long> { // Used for sorting in ascending order of // roll number public int compare(long a, long b) { return (int) (b - a); } @Override public int compare(Long o1, Long o2) { // TODO Auto-generated method stub return (int) (o2-o1); } } class pair{ long x; long y; long c; char ch; public pair(long x,long y) { this.x=x; this.y=y; } public pair(long x,char ch) { this.x=x; this.ch=ch; } public pair(long x,long y,long c) { this.x=x; this.y=y; this.c=c; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d11aca5d7936777fc95966c829da7aac
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.StringTokenizer; public class CodeForces { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public FastScanner(File f){ try { br=new BufferedReader(new FileReader(f)); st=new StringTokenizer(""); } catch(FileNotFoundException e){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } } String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a =new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } public static long factorial(int n){ if(n==0)return 1; return (long)n*factorial(n-1); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void sort (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sortReversed (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b,new Comparator<Integer>(){ @Override public int compare(Integer o1, Integer o2) { return o2-o1; } }); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sort (long[]a){ ArrayList<Long> b = new ArrayList<>(); for(long i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static ArrayList<Integer> sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } ArrayList<Integer> ans = new ArrayList<>(); for (int i = 2; i <= n; i++) { if (prime[i] == true) ans.add(i); } return ans; } static int binarySearchSmallerOrEqual(int arr[], int key) { int n = arr.length; int left = 0, right = n; int mid = 0; while (left < right) { mid = (right + left) >> 1; if (arr[mid] == key) { while (mid + 1 < n && arr[mid + 1] == key) mid++; break; } else if (arr[mid] > key) right = mid; else left = mid + 1; } while (mid > -1 && arr[mid] > key) mid--; return mid; } public static int binarySearchStrictlySmaller(int[] arr, int target) { int start = 0, end = arr.length-1; if(end == 0) return -1; if (target > arr[end]) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static int binarySearch(long arr[], long x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static void init(int[]arr,int val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static void init(int[][]arr,int val){ for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j]=val; } } } static void init(long[]arr,long val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static<T> void init(ArrayList<ArrayList<T>>arr,int n){ for(int i=0;i<n;i++){ arr.add(new ArrayList()); } } static int binarySearchStrictlySmaller(ArrayList<Pair> arr, int target) { int start = 0, end = arr.size()-1; if(end == 0) return -1; if (target > arr.get(end).y) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr.get(mid).y >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearchStrictlyGreater(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] <= target) { start = mid + 1; } else { ans = mid; end = mid - 1; } } return ans; } static long sum (int []a, int[][] vals){ long ans =0; int m=0; while(m<5){ for (int i=m+1;i<5;i+=2){ ans+=(long)vals[a[i]-1][a[i-1]-1]; ans+=(long)vals[a[i-1]-1][a[i]-1]; } m++; } return ans; } public static long pow(long n, long pow) { if (pow == 0) { return 1; } long retval = n; for (long i = 2; i <= pow; i++) { retval *= n; } return retval; } static String reverse(String s){ StringBuffer b = new StringBuffer(s); b.reverse(); return b.toString(); } static String charToString (char[] arr){ String t=""; for(char c :arr){ t+=c; } return t; } public static void main(String[] args) { // StringBuilder sbd = new StringBuilder(); // PrintWriter out = new PrintWriter("output.txt"); // File input = new File("input.txt"); // FastScanner fs = new FastScanner(input); // FastScanner fs = new FastScanner(); // Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int testNumber =fs.nextInt(); // ArrayList<Integer> arr = new ArrayList<>(); for (int T =0;T<testNumber;T++){ // StringBuffer sbf = new StringBuffer(); int n = fs.nextInt(); int [] arr =fs.readArray(n); boolean res = false; for (int i=0;i<n;i++){ int num = arr[i]; res=false; for (int j=2;j<=i+2;j++){ if(num%j!=0){ res=true; break; } } if(!res)break; } out.print(res?"YES\n":"NO\n"); } out.flush(); } static class Pair { int x;//l int y;//r public Pair(int x,int y){ this.x=x; this.y=y; } @Override public boolean equals(Object o) { if(o instanceof Pair){ if(o.hashCode()!=hashCode()){ return false; } else { return x==((Pair)o).x&&y==((Pair)o).y; } } return false; } @Override public int hashCode() { return x+2*y; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1f4553dfb89a4a29f51f825a97ea43cb
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; public class test { public static void main(String[] args) { Scanner sc=new Scanner(System.in); l:for(int t=sc.nextInt();t-->0;) { int n=sc.nextInt(),a[]=new int[n]; for(int i=0;i<n;i++) a[i]=sc.nextInt(); for(int i=1;i<=n;i++) { boolean b=false; for(int j=i+1;j>1&&!b;j--) if(a[i-1]%j>0) b=true; if(!b) {System.out.println("NO"); continue l;} } System.out.println("YES"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
72efc0a7496505e01cf1cce9f2ece884
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class r752a { public static void main(String[] args) { FastScanner scan=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=scan.nextInt(); t:for(int tt=0;tt<t;tt++) { int n=scan.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++) a[i]=scan.nextInt(); for(int i=0;i<Math.min(n,23);i++) { int x=a[i]; if((x>>1)*2==x) { boolean good=false; for(int j=2;j<=i+2;j++) { if(x%j!=0) { good=true; break; } } if(!good) { out.println("NO"); continue t; } } } out.println("YES"); } out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); } catch (Exception e){e.printStackTrace();} } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try {st = new StringTokenizer(br.readLine());} catch (Exception e) {e.printStackTrace();} return st.nextToken(); } public int nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; if(st.hasMoreTokens()) line = st.nextToken(); else try {return br.readLine();}catch(IOException e){e.printStackTrace();} while(st.hasMoreTokens()) line += " "+st.nextToken(); return line; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
e08ce42b39f522fa8ff3bf079fbc4e7f
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static PrintWriter pr = new PrintWriter(System.out); static String readLine() throws IOException { return br.readLine(); } static String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(readLine()); return st.nextToken(); } static int readInt() throws IOException { return Integer.parseInt(next()); } static long readLong() throws IOException { return Long.parseLong(next()); } static double readDouble() throws IOException { return Double.parseDouble(next()); } static char readChar() throws IOException { return next().charAt(0); } static class Pair implements Comparable<Pair> { int f, s; Pair(int f, int s) { this.f = f; this.s = s; } public int compareTo(Pair other) { if (this.f != other.f) return this.f - other.f; return this.s - other.s; } } static void solve() throws IOException { int n = readInt(), a[] = new int[n + 1]; boolean ans = true; for (int i = 1; i <= n; ++i) { a[i] = readInt(); boolean flag = true; for (int p = i; p >= 1 && flag; --p) if (a[i]%(p + 1) != 0) flag = false; if (flag) ans = false; } if (ans) pr.println("YES"); else pr.println("NO"); } public static void main(String[] args) throws IOException { //solve(); for (int t = readInt(); t > 0; --t) solve(); pr.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
b179f36653a34044ed7f3dc137dbbfd0
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public final class Main { static PrintWriter out = new PrintWriter(System.out); static FastReader in = new FastReader(); static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)}; static int mod = (int) (1e9 + 7); static int mod2 = 998244353; public static void main(String[] args) { int tt = i(); while (tt-- > 0) { solve(); } out.flush(); } public static void solve() { int n = i(); int[] a = input(n); long lcm = 2L; for (int i = 0; i < n; i++) { lcm = LCM(lcm, i + 2); if (lcm > 1e9) { break; } if (a[i] % lcm == 0) { out.println("NO"); return; } } out.println("YES"); } static long[] pre(int[] a) { long[] pre = new long[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } static void print(char A[]) { for (char c : A) { out.print(c); } out.println(); } static void print(boolean A[]) { for (boolean c : A) { out.print(c + " "); } out.println(); } static void print(int A[]) { for (int c : A) { out.print(c + " "); } out.println(); } static void print(long A[]) { for (long i : A) { out.print(i + " "); } out.println(); } static void print(List<Integer> A) { for (int a : A) { out.print(a + " "); } } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static double d() { return in.nextDouble(); } static String s() { return in.nextLine(); } static int[][] inputWithIdx(int N) { int A[][] = new int[N][2]; for (int i = 0; i < N; i++) { A[i] = new int[]{i, in.nextInt()}; } return A; } static int[] input(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] inputLong(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) { A[i] = in.nextLong(); } return A; } static int GCD(int a, int b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } static long GCD(long a, long b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } static long LCM(int a, int b) { return (long) a / GCD(a, b) * b; } static long LCM(long a, long b) { return a / GCD(a, b) * b; } static void shuffleAndSort(int[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int[] temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr, comparator); } static void shuffleAndSort(long[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); long temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static boolean isPerfectSquare(double number) { double sqrt = Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static void swap(int A[], int a, int b) { int t = A[a]; A[a] = A[b]; A[b] = t; } static long pow(long a, long b, int mod) { long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) { pow = (pow * x) % mod; } x = (x * x) % mod; b /= 2; } return pow; } static long pow(long a, long b) { long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) { pow *= x; } x = x * x; b /= 2; } return pow; } static long modInverse(long x, int mod) { return pow(x, mod - 2, mod); } static boolean isPrime(long N) { if (N <= 1) { return false; } if (N <= 3) { return true; } if (N % 2 == 0 || N % 3 == 0) { return false; } for (int i = 5; i * i <= N; i = i + 6) { if (N % i == 0 || N % (i + 2) == 0) { return false; } } return true; } public static String reverse(String str) { if (str == null) { return null; } return new StringBuilder(str).reverse().toString(); } public static String repeat(char ch, int repeat) { if (repeat <= 0) { return ""; } final char[] buf = new char[repeat]; for (int i = repeat - 1; i >= 0; i--) { buf[i] = ch; } return new String(buf); } public static int[] manacher(String s) { char[] chars = s.toCharArray(); int n = s.length(); int[] d1 = new int[n]; for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1); while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) { k++; } d1[i] = k--; if (i + k > r) { l = i - k; r = i + k; } } return d1; } public static int[] kmp(String s) { int n = s.length(); int[] res = new int[n]; for (int i = 1; i < n; ++i) { int j = res[i - 1]; while (j > 0 && s.charAt(i) != s.charAt(j)) { j = res[j - 1]; } if (s.charAt(i) == s.charAt(j)) { ++j; } res[i] = j; } return res; } } class Pair { int i, j; Pair(int i, int j) { this.i = i; this.j = j; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Pair pair = (Pair) o; return i == pair.i && j == pair.j; } @Override public int hashCode() { return Objects.hash(i, j); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } class Node { int data, open, close; Node() { this(0, 0, 0); } Node(int data, int open, int close) { this.data = data; this.open = open; this.close = close; } } class ST { int n; Node[] st; ST(int n) { this.n = n; st = new Node[4 * Integer.highestOneBit(n)]; } void build(Node[] nodes) { build(0, 0, n - 1, nodes); } private void build(int id, int l, int r, Node[] nodes) { if (l == r) { st[id] = nodes[l]; return; } int mid = (l + r) >> 1; build((id << 1) + 1, l, mid, nodes); build((id << 1) + 2, mid + 1, r, nodes); st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]); } void update(int i, Node node) { update(0, 0, n - 1, i, node); } private void update(int id, int l, int r, int i, Node node) { if (i < l || r < i) { return; } if (l == r) { st[id] = node; return; } int mid = (l + r) >> 1; update((id << 1) + 1, l, mid, i, node); update((id << 1) + 2, mid + 1, r, i, node); st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]); } Node get(int x, int y) { return get(0, 0, n - 1, x, y); } private Node get(int id, int l, int r, int x, int y) { if (x > r || y < l) { return new Node(); } if (x <= l && r <= y) { return st[id]; } int mid = (l + r) >> 1; return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y)); } Node comb(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } int min = Math.min(a.open, b.close); return new Node(a.data + b.data + min * 2, a.open + b.open - min, a.close + b.close - min); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
b455ceec44db440c5893bd3341cee8ae
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; //Juhaied Hossen //North South University,Bangladesh //Codeforces Round 827 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for (int t = 1;t<=test;t++){ int n = in.nextInt(); int a[] =new int[n+1]; for(int i = 1;i<=n;i++){ a[i] = in.nextInt(); } boolean ans = true; for(int i = 1;i<=n;i++){ boolean flag = true; for(int j = 1;j<=i;j++) if(a[i]%(j+1)!=0){ flag = false; break; } if(flag){ ans= false; break; } } if(ans){ pw.println("YES"); } else { pw.println("NO"); } } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
5bad7fde85ff9e3ce6723ac32ab96679
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* Author:-crazy_coder- */ import java.io.*; import java.util.*; public class cp{ public static void main(String[] args)throws Exception{ BufferedReader br=new BufferedReader (new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->0){ String[] str=br.readLine().split(" "); int n=Integer.parseInt(str[0]); // int x=Integer.parseInt(str[1]); // long B=Long.parseLong(str[1]); String[] str1=br.readLine().split(" "); int[] arr=new int[n+1]; for(int i=0;i<n;i++){ arr[i+1]=Integer.parseInt(str1[i]); } boolean ans=false; for(int i=1;i<=n;i++){ ans=false; for(int j=2;j<i+2;j++){ if(arr[i]%j!=0){ ans=true; break; } } if(!ans)break; } if(ans)pw.println("YES"); else pw.println("NO"); } pw.flush(); } public static ArrayList<Integer> findSquare(int n){ ArrayList<Integer> ans=new ArrayList<>(); int i=0; while(i*i<=2*(n-1)){ ans.add(i*i); i++; } return ans; } //****************************function to find all factor************************************************* public static ArrayList<Long> findAllFactors(long num){ ArrayList<Long> factors = new ArrayList<Long>(); for(long i = 1; i <= num/i; ++i) { if(num % i == 0) { //if i is a factor, num/i is also a factor factors.add(i); factors.add(num/i); } } //sort the factors Collections.sort(factors); return factors; } //*************************** function to find GCD of two number******************************************* public static long gcd(long a,long b){ if(b==0)return a; return gcd(b,a%b); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
ed6fc7d86b497181824adccca42564da
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
/* I am dead inside Do you like NCT, sKz, BTS? 5 4 3 2 1 Moonwalk Imma knock it down like domino Is this what you want? Is this what you want? Let's ttalkbocky about that :() */ import static java.lang.Math.*; import java.util.*; import java.io.*; public class x1603A { public static void main(String omkar[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); int[] arr = readArr(N, infile, st); String res = "YES"; if((arr[1]&1) == 0) res = "NO"; long lcm = 2; for(int i=3; i <= N+1; i++) { long gcd = gcd(lcm, i); lcm /= gcd; lcm *= i; if(lcm > 1000000000) break; if(arr[i-1]%lcm == 0) res = "NO"; } sb.append(res).append("\n"); } System.out.print(sb); } public static int[] readArr(int N, BufferedReader infile, StringTokenizer st) throws Exception { int[] arr = new int[N+1]; st = new StringTokenizer(infile.readLine()); for(int i=0; i < N; i++) arr[i+1] = Integer.parseInt(st.nextToken()); return arr; } public static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } } /* arr[1] must be odd arr[2] can be removed if it's NOT divisible by 2 or 3 arr[3] can be removed if it's NOT divisible by 4 or 3 arr[4] can be removed if it's NOT divisible by 5 (or 4 or 3) */
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
e5faa2de33c960737b4c133aaadc830f
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); long T = sc.nextLong(); while(T-->0){ long n = sc.nextLong(); List<Long> list = new ArrayList<>(); for(int i = 0;i<n;i++){ list.add(sc.nextLong()); } boolean flag = true; for(int i = 0;i<list.size();i++){ boolean d = false; long x = list.get(i); for(int j=i+2;j>=2;j--){ if(x%j!=0){ d=true; break; } } flag &= d; } if(flag){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
c4e4d8fff9caf5e6f581e4ad107585ce
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import static java.lang.Math.*; import java.io.*; import java.math.*; import java.util.*; public class cf1 { static FastReader x = new FastReader(); static OutputStream outputStream = System.out; static PrintWriter out = new PrintWriter(outputStream); /*---------------------------------------CODE STARTS HERE-------------------------*/ public static void main(String[] args) { int t = x.nextInt(); StringBuilder str = new StringBuilder(); while (t > 0) { int n = x.nextInt(); int a[] =new int[n]; for(int i=0;i<n;i++) { a[i] =x.nextInt(); } int count=0; boolean poss=true; for(int i=0;poss&&i<n&&count<1000;i++) { boolean pos=false; for(int j=0;j<=count+1;j++) { if(a[i]%(i+2-j)!=0) { pos=true; break; } } if(pos) { count++; }else { poss=false; break; } } if(poss) { System.out.println("YES"); }else { System.out.println("NO"); } str.append("\n"); t--; } out.println(str); out.flush(); } /*--------------------------------------------FAST I/O--------------------------------*/ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } char nextchar() { char ch = ' '; try { ch = (char) br.read(); } catch (IOException e) { e.printStackTrace(); } return ch; } } /*--------------------------------------------BOILER PLATE---------------------------*/ static int[] readarr(int n) { int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = x.nextInt(); } return arr; } static int[] sortint(int a[]) { ArrayList<Integer> al = new ArrayList<>(); for (int i : a) { al.add(i); } Collections.sort(al); for (int i = 0; i < a.length; i++) { a[i] = al.get(i); } return a; } static long[] sortlong(long a[]) { ArrayList<Long> al = new ArrayList<>(); for (long i : a) { al.add(i); } Collections.sort(al); for (int i = 0; i < al.size(); i++) { a[i] = al.get(i); } return a; } static int pow(int x, int y) { int result = 1; while (y > 0) { if (y % 2 == 0) { x = x * x; y = y / 2; } else { result = result * x; y = y - 1; } } return result; } static int[] revsort(int a[]) { ArrayList<Integer> al = new ArrayList<>(); for (int i : a) { al.add(i); } Collections.sort(al, Comparator.reverseOrder()); for (int i = 0; i < a.length; i++) { a[i] = al.get(i); } return a; } static int[] gcd(int a, int b, int ar[]) { if (b == 0) { ar[0] = a; ar[1] = 1; ar[2] = 0; return ar; } ar = gcd(b, a % b, ar); int t = ar[1]; ar[1] = ar[2]; ar[2] = t - (a / b) * ar[2]; return ar; } static boolean[] esieve(int n) { boolean p[] = new boolean[n + 1]; Arrays.fill(p, true); for (int i = 2; i * i <= n; i++) { if (p[i] == true) { for (int j = i * i; j <= n; j += i) { p[j] = false; } } } return p; } static ArrayList<Integer> primes(int n) { boolean p[] = new boolean[n + 1]; ArrayList<Integer> al = new ArrayList<>(); Arrays.fill(p, true); int i = 0; for (i = 2; i * i <= n; i++) { if (p[i] == true) { al.add(i); for (int j = i * i; j <= n; j += i) { p[j] = false; } } } for (i = i; i <= n; i++) { if (p[i] == true) { al.add(i); } } return al; } static int etf(int n) { int res = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { res /= i; res *= (i - 1); while (n % i == 0) { n /= i; } } } if (n > 1) { res /= n; res *= (n - 1); } return res; } static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) { return b; } return gcd(b % a, a); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d8698551527c73189e0c206e58fa24cf
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class DivisibleConfusion{ static MyScanner sc = new MyScanner(); static void solve(){ int n = sc.nextInt(); long arr[] = sc.readLongArray(n); for(int i = 1;i<=n;i++){ long temp = arr[i-1]; boolean flag = false; for(int j = i+1;j>=2;j--){ if(temp%j!=0){ flag = true; break; } } if(!flag){ out.println("NO"); return; } } out.println("YES"); } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while(t-- >0){ solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
a36d2f37f16ec9c27377167f62482e79
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = in.nextInt(); for (int tt = 0; tt < t; tt++) { int n = in.nextInt(); long[] arr = new long[n]; LinkedList<Long> list = new LinkedList<>(); for (int i = 0; i < n; i++) list.add(in.nextLong()); for (int i = n - 1; i >= 0; i--) { Iterator<Long> l = list.descendingIterator(); int j = i; while (l.hasNext()) { if (j < 0) break; long v = l.next(); if (v % (j + 2) != 0) { l.remove(); break; } j--; } } if (list.isEmpty()) pw.println("YES"); else pw.println("NO"); } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
228a864d7affd026fe5bbb515b47809f
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = in.nextInt(); for (int tt = 0; tt < t; tt++) { int n = in.nextInt(); long[] arr = new long[n]; Arrays.setAll(arr, i -> in.nextLong()); while (n > 0) { int i = n - 1; while (i >= 0 && arr[i] % (i + 2) == 0) i--; if (i < 0) break; for (int j = i; j < n - 1; j++) arr[j] = arr[j + 1]; //debug(n, i); n--; } if (n == 0) pw.println("YES"); else pw.println("NO"); } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
a11706f6d934ad3dd14b4bef9d2f6f00
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class S{ public static void main (String [] args) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); int t = Integer.parseInt(br.readLine()); while (t-->0){ int n = Integer.parseInt(br.readLine()); int ar[]= new int[n]; StringTokenizer st = new StringTokenizer (br.readLine()); for (int i =0;i<n;i++){ ar[i]= Integer.parseInt(st.nextToken()); } boolean flag = true; for (int i=1;i<=n;i++){ int e = ar[i-1]; if (e%(i+1) !=0) continue; else{ flag = false; for (int j=2;j<=i;j++){ if (e%j !=0){ flag = true; break; } } if (!flag) break; } } if (!flag) System.out.println ("NO"); else System.out.println ("YES"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
81847a7b725d702e51c6c9b9a362f91d
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; import java.util.ArrayList; public class divisible { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int b = s.nextInt(); for (int a = 0; a < b; a++) { ArrayList<Integer> nums = new ArrayList<Integer>(); int c = s.nextInt(); for (int i = 0; i < c; i++) { nums.add(s.nextInt()); } int lastsize = -1; while (!(nums.size() == lastsize) && lastsize != 0) { lastsize = nums.size(); for (int i = nums.size() - 1; i >= 0; i--) { if (nums.get(i) % (i + 2) != 0) { nums.remove(i); i=-1; } } } if (nums.size() == 0) { System.out.print("YES" + "\n"); } else { System.out.print("NO" + "\n"); } } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
9bc16b838f10edc443f56696d5b8a609
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.lang.*; // StringBuilder uses java.lang public class mC { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder st = new StringBuilder(); int t = sc.nextInt(); //ArrayList<Long> primesArr = new ArrayList<>(); //primesArr.add((long)2); //for (long i = 3; i <= 200; i+=2) { // boolean pos = true; // for (int j = 2; primesArr.get(j) * primesArr.get(j) <= i; j++) { // if (gcd(i,primesArr.get(j)) != 1) { // pos = false; // break; // } // } // if (pos == true) { // primesArr.add(i); // } //} for (int test = 0; test < t; test++) { int n = sc.nextInt(); boolean possible = true; for (int i = 0; i < n; i++) { int m = sc.nextInt(); if (i < 200) { boolean works = false; for (int j = 2; j <= i+2; j++) { if (gcd(j, m) != j) { works = true; break; } } if (works == false) { possible = false; } } } if (possible) { st.append("YES\n"); } else { st.append("NO\n"); } } System.out.print(st.toString()); } public static int firstLargerAb(int val,ArrayList<Integer> ok,int left,int right) { if (Math.abs(ok.get(right))<=val) { return -1; } if (left==right) { return left; } else if (left+1==right) { if (val<Math.abs(ok.get(left))) { return left; } else { return right; } } else { int mid = (left+right)/2; if (Math.abs(ok.get(mid))>val) { return firstLargerAb(val,ok,left,mid); } else { return firstLargerAb(val,ok,mid+1,right); } } } public static int findNthInArray(int[] arr,int val,int start,int o) { if (o==0) { return start-1; } else if (arr[start] == val) { return findNthInArray(arr,val,start+1,o-1); } else { return findNthInArray(arr,val,start+1,o); } } public static ArrayList<Integer> dfs(int at,ArrayList<Integer> went,ArrayList<ArrayList<Integer>> connect) { for (int i=0;i<connect.get(at).size();i++) { if (!(went.contains(connect.get(at).get(i)))) { went.add(connect.get(at).get(i)); went=dfs(connect.get(at).get(i),went,connect); } } return went; } public static int[] bfs (int at, int[] went, ArrayList<ArrayList<Integer>> queue, int numNodes, ArrayList<ArrayList<Integer>> connect) { if (went[at]==0) { went[at]=queue.get(numNodes).get(1); for (int i=0;i<connect.get(at).size();i++) { if (went[connect.get(at).get(i)]==0) { ArrayList<Integer> temp = new ArrayList<>(); temp.add(connect.get(at).get(i)); temp.add(queue.get(numNodes).get(1)+1); queue.add(temp); } } } if (queue.size()==numNodes+1) { return went; } else { return bfs(queue.get(numNodes+1).get(0),went, queue, numNodes+1, connect); } } public static long fastPow(long base,long exp,long mod) { if (exp==0) { return 1; } else { if (exp % 2 == 1) { long z = fastPow(base,(exp-1)/2,mod); return ((((z*base) % mod) * z) % mod); } else { long z = fastPow(base,exp/2,mod); return ((z*z) % mod); } } } public static int fastPow(int base,long exp) { if (exp==0) { return 1; } else { if (exp % 2 == 1) { int z = fastPow(base,(exp-1)/2); return ((((z*base)) * z)); } else { int z = fastPow(base,exp/2); return ((z*z)); } } } public static int firstLarger(int val,ArrayList<Integer> ok,int left,int right) { if (ok.get(right)<=val) { return -1; } if (left==right) { return left; } else if (left+1==right) { if (val<ok.get(left)) { return left; } else { return right; } } else { int mid = (left+right)/2; if (ok.get(mid)>val) { return firstLarger(val,ok,left,mid); } else { return firstLarger(val,ok,mid+1,right); } } } public static int binSearchArr(long val,ArrayList<Integer> ok,long[] arr,int left,int right) { if (arr[ok.get(right)]<=val) { return -1; } if (left==right) { return left; } else if (left+1==right) { if (val<arr[ok.get(left)]) { return left; } else { return right; } } else { int mid = (left+right)/2; if (arr[ok.get(mid)]>val) { return binSearchArr(val,ok,arr,left,mid); } else { return binSearchArr(val,ok,arr,mid+1,right); } } } public static long gcd(long a, long b) { if (b>a) { return gcd(b,a); } if (b==0) { return a; } if (a%b==0) { return b; } else { return gcd(b,a%b); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
827803815b01994406f747f0f0d0842a
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; ++i) { a[i] = sc.nextInt(); } System.out.println(solve(a) ? "YES" : "NO"); } sc.close(); } static boolean solve(int[] a) { List<Integer> rest = Arrays.stream(a).boxed().collect(Collectors.toList()); while (!rest.isEmpty()) { int index = rest.size() - 1; while (index != -1 && rest.get(index) % (index + 2) == 0) { --index; } if (index == -1) { return false; } rest.remove(index); } return true; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
65ff201d65615030eabc6454633d225a
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; import java.util.*; import static java.lang.System.out; import static java.lang.Math.*; public class pre212 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class MultiSet<K> { TreeMap<K, Integer> map; MultiSet() { map = new TreeMap<>(); } void add(K a) { map.put(a, map.getOrDefault(a, 0) + 1); } boolean contains(K a) { return map.containsKey(a); } void remove(K a) { map.put(a, map.get(a) - 1); if (map.get(a) == 0) map.remove(a); } int occrence(K a) { return map.get(a); } K floor(K a) { return map.floorKey(a); } K ceil(K a) { return map.ceilingKey(a); } @Override public String toString() { ArrayList<K> set = new ArrayList<>(); for (Map.Entry<K, Integer> i : map.entrySet()) { for (int j = 1; j <= i.getValue(); j++) set.add(i.getKey()); } return set.toString(); } } static class Pair<K, V> { K value1; V value2; Pair(K a, V b) { value1 = a; value2 = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair<?, ?> p = (Pair<?, ?>) o; return Objects.equals(this.value1, p.value1) && Objects.equals(this.value2, p.value2); } @Override public int hashCode() { int result = this.value1.hashCode(); result = 31 * result + this.value2.hashCode(); return result; } @Override public String toString() { return ("[" + value1 + " <=> " + value2 + "]"); } } static ArrayList<Integer> primes; static void setPrimes(int n) { boolean p[] = new boolean[n]; Arrays.fill(p, true); for (int i = 2; i < p.length; i++) { if (p[i]) { primes.add(i); for (int j = i * 2; j < p.length; j += i) p[j] = false; } } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } public static void main(String args[]) { FastReader obj = new FastReader(); int tc = obj.nextInt(); while(tc--!=0){ int n = obj.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); for(int i=0;i<n;i++) arr.add(obj.nextInt()); int size = arr.size(); boolean ans = true; while(arr.size()>0){ int idx = 0; for(int i=arr.size()-1;i>=0;i--){ if(arr.get(i)%(i+2)!=0){ arr.remove(i); break; } } if(size==arr.size()){ ans = false; break; }else size = arr.size(); } ans &= arr.size()==0; out.println(ans?"YES":"NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
ce72194049f258172077bca57a570c08
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; public class A1603 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); int[] A = new int[N]; for (int n=0; n<N; n++) { A[n] = in.nextInt(); } // number on positions >= 22 must be divisible by one of 2,...,23 int last = Math.min(20, A.length-1); int current = last; while (current >= 0) { if (A[current] % (current+2) != 0) { // delete for (int i=current; i<last; i++) { A[i] = A[i+1]; } last--; current = last; } else { current--; } } System.out.println((last == -1) ? "YES" : "NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
51bb178111ecc470d4dfb4c6a865ce2f
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Arrays; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args){ new Main().run(); } int N = 100010; int a[] = new int[N]; void run() { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { int n =sc.nextInt(); for(int i=1;i<=n;i++) a[i] = sc.nextInt(); String res = "YES"; for(int i=1;i<=n;i++) { boolean flag= false; for(int j=1;j<=i;j++) if(a[i]%(j+1)!=0) { flag = true; break; } if(!flag) { res = "NO"; break; } } System.out.println(res); t--; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
4112d0595a71372351eba465512780d8
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); Scanner sc = new Scanner(System.in); //code part int t = sc.nextInt(); while (t-- > 0){ int n = sc.nextInt(); int[] nums = new int[n + 1]; boolean ans = true; for (int i = 1; i <= n; i++) { nums[i] = sc.nextInt(); boolean flag = false; for(int j = i + 1; j >= 2; j--){ if(nums[i] % j != 0){ flag = true; break; } } ans &= flag; } if(ans){ System.out.println("YES"); }else{ System.out.println("NO"); } } //code part sc.close(); writer.flush(); writer.close(); reader.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
b591853dc2a610d17e3a6df3188f3424
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.StringTokenizer; public class CodeForces { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public FastScanner(File f){ try { br=new BufferedReader(new FileReader(f)); st=new StringTokenizer(""); } catch(FileNotFoundException e){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } } String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a =new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } public static long factorial(int n){ if(n==0)return 1; return (long)n*factorial(n-1); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void sort (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sortReversed (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b,new Comparator<Integer>(){ @Override public int compare(Integer o1, Integer o2) { return o2-o1; } }); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sort (long[]a){ ArrayList<Long> b = new ArrayList<>(); for(long i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static ArrayList<Integer> sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } ArrayList<Integer> ans = new ArrayList<>(); for (int i = 2; i <= n; i++) { if (prime[i] == true) ans.add(i); } return ans; } static int binarySearchSmallerOrEqual(int arr[], int key) { int n = arr.length; int left = 0, right = n; int mid = 0; while (left < right) { mid = (right + left) >> 1; if (arr[mid] == key) { while (mid + 1 < n && arr[mid + 1] == key) mid++; break; } else if (arr[mid] > key) right = mid; else left = mid + 1; } while (mid > -1 && arr[mid] > key) mid--; return mid; } public static int binarySearchStrictlySmaller(int[] arr, int target) { int start = 0, end = arr.length-1; if(end == 0) return -1; if (target > arr[end]) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static int binarySearch(long arr[], long x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static void init(int[]arr,int val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static void init(int[][]arr,int val){ for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j]=val; } } } static void init(long[]arr,long val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static<T> void init(ArrayList<ArrayList<T>>arr,int n){ for(int i=0;i<n;i++){ arr.add(new ArrayList()); } } static int binarySearchStrictlySmaller(ArrayList<Pair> arr, int target) { int start = 0, end = arr.size()-1; if(end == 0) return -1; if (target > arr.get(end).y) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr.get(mid).y >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearchStrictlyGreater(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] <= target) { start = mid + 1; } else { ans = mid; end = mid - 1; } } return ans; } static long sum (int []a, int[][] vals){ long ans =0; int m=0; while(m<5){ for (int i=m+1;i<5;i+=2){ ans+=(long)vals[a[i]-1][a[i-1]-1]; ans+=(long)vals[a[i-1]-1][a[i]-1]; } m++; } return ans; } public static long pow(long n, long pow) { if (pow == 0) { return 1; } long retval = n; for (long i = 2; i <= pow; i++) { retval *= n; } return retval; } static String reverse(String s){ StringBuffer b = new StringBuffer(s); b.reverse(); return b.toString(); } static String charToString (char[] arr){ String t=""; for(char c :arr){ t+=c; } return t; } public static void main(String[] args) { // StringBuilder sbd = new StringBuilder(); // PrintWriter out = new PrintWriter("output.txt"); // File input = new File("input.txt"); // FastScanner fs = new FastScanner(input); // FastScanner fs = new FastScanner(); // Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int testNumber =fs.nextInt(); // ArrayList<Integer> arr = new ArrayList<>(); for (int T =0;T<testNumber;T++){ // StringBuffer sbf = new StringBuffer(); int n = fs.nextInt(); int [] arr =fs.readArray(n); boolean res = false; for (int i=0;i<n;i++){ int num = arr[i]; res=false; for (int j=2;j<=i+2;j++){ if(num%j!=0){ res=true; break; } } if(!res)break; } out.print(res?"YES\n":"NO\n"); } out.flush(); } static class Pair { int x;//l int y;//r public Pair(int x,int y){ this.x=x; this.y=y; } @Override public boolean equals(Object o) { if(o instanceof Pair){ if(o.hashCode()!=hashCode()){ return false; } else { return x==((Pair)o).x&&y==((Pair)o).y; } } return false; } @Override public int hashCode() { return x+2*y; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
7a0c26909c7e7a3b41ec2e6a16a4648e
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
//package com.rajan.codeforces.leve_1300; import java.io.*; public class Di_visibleConfusion { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); int tt = Integer.parseInt(reader.readLine()); while (tt-- > 0) { int n = Integer.parseInt(reader.readLine()); int[] nums = new int[n]; String[] temp = reader.readLine().split("\\s+"); for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(temp[i]); if (nums[0] % 2 == 0) { writer.write("No\n"); continue; } boolean ok = true; for (int i = 0; i < n; i++) { boolean found = false; for (int j = i + 2; j >= 2; j--) { if ((nums[i] % j) != 0) { found = true; break; } } ok &= found; } if (ok) writer.write("Yes\n"); else writer.write("No\n"); } writer.flush(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
910167e18489fad3d18d051ed9c8bfef
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class A { public static void main(String[] args) { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for(int ttt = 1; ttt <= T; ttt++) { int n = in.nextInt(); int[] a = in.readInt(n); boolean p = false; for(int i = 0; i < n; i++) { p = false; if(a[i] < i+2) p = true; else { for(int j = 2; j <= i+2; j++) { if(a[i]%j != 0) { p = true; break; } } } if(!p) break; } if(p) out.println("YES"); else out.println("NO"); } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } int[] readInt(int size) { int[] arr = new int[size]; for(int i = 0; i < size; i++) arr[i] = Integer.parseInt(next()); return arr; } long[] readLong(int size) { long[] arr = new long[size]; for(int i = 0; i < size; i++) arr[i] = Long.parseLong(next()); return arr; } int[][] read2dArray(int rows, int cols) { int[][] arr = new int[rows][cols]; for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) arr[i][j] = Integer.parseInt(next()); } return arr; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1c0766a60793dc6d905eddc0af4691c8
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws Exception { int tc = io.nextInt(); for (int i = 0; i < tc; i++) { solve(); } io.close(); } private static void solve() throws Exception { int n = io.nextInt(); int[] data = io.nextInts(n); long lcm = 1; for (int i = 0; i < n; i++) { lcm = lcm(lcm, i + 2); if (data[i] % lcm == 0) { io.println("NO"); return; } } io.println("YES"); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static long gcd(long a, long b) { while (b != 0) { a %= b; long temp = a; a = b; b = temp; } return a; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(a.length); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } //-----------PrintWriter for faster output--------------------------------- public static FastIO io = new FastIO(); //-----------MyScanner class for faster input---------- static class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public String nextLine() { int c; do { c = nextByte(); } while (c < '\n'); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > '\n'); return res.toString(); } public int nextInt() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } int[] nextInts(int n) { int[] data = new int[n]; for (int i = 0; i < n; i++) { data[i] = io.nextInt(); } return data; } public double nextDouble() { return Double.parseDouble(next()); } } //-------------------------------------------------------- }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
e43c65c4b1e37a79aba45b0d172ff9c4
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.math.*; import java.util.* ; import java.io.* ; @SuppressWarnings("unused") //I am working for the day i will surpass you //Scanner s = new Scanner(new File("input.txt")); //s.close();//USN:SSINGH0271 //PrintWriter writer = new PrintWriter("output.txt"); //writer.close(); public class cf { public static void main(String[] args)throws Exception { FastReader in = new FastReader() ; // FastIO in = new FastIO(System.in) ; StringBuilder op = new StringBuilder() ; int T = in.nextInt() ; // int T=1 ; for(int tt=0 ; tt<T ; tt++) { int n = in.nextInt(); int a[] = in.readArray(n) ; int rem=0 ,f=0 ; for(int i=1 ; i<=n ; i++) { if(a[i-1]%(i-rem+1)!=0) { rem++ ; } else { int flag=0 ; for(int div=i+1 ; div>=i+1-rem ; div--) { if(a[i-1]%div!=0) { flag=1; rem++ ; break ; } } if(flag==0) { f=1;break ; } } } if(f==1)op.append("NO\n") ; else op.append("YES\n") ; } System.out.println(op.toString()); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); }; String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
357aec060a161e7fe33da468fe119b8c
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < a.length; ++i) { a[i] = sc.nextInt(); } System.out.println(solve(a) ? "YES" : "NO"); } sc.close(); } static boolean solve(int[] a) { List<Integer> rest = Arrays.stream(a).boxed().collect(Collectors.toList()); while (!rest.isEmpty()) { int index = rest.size() - 1; while (index != -1 && rest.get(index) % (index + 2) == 0) { --index; } if (index == -1) { return false; } rest.remove(index); } return true; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
0e2fd8018701fdf4e4877748e04c527c
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class Omar { static PrintWriter pw = new PrintWriter(System.out); static Scanner sc=new Scanner(System.in); public static void main(String[] args) throws IOException { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int []arr=sc.nextIntArray(n); boolean f=true; for(int i=0;i<n;i++) { boolean can=false; for(long j=2;j<=Math.min(i+2,23);j++) { if(arr[i]%j!=0) { can=true; break; } } f&=can; if(!f)break; } pw.println(f?"YES":"NO"); } pw.flush(); } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static class PairPoint { pair p1; pair p2; public PairPoint(pair p1, pair p2) { this.p1 = p1; this.p2 = p2; } public String toString() { return p1.toString() + p2.toString(); } public boolean equals(PairPoint pp) { if (p1.equals(pp.p1) && p2.equals(pp.p2)) return true; return false; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
1a46f1f2144070942b0760d27d923cfe
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.Scanner; public class DivisibleConfusion { public static void solve(int n,long[] arr) { long lcm=1; for (int i = 1; i <= n; i++) { lcm=(lcm*(i+1))/gcd(lcm, i+1); // System.out.println(lcm+" hi"); if(arr[i]%lcm==0) { System.out.println("NO"); return; } } System.out.println("YES"); } public static long gcd(long a,long b) { if(b==0) { return a; } else { return gcd(b,a%b); } } public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int t=in.nextInt(); for (int i = 0; i< t; i++) { int n=in.nextInt(); long[] arr=new long[n+1]; for (int j = 1; j <= n; j++) { arr[j] = in.nextLong(); } solve(n, arr); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
771a3a928ba4cddc1fd3e808f151584b
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Task { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader reader = new FastReader(); int tests = reader.nextInt(); for (int T = 0; T < tests; T++) { int n = reader.nextInt(); boolean valid = true; for (int i = 2; i < n + 2; i++) { int next = reader.nextInt(); boolean nextValid = false; for (int j = i; j >= 2; j--) { nextValid = (next % j) != 0; if (nextValid) break; } valid &= nextValid; } System.out.println(valid ? "YES" : "NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
0c232f642ce74fafdc655f66b72c33e3
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class Main{ public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static long MOD = (long) (1e9 + 7); // static long MOD = 998244353; static long MOD2 = MOD * MOD; static FastReader sc = new FastReader(); static int pInf = Integer.MAX_VALUE; static int nInf = Integer.MIN_VALUE; static long ded = (long)(1e17)+9; public static void main(String[] args) throws Exception { int test = 1; test = sc.nextInt(); for (int i = 1; i <= test; i++){ // out.print("Case #"+i+": "); solve(); } out.flush(); out.close(); } static void solve(){ int n = sc.nextInt(); int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = sc.nextInt(); } for(int i = 0; i < n; i++){ boolean found = false; for(int j = 2; j <= i+2; j++){ if(a[i]%j!=0){ found = true; break; } } if(!found){ out.println("NO"); return; } } out.println("YES"); } static long lcm(long a, long b){ return (a*b)/gcd(a,b); } public static long mul(long a, long b) { return ((a % MOD) * (b % MOD)) % MOD; } public static long sub(long a, long b) { return ((a%MOD)-(b%MOD)+MOD)%MOD; } public static long add(long a, long b) { if((a+b)>MOD){ return a+b-MOD; }else{ return a+b; } // return ((a % MOD) + (b % MOD)) % MOD; } static class Pair implements Comparable<Pair> { int x; int y; int idx; public Pair(int x, int y,int idx) { this.x = x; this.y = y; this.idx = idx; } @Override public int compareTo(Pair o){ if(this.y==o.y){ return Integer.compare(this.x,o.x); } return Integer.compare(this.y,o.y); } @Override public String toString() { return "Pair{" + "x=" + x + ", y=" + y + '}'; // return x+" "+y; } // public boolean equals(Pair o){ // return this.x==o.x&&this.y==o.y; // } } public static long c2(long n) { if ((n & 1) == 0) { return mul(n / 2, n - 1); } else { return mul(n, (n - 1) / 2); } } //Shuffle Sort static final Random random = new Random(); static void ruffleSort(long[] a) { int n = a.length;//shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n); long temp= a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } //Brian Kernighans Algorithm static long countSetBits(long n) { if (n == 0) return 0; return 1 + countSetBits(n & (n - 1)); } //Euclidean Algorithm static long gcd(long A, long B) { if (B == 0) return A; return gcd(B, A % B); } //Modular Exponentiation static long fastExpo(long x, long n) { if (n == 0) return 1; if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD; return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD; } //AKS Algorithm static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i <= Math.sqrt(n); i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static long modinv(long x) { return modpow(x, MOD - 2); } public static long modpow(long a, long b) { if (b == 0) { return 1; } long x = modpow(a, b / 2); x = (x * x) % MOD; if (b % 2 == 1) { return (x * a) % MOD; } return x; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
ea0f8375d702475e67f602ba09497eee
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; //start of Scanner class public class msa { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw = new PrintWriter(System.out); static StringTokenizer st; static Snner sc = new Snner(System.in); static public int maximumProduct(int[] num) { int max1 = 1, max2 = 1; Arrays.sort(num); for (int i = 0; i < 3; i++) { max1 *= num[num.length - 1 - i]; if (i < 2) max2 *= num[i]; } max2 *= num[num.length - 1]; return max1 > max2 ? max1 : max2; } public static void main(String args[]) throws NumberFormatException, IOException { int t = sc.nextInt(); while (t-- > 0) { long arr[] = new long[sc.nextInt()]; for (int i = 0; i < arr.length; i++) arr[i] = sc.nextLong(); pw.println(solve_c(arr) ? "yes" : "no"); } pw.close(); } //segtree static long b(int arr[][]) { int s = 1; int e = (int) 10e9; int mid; while (s <= e) { mid = s + ((e - s) >> 1); int temp = sum(arr, mid); if (temp < 0) s = mid + 1; else if (temp == 0) return mid; else e = mid - 1; } return s; } static long solve(long arr[][]) { long b[] = new long[arr.length]; long max0 = Long.MIN_VALUE; for (int i = 0; i < arr.length; i++) { long max = Long.MIN_VALUE; for (int j = 1; j < arr[i].length; j++) { max = Math.max(max, arr[i][j] - j + 1); } long k = arr[i].length; b[i] = max - k; } Arrays.sort(b); return b[b.length - 1]; } private static int sum(int[][] arr, int mid) { int sum = arr[0][0] + 1; for (int i = 0; i < arr.length; i++) { for (int j = 1; j < arr[i].length; j++) { if (sum < arr[i][j]) sum += 1 + arr[i][j] - sum; sum++; } } return mid - sum; } static long solveb(long n, long k) { ; long done = 1; long poss = 1; long i = 0; if (k == 1) return n - 1; if (k > n) k = n; while (done < k && done < n) { i++; done += poss; poss = done; } if ((n - done) % k > 0) i++; i += (n - done) / k; return i; } // //end of public clas static String solve_a(String x) { int a = 0, b = 0; for (int i = 0; i < x.length() - 1; i++) { if (x.charAt(i) != x.charAt(i + 1)) { if (x.charAt(i) == 'a') a++; else b++; } } //char aa[] = x.toCharArray(); StringBuilder xx = new StringBuilder(x); if (a == b) return x; else if (a > b) { for (int i = 0; i < x.length(); i++) { if (x.charAt(i) == 'a') { xx.setCharAt(i, 'b'); break; } } } else { for (int i = 0; i < x.length(); i++) { if (x.charAt(i) == 'b') { xx.setCharAt(i, 'a'); break; } } } return xx.toString(); } static void solve_c() throws IOException { long sum = 0; long t = sc.nextLong(); while (t-- > 0) { int n = sc.nextInt(); long k = sc.nextLong(); long arr[] = new long[n]; for (int i = 0; i < n; i++) { arr[i] = (long) Math.pow(10, sc.nextLong()); } int i = 0; while (k > 0) { arr[n - 1 - (i)] = k / arr[n - 1 - i]; if (arr[n - 1 - i] != 0) k %= arr[n - 1 - i]; i++; } for (long a : arr) sum += a; pw.println(sum); sum = 0; } } static boolean solve_c(long arr[]) { boolean done = true, found = false; for (int j = 0; j < arr.length; j++) { found = false; for (int i = j + 2; i >= 2; i--) { if (arr[j] % i != 0) { found = true; break; } } done &= found; if (done == false) return false; } return done; } int count(String x) { int c = 0; for (int i = 0; i < x.length() - 1; i++) { if (x.charAt(i) != x.charAt(i + 1)) c++; } return c; } boolean prime_or_not(long x) { if (x % 2 == 0 || x % 3 == 0) return false; for (long i = 6; i * i < x; i += 6) if (x % (i + 1) == 0 || x % (i - 1) == 0) return false; return true; } static class Snner { StringTokenizer st; BufferedReader br; public Snner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Snner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } class SegmentTree { int N, n; long[] arr, a; long ident; //arr = segment tree; //a is input_array but (1 based , its len is completed to power 2 with identity values if possible ); //N =len of a; //n=num of input array element ; // All index are 1 based except for am array (in the constructor); SegmentTree(long[] am, long ident) { n = am.length; N = 1; while (N < n) N *= 2; a = new long[N + 1]; this.ident = ident; Arrays.fill(a, ident); for (int i = 0; i < n; i++) a[i + 1] = am[i]; arr = new long[2 * N]; Arrays.fill(arr, ident); build(1, 1, N); } long build(int node, int l, int r) { if (l == r) return arr[node] = a[node - (N - 1)]; int mid = (l + r) / 2; return arr[node] = build(2 * node, l, mid) + build(2 * node + 1, mid + 1, r); } void update_point(int index, long new_value) { arr[N - 1 + index] = new_value; index = index + N - 1; while (index > 1) { index /= 2; arr[index] = arr[2 * index] + arr[2 * index + 1]; } } long query(int l, int r) { return q(1, 1, N, l, r); } private long q(int node, int s, int e, int l, int r) { if (l > e || r < s) return ident; if (s >= l && e <= r) return arr[node]; int mid = (s + e) / 2; return q(node * 2, s, mid, l, r) + q(node * 2 + 1, mid + 1, e, l, r); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d5fc526055d42cc1094950d4bf6a3ca7
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class c { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); long lcm[] = new long[25]; lcm[0] = 1; lcm[1] = 1; lcm[2] = 2; for(int i=2; i<lcm.length; i++){ lcm[i] = (lcm[i-1]*i) / gcd(lcm[i-1], i); } while(t-- > 0){ int n = sc.nextInt(); long arr[] = new long[n]; for(int i=0; i<n; i++){ arr[i] = sc.nextLong(); } boolean ans = true; for(int i=0; i<Math.min(22, arr.length); i++){ if(arr[i] % lcm[i+2] == 0){ ans = false; } } if(ans){ System.out.println("YES"); } else{ System.out.println("No"); } } } public static long gcd(long a, long b){ if(a%b == 0){ return b; } return gcd(b, a%b); } } class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
04ae74aa6a4207de53dc2dded379131c
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.StringTokenizer; public class P1604C { static PrintWriter out = new PrintWriter(System.out); static MyFastReaderP1604C in = new MyFastReaderP1604C(); static long mod = (long) (1e9 + 7); public static void main(String[] args) throws Exception { int test = i(); while (test-- > 0) { int n = i(); int arr[] = arrI(n); boolean isPossible = true; for (int i = 1; i <= n; i++) { boolean st = false; for (int k = 2; k <= i+1; k++) { if (arr[i - 1] % k != 0) { st = true; break; } } if (st == false) { isPossible = false; break; } } if(isPossible) out.print("YES"); else out.print("NO"); out.print("\n"); out.flush(); } out.close(); } static class pair { long x, y; pair(long ar, long ar2) { x = ar; y = ar2; } } static void sort(long[] a) // check for long { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static class DescendingComparator implements Comparator<Integer> { public int compare(Integer a, Integer b) { return b - a; } } static class AscendingComparator implements Comparator<Integer> { public int compare(Integer a, Integer b) { return a - b; } } static boolean isPalindrome(char X[]) { int l = 0, r = X.length - 1; while (l <= r) { if (X[l] != X[r]) return false; l++; r--; } return true; } static long fact(long N) { long num = 1L; while (N >= 1) { num = ((num % mod) * (N % mod)) % mod; N--; } return num; } static long pow(long a, long b) { long mod = 1000000007; long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) pow = (pow * x) % mod; x = (x * x) % mod; b /= 2; } return pow; } static long toggleBits(long x)// one's complement || Toggle bits { int n = (int) (Math.floor(Math.log(x) / Math.log(2))) + 1; return ((1 << n) - 1) ^ x; } static int countBits(long a) { return (int) (Math.log(a) / Math.log(2) + 1); } static boolean isPrime(long N) { if (N <= 1) return false; if (N <= 3) return true; if (N % 2 == 0 || N % 3 == 0) return false; for (int i = 5; i * i <= N; i = i + 6) if (N % i == 0 || N % (i + 2) == 0) return false; return true; } static long GCD(long a, long b) { if (b == 0) { return a; } else return GCD(b, a % b); } // Debugging Functions Starts static void print(char A[]) { for (char c : A) System.out.print(c + " "); System.out.println(); } static void print(boolean A[]) { for (boolean c : A) System.out.print(c + " "); System.out.println(); } static void print(int A[]) { for (int a : A) System.out.print(a + " "); System.out.println(); } static void print(long A[]) { for (long i : A) System.out.print(i + " "); System.out.println(); } static void print(ArrayList<Integer> A) { for (int a : A) System.out.print(a + " "); System.out.println(); } // Debugging Functions END // ---------------------- // IO FUNCTIONS STARTS static HashMap<Integer, Integer> Hash(int A[]) { HashMap<Integer, Integer> mp = new HashMap<>(); for (int a : A) { int f = mp.getOrDefault(a, 0) + 1; mp.put(a, f); } return mp; } static String string() { return in.nextLine(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] arrI(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] arrL(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) A[i] = in.nextLong(); return A; } } class MyFastReaderP1604C { BufferedReader br; StringTokenizer st; public MyFastReaderP1604C() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
d7d8a0034fa3230e2064a7238112079a
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder bw = new StringBuilder(); int TC = Integer.parseInt(br.readLine()); while (TC-- > 0) { int N = Integer.parseInt(br.readLine()); int[] S = new int[N + 1]; StringTokenizer st = new StringTokenizer(br.readLine(), " "); for (int i = 1; i <= N; i++) S[i] = Integer.parseInt(st.nextToken()); boolean flag = true; for (int i = 1; i <= Math.min(N, 22); i++) { boolean temp = false; for (int j = 2; j <= i + 1; j++) { if ((S[i] % j) != 0) temp = true; } if (!temp) flag = false; } bw.append(flag ? "YES" : "NO"); bw.append("\n"); } System.out.print(bw); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
c49ef3bef6b604d004ce62f767fcc6a6
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Locale; import java.util.StringTokenizer; public class Solution implements Runnable { private PrintStream out; private BufferedReader in; private StringTokenizer st; public void solve() throws IOException { long time0 = System.currentTimeMillis(); int t = nextInt(); for (int test = 1; test <= t; test++) { int n = nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } boolean answer = solve(n, a); if (answer) { out.println("YES"); } else { out.println("NO"); } } System.err.println("time: " + (System.currentTimeMillis() - time0)); } private boolean solve(int n, int[] a) { int lcm = 1; for (int i = 0; i < n; i++) { int j = i + 2; int gcd = gcd(lcm, j); long nlcm = 1L * lcm * (j / gcd); if (a[i] % nlcm == 0) { return false; } lcm = (int) nlcm; } return true; } private int gcd(int a, int b) { while (a > 0) { int tmp = a; a = b % a; b = tmp; } return b; } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } @Override public void run() { try { solve(); out.close(); } catch (Throwable e) { throw new RuntimeException(e); } } public Solution(String name) throws IOException { Locale.setDefault(Locale.US); if (name == null) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintStream(new BufferedOutputStream(System.out)); } else { in = new BufferedReader(new InputStreamReader(new FileInputStream(name + ".in"))); out = new PrintStream(new BufferedOutputStream(new FileOutputStream(name + ".out"))); } st = new StringTokenizer(""); } public static void main(String[] args) throws IOException { new Thread(new Solution(null)).start(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
7da3d4de4964ff636c8de95a09d95745
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.io.*; public class A1603 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] arr = sc.nextIntArr(n); boolean valid = true; for (int i = 0; i < n; i++) { boolean rem = false; for (int j = Math.max(0, i - 30); j <= i; j++) { rem |= arr[i] % (j + 2) != 0; } valid &= rem; } pw.println(valid ? "YES" : "NO"); } pw.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
46196bf0ece7a89572244377f2a0df39
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class A { public static void main(String[] args) throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(in.readLine()); for (int ti=0;ti<t;ti++) { int n=Integer.parseInt(in.readLine()); String[] ss=in.readLine().split(" "); int[] a=new int[n]; for (int i=0;i<n;i++) { a[i]=Integer.parseInt(ss[i]); } boolean can=true; for (int i=0;i<n;i++) { boolean cani = false; for (int p=2; p<=i+2; p++) { if (a[i] % p != 0) { cani = true; break; } } if (!cani) { can=false;break; } } System.out.println(can?"YES":"NO"); } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
63ef1f44620b268ddf7890348a180d84
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.util.*; import java.util.function.*; import java.io.*; // you can compare with output.txt and expected out public class Round752Div1A { MyPrintWriter out; MyScanner in; // final static long FIXED_RANDOM; // static { // FIXED_RANDOM = System.currentTimeMillis(); // } final static String IMPOSSIBLE = "IMPOSSIBLE"; final static String POSSIBLE = "POSSIBLE"; final static String YES = "YES"; final static String NO = "NO"; private void initIO(boolean isFileIO) { if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) { try{ in = new MyScanner(new FileInputStream("input.txt")); out = new MyPrintWriter(new FileOutputStream("output.txt")); } catch(FileNotFoundException e){ e.printStackTrace(); } } else{ in = new MyScanner(System.in); out = new MyPrintWriter(new BufferedOutputStream(System.out)); } } public static void main(String[] args){ // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); // the code for the deep recursion (more than 100k or 3~400k or so) // Thread t = new Thread(null, new RoundEdu130F(), "threadName", 1<<28); // t.start(); // t.join(); Round752Div1A sol = new Round752Div1A(); sol.run(); } private void run() { boolean isDebug = false; boolean isFileIO = true; boolean hasMultipleTests = true; initIO(isFileIO); precalculate(); int t = hasMultipleTests? in.nextInt() : 1; for (int i = 1; i <= t; ++i) { if(isDebug){ out.printf("Test %d\n", i); } getInput(); solve(); printOutput(); } in.close(); out.close(); } // use suitable one between matrix(2, n), matrix(n, 2), transposedMatrix(2, n) for graph edges, pairs, ... int n; int[] a; void getInput() { n = in.nextInt(); a = in.nextIntArray(n); } void printOutput() { out.printlnAns(ans); } boolean ans; void solve(){ // a[i] is not divisible by j+2 for some j <= i -> can delete it // how can this be not true? // a[i] is divisible by 2, 3, 4, ..., i+2 for(int i=0; i < n && i<lcms.length; i++) { if(a[i] % lcms[i] == 0) { ans = false; return; } } ans = true; } int[] lcms; void precalculate(){ long MAX = 1_000_000_000; ArrayList<Long> lcms = new ArrayList<>(); long lcm = 1; for(int i=0; ; i++) { lcm = this.lcm(lcm, i+2); if(lcm < MAX) lcms.add(lcm); else break; } this.lcms = new int[lcms.size()]; for(int i=0; i<lcms.size(); i++) this.lcms[i] = lcms.get(i).intValue(); } static long lcm(long a, long b) { return a/gcd(a, b)*b; } static long gcd(long a, long b){ if(a < b){ long temp = b; b = a; a = temp; } // a > b while (b > 0) { long r = a % b; a = b; b = r; } return a; } // Optional<T> solve() // return Optional.empty(); static class Pair implements Comparable<Pair>{ final static long FIXED_RANDOM = System.currentTimeMillis(); int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public int hashCode() { // http://xorshift.di.unimi.it/splitmix64.c long x = first; x <<= 32; x += second; x += FIXED_RANDOM; x += 0x9e3779b97f4a7c15l; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l; x = (x ^ (x >> 27)) * 0x94d049bb133111ebl; return (int)(x ^ (x >> 31)); } @Override public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; Pair other = (Pair) obj; return first == other.first && second == other.second; } @Override public String toString() { return "[" + first + "," + second + "]"; } @Override public int compareTo(Pair o) { int cmp = Integer.compare(first, o.first); return cmp != 0? cmp: Integer.compare(second, o.second); } } public static class MyScanner { BufferedReader br; StringTokenizer st; // 32768? public MyScanner(InputStream is, int bufferSize) { br = new BufferedReader(new InputStreamReader(is), bufferSize); } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); // br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[][] nextMatrix(int n, int m) { return nextMatrix(n, m, 0); } int[][] nextMatrix(int n, int m, int offset) { int[][] mat = new int[n][m]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[i][j] = nextInt()+offset; } } return mat; } int[][] nextTransposedMatrix(int n, int m){ return nextTransposedMatrix(n, m, 0); } int[][] nextTransposedMatrix(int n, int m, int offset){ int[][] mat = new int[m][n]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[j][i] = nextInt()+offset; } } return mat; } int[] nextIntArray(int len) { return nextIntArray(len, 0); } int[] nextIntArray(int len, int offset){ int[] a = new int[len]; for(int j=0; j<len; j++) a[j] = nextInt()+offset; return a; } long[] nextLongArray(int len) { return nextLongArray(len, 0); } long[] nextLongArray(int len, int offset){ long[] a = new long[len]; for(int j=0; j<len; j++) a[j] = nextLong()+offset; return a; } String[] nextStringArray(int len) { String[] s = new String[len]; for(int i=0; i<len; i++) s[i] = next(); return s; } } public static class MyPrintWriter extends PrintWriter{ public MyPrintWriter(OutputStream os) { super(os); } // public <T> void printlnAns(Optional<T> ans) { // if(ans.isEmpty()) // println(-1); // else // printlnAns(ans.get()); // } public void printlnAns(OptionalInt ans) { println(ans.orElse(-1)); } public void printlnAns(long ans) { println(ans); } public void printlnAns(int ans) { println(ans); } public void printlnAns(boolean[] ans) { for(boolean b: ans) printlnAns(b); } public void printlnAns(boolean ans) { if(ans) println(YES); else println(NO); } public void printAns(long[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(long[] arr){ printAns(arr); println(); } public void printAns(int[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(int[] arr){ printAns(arr); println(); } public <T> void printAns(ArrayList<T> arr){ if(arr != null && arr.size() > 0){ print(arr.get(0)); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)); } } } public <T> void printlnAns(ArrayList<T> arr){ printAns(arr); println(); } public void printAns(int[] arr, int add){ if(arr != null && arr.length > 0){ print(arr[0]+add); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]+add); } } } public void printlnAns(int[] arr, int add){ printAns(arr, add); println(); } public void printAns(ArrayList<Integer> arr, int add) { if(arr != null && arr.size() > 0){ print(arr.get(0)+add); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)+add); } } } public void printlnAns(ArrayList<Integer> arr, int add){ printAns(arr, add); println(); } public void printlnAnsSplit(long[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public void printlnAnsSplit(int[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public <T> void printlnAnsSplit(ArrayList<T> arr, int split){ if(arr != null && !arr.isEmpty()){ for(int i=0; i<arr.size(); i+=split){ print(arr.get(i)); for(int j=i+1; j<i+split; j++){ print(" "); print(arr.get(j)); } println(); } } } } static private void permutateAndSort(long[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); long temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private void permutateAndSort(int[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); int temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private int[][] constructChildren(int n, int[] parent, int parentRoot){ int[][] childrens = new int[n][]; int[] numChildren = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) numChildren[parent[i]]++; } for(int i=0; i<n; i++) { childrens[i] = new int[numChildren[i]]; } int[] idx = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) childrens[parent[i]][idx[parent[i]]++] = i; } return childrens; } static private int[][][] constructDirectedNeighborhood(int n, int[][] e){ int[] inDegree = new int[n]; int[] outDegree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outDegree[u]++; inDegree[v]++; } int[][] inNeighbors = new int[n][]; int[][] outNeighbors = new int[n][]; for(int i=0; i<n; i++) { inNeighbors[i] = new int[inDegree[i]]; outNeighbors[i] = new int[outDegree[i]]; } for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outNeighbors[u][--outDegree[u]] = v; inNeighbors[v][--inDegree[v]] = u; } return new int[][][] {inNeighbors, outNeighbors}; } static private int[][] constructNeighborhood(int n, int[][] e) { int[] degree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; degree[u]++; degree[v]++; } int[][] neighbors = new int[n][]; for(int i=0; i<n; i++) neighbors[i] = new int[degree[i]]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; neighbors[u][--degree[u]] = v; neighbors[v][--degree[v]] = u; } return neighbors; } static private void drawGraph(int[][] e) { makeDotUndirected(e); try { final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot") .redirectOutput(new File("graph.png")) .start(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } static private void makeDotUndirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict graph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "--" + e[i][1] + ";"); } out2.println("}"); out2.close(); } static private void makeDotDirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict digraph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "->" + e[i][1] + ";"); } out2.println("}"); out2.close(); } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
7d1d15b10c6438cae89ca5ed889c13fa
train_110.jsonl
1635604500
YouKn0wWho has an integer sequence $$$a_1, a_2, \ldots, a_n$$$. He will perform the following operation until the sequence becomes empty: select an index $$$i$$$ such that $$$1 \le i \le |a|$$$ and $$$a_i$$$ is not divisible by $$$(i + 1)$$$, and erase this element from the sequence. Here $$$|a|$$$ is the length of sequence $$$a$$$ at the moment of operation. Note that the sequence $$$a$$$ changes and the next operation is performed on this changed sequence.For example, if $$$a=[3,5,4,5]$$$, then he can select $$$i = 2$$$, because $$$a_2 = 5$$$ is not divisible by $$$i+1 = 3$$$. After this operation the sequence is $$$[3,4,5]$$$.Help YouKn0wWho determine if it is possible to erase the whole sequence using the aforementioned operation.
256 megabytes
import java.lang.reflect.Array; import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static FastReader cin; public static PrintWriter out; public static void main(String[] args) throws Exception { out = new PrintWriter(new BufferedOutputStream(System.out)); cin = new FastReader(); long [] T = new long [20]; T[0] = 1; for(int i = 1 ; i < 20 ; i++){ T[i] = T[i-1]*i; // out.printf("T[%d]=%d\n",i,T[i]); } int qq = cin.nextInt(); // int qq = 1; label:while (qq-- > 0) { int n = cin.nextInt(); ArrayList<Integer>list = new ArrayList<>(); list.add(0); for(int i = 0 ; i< n ; i++){ int t = cin.nextInt(); list.add(t); } for(int i = 1 ; i <= n ; i++){ int now = list.get(i); boolean flag = false; for(int j = 2 ; j <= i + 1 ;j++){ if(now%j!=0){ flag = true; break; } } if(flag == false){ out.println("NO"); continue label; } } out.println("YES"); continue label; } out.close(); } static class FastReader { BufferedReader br; StringTokenizer str; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (str == null || !str.hasMoreElements()) { try { str = new StringTokenizer(br.readLine()); } catch (IOException lastMonthOfVacation) { lastMonthOfVacation.printStackTrace(); } } return str.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException lastMonthOfVacation) { lastMonthOfVacation.printStackTrace(); } return str; } } }
Java
["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696"]
1 second
["YES\nNO\nYES\nYES\nNO"]
NoteIn the first test case, YouKn0wWho can perform the following operations (the erased elements are underlined): $$$[1, \underline{2}, 3] \rightarrow [\underline{1}, 3] \rightarrow [\underline{3}] \rightarrow [\,].$$$In the second test case, it is impossible to erase the sequence as $$$i$$$ can only be $$$1$$$, and when $$$i=1$$$, $$$a_1 = 2$$$ is divisible by $$$i + 1 = 2$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
080f29d4e2aa5bb9ee26d882362c8cd7
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$)  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.
1,300
For each test case, print "YES" (without quotes) if it is possible to erase the whole sequence using the aforementioned operation, print "NO" (without quotes) otherwise. You can print each letter in any register (upper or lower).
standard output
PASSED
9aa055ba0ec84ae291b6565f35024ff8
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
// package TLEEleminators; import java.io.*; import java.util.*; public class day1 { static FastReader scn = new FastReader(); static FastWriter syso = new FastWriter(); public static void main(String[] args)throws Exception { // solve(); // solve1(); // solve_02(); solve_03(); syso.close(); } static void solve_03()throws Exception{ int t=scn.nextInt(); long mm=(long)1e18+7; while(t-->0){ long x=scn.nextLong(); long y=scn.nextLong(); if(x>y){ syso.println(((x*2)%mm+y)%mm); } else if(y>x){ if(y%x==0)syso.println(x); else{ long num=y-(y%x)/2; syso.println(num); } } else if(x==y){ syso.println(x); } } } static void solve_02()throws Exception{ int n=scn.nextInt(); // number of derangements =Dn=n!∑k=0n(−1)kk! long[]dp=new long[n+1]; dp[0]=dp[1]=1; for(int i=2;i<=n;i++) { dp[i]=(dp[i-1]*i)%mod; } long ans=0; for(int i=0;i<=n;i++) { if(i%2==0){ ans= (ans+(dp[n]*power(dp[i],mod-2,mod))%mod)%mod; } else{ ans= (ans%mod-(dp[n]*power(dp[i],mod-2,mod))%mod+mod)%mod; } } syso.println(ans); } static int[]arr; static int mod=(int)1e9+7; //https://cses.fi/problemset/result/4478131/ static void solve()throws Exception { int n=scn.nextInt(); arr=new int[(int)1e6+1]; for(int i=0;i<n;i++){ int num=scn.nextInt(); arr[num]++; } for(int i=(int)1e6;i>=0;i--){ int count=0; for(int j=i;j<=(int)1e6;j+=i){ count+=arr[j]; if(count>=2){ syso.println(i); return; } } // } } } static void solve1() throws Exception{ int n=scn.nextInt(); int[][]arr=new int[n][2]; long numDvs=1,sumDvs=1; long num=1; for(int i=0;i<n;i++){ arr[i][0]=scn.nextInt(); arr[i][1]=scn.nextInt(); numDvs=(numDvs*(arr[i][1]+1))%mod; num=(num*power(arr[i][0],arr[i][1],mod))%mod; sumDvs=(sumDvs*((((power(arr[i][0],arr[i][1]+1,mod)-1)%mod)*power((arr[i][0]-1),mod-2,mod))%mod)%mod)%mod; // sumDvs=(sumDvs* ((power(arr[i][0],arr[i][1]+1,mod)-1)%mod*B-1%mod)%mod )%mod; } long ans=1; // syso.println(num); for(long i=2;(i*i)%mod<=num;i++){ if(num%i==0){ ans=(ans*i)%mod; } if((num/i)!=i){ ans=(ans*(num/i))%mod; } } syso.print(numDvs+" "+sumDvs+" "+(ans*num)%mod); } // static long power(long a,long b){ // if(b==0)return 1; // long res=power(a,b/2); // if((b&1)!=0){ // return (a*(res*res)%mod)%mod; // } // else{ // return (res*res)%mod; // } // } static long power(long x, long y, int p) { // Initialize result long res = 1; // Update x if it is more // than or equal to p x = x % p; while (y > 0) { // If y is odd, multiply x // with result if (y % 2 != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } //Io static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output
PASSED
204058d3c5f9f87e8517c887a725a941
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } static FastReader sc = new FastReader(); static OutputStream outputStream = System.out; static PrintWriter out = new PrintWriter(outputStream); final static long mod = 1000000007; static class IntPair { int v1, v2; IntPair(int v1, int v2) { this.v1 = v1; this.v2 = v2; } } static class LongPair { long v1, v2; LongPair(long v1, long v2) { this.v1 = v1; this.v2 = v2; } } private static void printl(long []arr) { for(long a : arr) out.print(a + " "); out.println(); } private static void printl(int []arr) { for(int a : arr) out.print(a + " "); out.println(); } private static void print(long a) { out.print(a); } private static void printl(long a) { out.println(a); } private static void printl(char ch) { out.println(ch); } private static void print(char ch) { out.print(ch); } private static void printl(String s) { out.println(s); } private static void print(String s) { out.print(s); } private static int[] intArray(int n) { int arr[] = new int[n]; for(int i = 0; i < n; i++) arr[i] = sc.nextInt(); return arr; } private static long[] longArray(int n) { long arr[] = new long[n]; for(int i = 0; i < n; i++) arr[i] = sc.nextLong(); return arr; } private static double[] doubleArray(int n) { double arr[] = new double[n]; for(int i = 0; i < n; i++) arr[i] = sc.nextDouble(); return arr; } private static int[][] intMatrix(int n, int m) { int mat[][] = new int[n][m]; for(int i = 0; i < mat.length; i++) for(int j = 0; j < mat[0].length; j++) mat[i][j] = sc.nextInt(); return mat; } private static long[][] longMatrix(int n, int m) { long mat[][] = new long[n][m]; for(int i = 0; i < mat.length; i++) for(int j = 0; j < mat[0].length; j++) mat[i][j] = sc.nextLong(); return mat; } private static int intgr() { int x = sc.nextInt(); return x; } private static long lng() { long x = sc.nextLong(); return x; } private static double dbl() { double x = sc.nextDouble(); return x; } private static String str() { String s = sc.next(); return s; } private static char chr() { char ch = sc.next().charAt(0); return ch; } //if gcd(a, b) = 1 then a and b are said to be coprime //gcd(a, 0) == a //gcd(a, 1) == 1 //gcd(a, a) = a //gcd(a, b) = gcd(a - b, b) //gcd(a, b) = gcd(a % b, a) //gcd(m ⋅ a, m ⋅ b) = m ⋅ gcd(a, b) (m > 0) // gcd(a,b) = g, then a/g and b/g should be coprime //gcd(a, b) = gcd(a+(m*b), b) //gcd(a, b) = gcd(b, a % b) private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcdL(long a, long b) { if (b == 0) return a; return gcdL(b, a % b); } private static long lcmL(long a, long b) { return ((a * b) / gcdL(a, b)); } private static int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } private static List<Integer> getDivisors(int n) { List<Integer> ls = new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) if (n % i == 0) { ls.add(i); if (n / i != i) ls.add(n / i); } return ls; } private static List<Long> getDivisors(long n) { List<Long> ls = new ArrayList<>(); for (long i = 1; i <= Math.sqrt(n); i++) if (n % i == 0) { ls.add(i); if (n / i != i) ls.add(n / i); } return ls; } private static List<Integer> primeFactors(int n) { List<Integer> ls = new ArrayList<>(); int c = 2; while (n > 1) { if (n % c == 0) { ls.add(c); n /= c; } else c++; } return ls; } private static long fact(int x) { if(x == 0 || x == 1) return 1; return x * fact(x - 1); } private static long powMod(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } private static long pow(long a, long b) { long res = 1; while(b > 0) { if((b & 1) == 1) res = (res * a) % mod; a = (a * a) % mod; b = b >> 1; } return res; } private static boolean[] sieve(int n) { boolean prime[] = new boolean[n + 1]; Arrays.fill(prime, true); for (int p = 2; p * p <= n; p++) if (prime[p] == true) for (int i = p * p; i <= n; i += p) prime[i] = false; return prime; } private static boolean isPrime(int n) { if (n == 2 || n == 3) return true; if (n <= 1 || n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i <= Math.sqrt(n); i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long findGCD(long arr[], int n) { long result = arr[0]; for (long element: arr) { result = gcdL(result, element); if(result == 1) return 1; } return result; } private static void sort(int []a) { Arrays.sort(a); } private static void sort(long []a) { Arrays.sort(a); } private static int max(int a, int b) { return Math.max(a, b); } private static int min(int a, int b) { return Math.max(a, b); } private static long max(long a, long b) { return Math.max(a, b); } private static long min(int a, long b) { return Math.max(a, b); } public static void main(String[] args) { long tc = lng(); while(tc-- > 0) { long x = lng(), y = lng(); if(x == y) printl(x); else if(x > y) printl(x + y); else printl(y - (y % x) / 2); } out.close(); } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output
PASSED
fa37739a070d864a7d3c19690b9baadc
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
import java.io.*; import java.text.*; import java.util.*; /** * Provide prove of correctness before implementation. Implementation can cost a lot of time. * Anti test that prove that it's wrong. * <p> * Do not confuse i j k g indexes, upTo and length. Do extra methods!!! Write more informative names to simulation * <p> * Will program ever exceed limit? * Try all approaches with prove of correctness if task is not obvious. * If you are given formula/rule: Try to play with it. * Analytic solution/Hardcoded solution/Constructive/Greedy/DP/Math/Brute force/Symmetric data * Number theory * Game theory (optimal play) that consider local and global strategy. * Start writing the hardest code first */ public class Stage1_9 { final boolean ONLINE_JUDGE = java.lang.System.getProperty("ONLINE_JUDGE") != null; final boolean ANTI_TEST_FINDER_MODE = false; final Random random = new Random(42); private int solveOne(int testCase) { long x = nextLong(), y = nextLong(); assertThat(x % 2 == 0); assertThat(y % 2 == 0); long n; if (y % x == 0) { n = x; } else if (y < x) { n = x + y; } else { n = y - ((y % x) >>> 1); } assertThat(n % x == y % n, String.format("%d mod %d == %d mod %d, %d != %d", n, x, y, n, n % x, y % n)); System.out.println(n); return 0; } private int solveOneNaive(int testCase) { return 0; } private void solve() { if (ANTI_TEST_FINDER_MODE) { int t = 100_000; for (int testCase = 0; testCase < t; testCase++) { int expected = solveOneNaive(testCase); int actual = solveOne(testCase); if (expected != actual) { throw new AssertionRuntimeException( this.getClass().getSimpleName(), testCase, expected, actual); } } } else { int t = nextInt(); for (int testCase = 0; testCase < t; testCase++) { solveOne(testCase); } } } class AssertionRuntimeException extends RuntimeException { AssertionRuntimeException(String testName, int testCase, Object expected, Object actual, Object... input) { super("Testcase: " + testCase + "\n expected = " + expected + ",\n actual = " + actual + ",\n " + Arrays.deepToString(input)); } } private void assertThat(boolean b) { if (!b) throw new RuntimeException(); } private void assertThat(boolean b, String s) { if (!b) throw new RuntimeException(s); } private int assertThatInt(long a) { assertThat(Integer.MIN_VALUE <= a && a <= Integer.MAX_VALUE, "Integer overflow long = [" + a + "]" + " int = [" + (int) a + "]"); return (int) a; } void _______debug(String str, Object... os) { if (!ONLINE_JUDGE) { System.out.println(MessageFormat.format(str, os)); System.out.flush(); } } void _______debug(Object o) { if (!ONLINE_JUDGE) { _______debug("{0}", String.valueOf(o)); } } private int nextInt() { return System.in.readInt(); } private long nextLong() { return System.in.readLong(); } private String nextString() { return System.in.readString(); } private int[] nextIntArr(int n) { return System.in.readIntArray(n); } private long[] nextLongArr(int n) { return System.in.readLongArray(n); } public static void main(String[] args) { new Stage1_9().run(); } static class System { private static FastInputStream in; private static FastPrintStream out; } private void run() { // final long startTime = java.lang.System.currentTimeMillis(); final boolean USE_IO = ONLINE_JUDGE; if (USE_IO) { System.in = new FastInputStream(java.lang.System.in); System.out = new FastPrintStream(java.lang.System.out); solve(); System.out.flush(); } else { final String nameIn = "input.txt"; final String nameOut = "output.txt"; try { System.in = new FastInputStream(new FileInputStream(nameIn)); System.out = new FastPrintStream(new PrintStream(nameOut)); solve(); System.out.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } } // final long endTime = java.lang.System.currentTimeMillis(); // _______debug("Execution time: {0}", endTime - startTime); } private static class FastPrintStream { private static final int BUF_SIZE = 8192; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastPrintStream() { this(java.lang.System.out); } public FastPrintStream(OutputStream os) { this.out = os; } public FastPrintStream(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastPrintStream print(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerFlush(); return this; } public FastPrintStream print(char c) { return print((byte) c); } public FastPrintStream print(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerFlush(); } return this; } public FastPrintStream print(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerFlush(); }); return this; } //can be optimized public FastPrintStream print0(char[] s) { if (ptr + s.length < BUF_SIZE) { for (char c : s) { buf[ptr++] = (byte) c; } } else { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerFlush(); } } return this; } //can be optimized public FastPrintStream print0(String s) { if (ptr + s.length() < BUF_SIZE) { for (int i = 0; i < s.length(); i++) { buf[ptr++] = (byte) s.charAt(i); } } else { for (int i = 0; i < s.length(); i++) { buf[ptr++] = (byte) s.charAt(i); if (ptr == BUF_SIZE) innerFlush(); } } return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastPrintStream print(int x) { if (x == Integer.MIN_VALUE) { return print((long) x); } if (ptr + 12 >= BUF_SIZE) innerFlush(); if (x < 0) { print((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastPrintStream print(long x) { if (x == Long.MIN_VALUE) { return print("" + x); } if (ptr + 21 >= BUF_SIZE) innerFlush(); if (x < 0) { print((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastPrintStream print(double x, int precision) { if (x < 0) { print('-'); x = -x; } x += Math.pow(10, -precision) / 2; print((long) x).print("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; print((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastPrintStream println(char c) { return print(c).println(); } public FastPrintStream println(int x) { return print(x).println(); } public FastPrintStream println(long x) { return print(x).println(); } public FastPrintStream println(String x) { return print(x).println(); } public FastPrintStream println(Object x) { return print(x.toString()).println(); } public FastPrintStream println(double x, int precision) { return print(x, precision).println(); } public FastPrintStream println() { return print((byte) '\n'); } public FastPrintStream printf(String format, Object... args) { return print(String.format(format, args)); } private void innerFlush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerFlush"); } } public void flush() { innerFlush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } } private static class FastInputStream { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastInputStream(InputStream stream) { this.stream = stream; } public double[] readDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = readDouble(); } return array; } public String[] readStringArray(int size) { String[] array = new String[size]; for (int i = 0; i < size; i++) { array[i] = readString(); } return array; } public char[] readCharArray(int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) { array[i] = readCharacter(); } return array; } public String readText() { StringBuilder result = new StringBuilder(); while (true) { int character = read(); if (character == '\r') { continue; } if (character == -1) { break; } result.append((char) character); } return result.toString(); } public long[] readLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = readLong(); } return array; } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = readInt(); } return array; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int peekNonWhitespace() { while (isWhitespace(peek())) { read(); } return peek(); } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public char[] readStringAsCharArray() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); char[] resArr = new char[res.length()]; res.getChars(0, res.length(), resArr, 0); return resArr; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return readString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output
PASSED
4cc7a6086bb7e1e64bedbebc72bfe92b
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Solution { public static void main(String[] args) { Kattio kattio = new Kattio(); int t = kattio.nextInt(); while (t > 0) { solve(kattio); t--; } // solve(kattio); kattio.close(); } static int[] dirs = new int[]{0, 1, 0, -1, 0}; static List<Integer> primes; static int[] primeFactor; static int[] preSum; public static void solve(Kattio kattio) { int x = kattio.nextInt(); int y = kattio.nextInt(); if (x == y) { kattio.println(x); } else if (x > y) { kattio.println(x + y); } else { kattio.println(y - (y % x) / 2); } } public static int[] getPrimeFactorPreSum() { int n = primeFactor.length; int[] count = new int[n]; for (int i = 2; i < n; i++) { if (primeFactor[i] == i) { count[i] = 1; } else { count[i] = 1 + count[i / primeFactor[i]]; } } // for (int i = 2; i < n; i++) { // int cur = i; // while (cur != primeFactor[cur]) { // cur = cur / primeFactor[cur]; // count[i]++; // } // count[i]++; // } preSum = new int[n]; for (int i = 1; i < n; i++) { preSum[i] = preSum[i - 1] + count[i]; } return preSum; } public static int[] getPrimeFactor(int max) { int[] res = new int[max + 1]; for (int i = 2; i <= max; i++) { if (res[i] != 0) { continue; } for (int j = 1; j * i <= max; j++) { res[j * i] = i; } } return res; } public static List<Integer> getPrime(int max) { boolean[] notP = new boolean[max + 1]; List<Integer> res = new ArrayList<>(); for (int i = 2; i <= max; i++) { if (notP[i]) { continue; } res.add(i); for (int j = 1; j * i <= max; j++) { notP[j * i] = true; } } return res; } public static int countFactors(int num) { int res = 0; for (Integer prime : primes) { if (prime * prime > num) { break; } while (num % prime == 0) { num /= prime; res++; } } if (num > 1) { res++; } return res; } public static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static String toBinary(int num) { return String.format("%16s", Integer.toBinaryString(num)).replace(" ", "0"); } static class Kattio extends PrintWriter { BufferedReader r; StringTokenizer st; // 标准 IO Kattio() { this(System.in, System.out); } Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // 文件 IO Kattio(String input, String output) throws IOException { super(output); r = new BufferedReader(new FileReader(input)); } // 在没有其他输入时返回 null public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(r.readLine()); } return st.nextToken(); } catch (IOException e) { e.printStackTrace(); } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output
PASSED
d143feb62cf555b6d10204b3fcd9c5d8
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
import java.util.*; import java.util.function.*; import java.io.*; // you can compare with output.txt and expected out public class Round752Div1B { MyPrintWriter out; MyScanner in; // final static long FIXED_RANDOM; // static { // FIXED_RANDOM = System.currentTimeMillis(); // } final static String IMPOSSIBLE = "IMPOSSIBLE"; final static String POSSIBLE = "POSSIBLE"; final static String YES = "YES"; final static String NO = "NO"; private void initIO(boolean isFileIO) { if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) { try{ in = new MyScanner(new FileInputStream("input.txt")); out = new MyPrintWriter(new FileOutputStream("output.txt")); } catch(FileNotFoundException e){ e.printStackTrace(); } } else{ in = new MyScanner(System.in); out = new MyPrintWriter(new BufferedOutputStream(System.out)); } } public static void main(String[] args){ // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); // the code for the deep recursion (more than 100k or 3~400k or so) // Thread t = new Thread(null, new RoundEdu130F(), "threadName", 1<<28); // t.start(); // t.join(); Round752Div1B sol = new Round752Div1B(); sol.run(); } private void run() { boolean isDebug = false; boolean isFileIO = true; boolean hasMultipleTests = true; initIO(isFileIO); int t = hasMultipleTests? in.nextInt() : 1; for (int i = 1; i <= t; ++i) { if(isDebug){ out.printf("Test %d\n", i); } getInput(); solve(); printOutput(); } in.close(); out.close(); } // use suitable one between matrix(2, n), matrix(n, 2), transposedMatrix(2, n) for graph edges, pairs, ... long x, y; void getInput() { x = in.nextInt(); y = in.nextInt(); } void printOutput() { out.printlnAns(ans); } long ans; void solve(){ // x, y even // find n s.t. n % x = y % n // if x | y then make n = x // n % x = 0, y % x = 0 // y = xk + r // n % x = (xk + r) % n // (xk + r/2) % x = r/2 // (xk + r) % (xk + r/2) = r/2 if(y > x) { long r = y % x; ans = y - r/2; } else if(y == x) { ans = x; } else { // y < x // n % x = y % n // (x + y) % x = y % (x + y) ans = x + y; } } // Optional<T> solve() // return Optional.empty(); static class Pair implements Comparable<Pair>{ final static long FIXED_RANDOM = System.currentTimeMillis(); int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public int hashCode() { // http://xorshift.di.unimi.it/splitmix64.c long x = first; x <<= 32; x += second; x += FIXED_RANDOM; x += 0x9e3779b97f4a7c15l; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l; x = (x ^ (x >> 27)) * 0x94d049bb133111ebl; return (int)(x ^ (x >> 31)); } @Override public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; Pair other = (Pair) obj; return first == other.first && second == other.second; } @Override public String toString() { return "[" + first + "," + second + "]"; } @Override public int compareTo(Pair o) { int cmp = Integer.compare(first, o.first); return cmp != 0? cmp: Integer.compare(second, o.second); } } public static class MyScanner { BufferedReader br; StringTokenizer st; // 32768? public MyScanner(InputStream is, int bufferSize) { br = new BufferedReader(new InputStreamReader(is), bufferSize); } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); // br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[][] nextMatrix(int n, int m) { return nextMatrix(n, m, 0); } int[][] nextMatrix(int n, int m, int offset) { int[][] mat = new int[n][m]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[i][j] = nextInt()+offset; } } return mat; } int[][] nextTransposedMatrix(int n, int m){ return nextTransposedMatrix(n, m, 0); } int[][] nextTransposedMatrix(int n, int m, int offset){ int[][] mat = new int[m][n]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[j][i] = nextInt()+offset; } } return mat; } int[] nextIntArray(int len) { return nextIntArray(len, 0); } int[] nextIntArray(int len, int offset){ int[] a = new int[len]; for(int j=0; j<len; j++) a[j] = nextInt()+offset; return a; } long[] nextLongArray(int len) { return nextLongArray(len, 0); } long[] nextLongArray(int len, int offset){ long[] a = new long[len]; for(int j=0; j<len; j++) a[j] = nextLong()+offset; return a; } String[] nextStringArray(int len) { String[] s = new String[len]; for(int i=0; i<len; i++) s[i] = next(); return s; } } public static class MyPrintWriter extends PrintWriter{ public MyPrintWriter(OutputStream os) { super(os); } // public <T> void printlnAns(Optional<T> ans) { // if(ans.isEmpty()) // println(-1); // else // printlnAns(ans.get()); // } public void printlnAns(OptionalInt ans) { println(ans.orElse(-1)); } public void printlnAns(long ans) { println(ans); } public void printlnAns(int ans) { println(ans); } public void printlnAns(boolean[] ans) { for(boolean b: ans) printlnAns(b); } public void printlnAns(boolean ans) { if(ans) println(YES); else println(NO); } public void printAns(long[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(long[] arr){ printAns(arr); println(); } public void printAns(int[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(int[] arr){ printAns(arr); println(); } public <T> void printAns(ArrayList<T> arr){ if(arr != null && arr.size() > 0){ print(arr.get(0)); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)); } } } public <T> void printlnAns(ArrayList<T> arr){ printAns(arr); println(); } public void printAns(int[] arr, int add){ if(arr != null && arr.length > 0){ print(arr[0]+add); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]+add); } } } public void printlnAns(int[] arr, int add){ printAns(arr, add); println(); } public void printAns(ArrayList<Integer> arr, int add) { if(arr != null && arr.size() > 0){ print(arr.get(0)+add); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)+add); } } } public void printlnAns(ArrayList<Integer> arr, int add){ printAns(arr, add); println(); } public void printlnAnsSplit(long[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public void printlnAnsSplit(int[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public <T> void printlnAnsSplit(ArrayList<T> arr, int split){ if(arr != null && !arr.isEmpty()){ for(int i=0; i<arr.size(); i+=split){ print(arr.get(i)); for(int j=i+1; j<i+split; j++){ print(" "); print(arr.get(j)); } println(); } } } } static private void permutateAndSort(long[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); long temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private void permutateAndSort(int[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); int temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private int[][] constructChildren(int n, int[] parent, int parentRoot){ int[][] childrens = new int[n][]; int[] numChildren = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) numChildren[parent[i]]++; } for(int i=0; i<n; i++) { childrens[i] = new int[numChildren[i]]; } int[] idx = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) childrens[parent[i]][idx[parent[i]]++] = i; } return childrens; } static private int[][][] constructDirectedNeighborhood(int n, int[][] e){ int[] inDegree = new int[n]; int[] outDegree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outDegree[u]++; inDegree[v]++; } int[][] inNeighbors = new int[n][]; int[][] outNeighbors = new int[n][]; for(int i=0; i<n; i++) { inNeighbors[i] = new int[inDegree[i]]; outNeighbors[i] = new int[outDegree[i]]; } for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outNeighbors[u][--outDegree[u]] = v; inNeighbors[v][--inDegree[v]] = u; } return new int[][][] {inNeighbors, outNeighbors}; } static private int[][] constructNeighborhood(int n, int[][] e) { int[] degree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; degree[u]++; degree[v]++; } int[][] neighbors = new int[n][]; for(int i=0; i<n; i++) neighbors[i] = new int[degree[i]]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; neighbors[u][--degree[u]] = v; neighbors[v][--degree[v]] = u; } return neighbors; } static private void drawGraph(int[][] e) { makeDotUndirected(e); try { final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot") .redirectOutput(new File("graph.png")) .start(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } static private void makeDotUndirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict graph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "--" + e[i][1] + ";"); } out2.println("}"); out2.close(); } static private void makeDotDirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict digraph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "->" + e[i][1] + ";"); } out2.println("}"); out2.close(); } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 17
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output
PASSED
6a5bb88a522c40b87044133bad78d426
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
import java.util.*; public class ModerateModularMode { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for (long i=0;i<t;i++) { long a = sc.nextLong(), b = sc.nextLong(); if (b >= a) { System.out.println(b-(b%a)/2); } else System.out.println(a+b); } } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output
PASSED
d8da1c0094cb1c45bd86ae6bb91933e8
train_110.jsonl
1635604500
YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
256 megabytes
import java.io.*; import java.util.*; public class ModerateModularMode { private static final int START_TEST_CASE = 1; public static void solveCase(FastIO io, int testCase) { final long X = io.nextLong(); final long Y = io.nextLong(); if (X > Y) { io.println(X + Y); } else { io.println(Y - (Y % X) / 2); } } public static void solve(FastIO io) { final int T = io.nextInt(); for (int t = 0; t < T; ++t) { solveCase(io, START_TEST_CASE + t); } } public static class FastIO { private InputStream reader; private PrintWriter writer; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastIO(InputStream r, OutputStream w) { reader = r; writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(w))); } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = reader.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } // TODO: read this byte-by-byte like the other read functions. public double nextDouble() { return Double.parseDouble(nextString()); } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void printArray(int[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printArray(long[] arr) { for (int i = 0; i < arr.length; i++) { if (i != 0) { writer.print(' '); } writer.print(arr[i]); } } public void printlnArray(int[] arr) { printArray(arr); writer.println(); } public void printlnArray(long[] arr) { printArray(arr); writer.println(); } public void printf(String format, Object... args) { print(String.format(format, args)); } public void flush() { writer.flush(); } } public static void main(String[] args) { FastIO io = new FastIO(System.in, System.out); solve(io); io.flush(); } }
Java
["4\n4 8\n4 2\n420 420\n69420 42068"]
1 second
["4\n10\n420\n9969128"]
NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.
Java 8
standard input
[ "constructive algorithms", "math", "number theory" ]
a24aac9152417527d43b9b422e3d2303
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).
1,600
For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.
standard output