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
09d7665f2ffe8116d83978ab68c56d27
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.lang.*; // import java.math.*; import java.io.*; import java.util.*; public class Main{ public static int mod=(int)(1e9) + 7; public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public static PrintWriter ot=new PrintWriter(System.out); public static int[] take_arr(int n){ int a[]=new int[n]; try { String s[]=br.readLine().trim().split(" "); for(int i=0;i<n;i++) a[i]=Integer.parseInt(s[i]); } catch (Exception e) { e.printStackTrace(); } return a; } public static void main (String[] args) throws java.lang.Exception { try{ int t=Integer.parseInt(br.readLine().trim()); int cno=1; pre(); while(t-->0){ String s[]=br.readLine().trim().split(" "); int n=Integer.parseInt(s[0]); int m=Integer.parseInt(s[1]); // int k=Integer.parseInt(s[2]); // int a[]=take_arr(n); // int b[]=take_arr(n); // char ch[]=br.readLine().trim().toCharArray(); // long n=Long.parseLong(s[0]); solve(n,m); } ot.close(); br.close(); }catch(Exception e){ e.printStackTrace(); return; } } static void solve(int n, int m){ try{ ot.println(dp[n][m]); } catch(Exception e){ e.printStackTrace(); return ; } } static void pre(){ dp=new Integer[51][51]; boolean visited[][]=new boolean[51][51]; Queue<int[]> q=new LinkedList<>(); q.add(new int[]{0,0}); visited[0][0]=true; int count=0; while(!q.isEmpty()){ int size=q.size(); for(int x=0;x<size;x++){ int Temp[]=q.poll(); int xx=Temp[0]; int yy=Temp[1]; dp[xx][yy]=count; for(int i=-50;i<=50;i++){ for(int j=-50;j<=50;j++){ int xi=xx+i; int xj=yy+j; if(xi<=50&&xj<=50&&xi>=0&&xj>=0){ double temp = (xi-xx)*(xi-xx)+(xj-yy)*(xj-yy); temp=Math.sqrt(temp); if((int)(temp)==temp&&!visited[xi][xj]){ q.add(new int[]{xi,xj}); visited[xi][xj]=true; } } } } } count++; } } static Integer dp[][]; }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
3c54259aba4a18f8634021185add3193
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
/* package codeforces; // don't place package name! */ // algo_messiah23 , NIT RKL ... import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import static java.lang.System.*; import java.util.stream.IntStream; import java.util.Map; import java.util.Map.Entry; /* Name of the class has to be "Main" only if the class is public. */ public class CodeForces { static PrintWriter out=new PrintWriter((System.out)); static FastReader in = new FastReader(); static int INF = Integer.MAX_VALUE; static int NINF = Integer.MIN_VALUE; public static void main (String[] args) throws java.lang.Exception { // your code goes here int t=i(); while(t-->0) { solve(); } out.close(); } public static void solve() { int x=i(); int y=i(); if(x==0 && y==0) out.println("0"); else if(x==0 || y==0) out.println(1); else { int k=x*x + y*y; if((double)Math.sqrt((double)k)%1==0) out.println(1); else out.println(2); } } static int[] input(int N){ int[] A=new int[N]; for(int i=0; i<N; i++) A[i]=in.nextInt(); return A; } public static void print(int[] arr){ int n = arr.length; for(int i = 0;i < n;i++){ out.print(arr[i] + " "); } out.println(); } public static void sort(int[] arr){ ArrayList<Integer> ls = new ArrayList<>(); for(int x : arr){ ls.add(x); } Collections.sort(ls); for(int i = 0;i < arr.length;i++){ arr[i] = ls.get(i); } } public static void reverse(int[] arr){ int n = arr.length; for(int i = 0;i < n/2;i++){ int temp = arr[i]; arr[i] = arr[n-1-i]; arr[n-1-i] = temp; } } public static void reverse(long[] arr){ int n = arr.length; for(int i = 0;i < n/2;i++){ long temp = arr[i]; arr[i] = arr[n-1-i]; arr[n-1-i] = temp; } } public static void print(ArrayList<Integer> arr){ int n = arr.size(); for(int i = 0;i < n;i++){ out.print(arr.get(i) + " "); } out.println(); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static char ich() { return in.next().charAt(0); } static String is() { return in.next(); } static String isl() { return in.nextLine(); } public static int max(int[] arr){ int max = -1; int n = arr.length; for(int i = 0;i < n;i++) max = Math.max(max,arr[i]); return max; } public static int min(int[] arr){ int min=INF; int n=arr.length; for(int i = 0;i< n;i++) min=Math.min(min,arr[i]); return min; } public static int gcd(int x, int y) { if (y==0){ return x; } return gcd(y,x%y); } } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
17a3162a397a3aca3401f15f83bf3a92
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
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 x = sc.nextInt(); int y = sc.nextInt(); int res = (x*x) + (y*y); int count = 0; if(x==0 && y == 0) System.out.println(0); else if((x==0 && y>0 )|| (y==0 && x>0)) System.out.println(1); else { for (int i = 1; i < x+y; i++) { if (res==i*i){ count = 1; break;} else count =2; } System.out.println(count); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
ea9d8cfbf23b020fe7eeea2370e3336a
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class IntegerMoves { public static int Dist(int x1 , int y1 , int x2 , int y2){ double ans = Math.pow(Math.pow(x2-x1,2) + Math.pow(y2-y1,2),0.5); int Ans = (int) ans; // System.out.println(Ans); if(Ans == 0){ return Ans; } if(ans%Ans == 0){ return Ans; } return -1; } public static int IntMoves(int x , int y){ if(Dist(0,0,x,y) == 0){ return 0; } else if(Dist(0,0,x,y)!=-1){ return 1; } return 2; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0 ; i < t ; i++){ int x = sc.nextInt(); int y = sc.nextInt(); System.out.println(IntMoves(x,y)); } // System.out.println(Dist(0,0,2,3)); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
6c6ec347c045f4317b8d85bc88921906
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class P03 { 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 class BPair { Integer index;boolean value; public BPair(Integer index, boolean value) {this.value =value;this.index =index;} int getIndex() {return index;} boolean getValue() {return value;} } static class Pair implements Comparable<Pair> { Integer index,value; public Pair(Integer index, Integer value) {this.value = value;this.index = index;} @Override public int compareTo(Pair o){return value - o.value;} int getValue(){ return value;} int getindex(){return index;} } private static long gcd(long l, long m){ if(m==0) {return l;} return gcd(m,l%m); } static void swap(long[] arr, int i, int j){long temp = arr[i];arr[i] = arr[j];arr[j] = temp;} static int partition(long[] arr, int low, int high){ long pivot = arr[high]; int i = (low - 1); for(int j = low; j <= high - 1; j++){ if (arr[j] < pivot){ i++; swap(arr, i, j); } } swap(arr, i + 1, high); return (i + 1); } static void quickSort(long[] arr, int low, int high){ if (low < high){ int pi = partition(arr, low, high); quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } static long M = 1000000007; static long powe(long a,long b) { long res =1; while(b>0){ if((b&1)!=0) { res=(res*a)&M; } a=(a*a)%M; b>>=1; } return res; } 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) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static boolean [] seive(int n) { boolean a[] = new boolean[n+1]; Arrays.fill(a, true); a[0]=false; a[1]=false; for(int i =2;i<=Math.sqrt(n);i++) { for(int j =2*i;j<=n;j+=i) { a[j]=false; } } return a; } private static void pa(char[] cs){for(int i =0;i<cs.length;i++){System.out.print(cs[i]+" ");}System.out.println();} private static void pa(long[] b){for(int i =0;i<b.length;i++) {System.out.print(b[i]+" ");}System.out.println();} private static void pm(Character[][] a){for(int i =0;i<a.length;i++){for(int j=0;j<a[i].length;j++){System.out.print(a[i][j]);}System.out.println();}} private static void pm(int [][] a) {for(int i =0;i<a.length;i++) {for(int j=0;j<a[0].length;j++) {System.out.print(a[i][j]+" ");}System.out.println();}} private static void pa(int[] a){for(int i =0;i<a.length;i++){System.out.print(a[i]+" ");}System.out.println();} private static boolean isprime(int n){if (n <= 1) return false;else if (n == 2) return true;else if (n % 2 == 0) return false;for (int i = 3; i <= Math.sqrt(n); i += 2){if (n % i == 0) return false;}return true;} static int lb(long[] b, long a){ int l=-1,r=b.length; while(l+1<r) { int m=(l+r)>>>1; if(b[m]>=a) r=m; else l=m; } return r; } static int ub(long a[], long 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 void rec(String digits,ArrayList<String> ans,String temp,int in ,HashMap<Integer,String>hm,int l){ if(temp.length()==l){ ans.add(temp); return ; } String s = hm.get(digits.charAt(in)-'0'); int n = s.length(); for(int i =0;i<n;i++){ rec(digits,ans,temp+s.charAt(i),in+1,hm,l); } } public static int longestCommonSubsequence(String text1, String text2) { int n = text1.length(); int m = text2.length(); int dp [][]= new int [n+1][m+1]; for(int i =0;i<=n;i++){ for(int j =0;j<=m;j++){ if(i==0||j==0)dp[i][j]=0; else if(text1.charAt(i-1)==text2.charAt(j-1)){ dp[i][j]=1+dp[i-1][j-1]; } else dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]); } } return dp[n][m]; } static //MAIN FUNCTION -------> ArrayList<String> alpos = new ArrayList<>(); public static void main(String[] args) throws IOException { long start2 = System.currentTimeMillis(); // FastReader fs = new FastReader(); Scanner fs = new Scanner (System.in); int t = fs.nextInt(); // int t =1; while(t-->0) { int x = fs.nextInt(); int y = fs.nextInt(); double ans = x*x + y*y ; if(x==0||y==0) { if(x==0&&y==0)System.out.println("0"); else System.out.println(1); } else if((int)Math.sqrt(ans)==Math.sqrt(ans)) { System.out.println(1); } else { System.out.println(2); } } long end2 = System.currentTimeMillis(); // System.out.println("time :"+(end2-start2)); // sc.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
9d358e7520add23e52e148d4cfd7ef37
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.lang.*; public class Main{ public static void main(String args[]){ Scanner inp=new Scanner(System.in); int t=inp.nextInt(); for(int i=0;i<t;i++){ int x2=inp.nextInt(); int y2=inp.nextInt(); if(x2==0 && y2==0){ System.out.println(0); continue; } else{ int n1=x2*x2; int n2=y2*y2; int n3=n1+n2; double sqrt=Math.sqrt(n3); int sqrt1=(int) sqrt; // System.out.println(sqrt-sqrt1); if(Math.abs(sqrt-sqrt1)==0){ System.out.println(1); continue; } else{ System.out.println(2); continue; } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
4e5f3f06e7c1f6e6da5c82500f776c7b
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class cf{ public static void main(String[] args ){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0; i<n;i++){ int x = sc.nextInt(); int y = sc.nextInt(); if(x+y==0){ System.out.println(0); } else{ if(Math.sqrt(x*x+y*y)==(int)Math.sqrt(x*x+y*y)){ System.out.println(1); } else{ System.out.println(2); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
e4b0e8353a4e758ee21667e70564a3eb
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class sol { public static void main(String arg[]) { Scanner sc=new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int x=sc.nextInt(); int y=sc.nextInt(); if(x==0&&y==0){ System.out.println(0); continue; } int v=x*x+y*y; double squareRoot = Math.sqrt(v); long val=(long)(squareRoot+0.5); if(v==val*val){ System.out.println(1); } else{ System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
76be52b9b5093bbeb1b0b5dd713740a6
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class moves { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans[]=new int[n]; for(int i=0;i<n;i++){ int n1=sc.nextInt(); int n2=sc.nextInt(); double num=Math.sqrt(Math.pow(n1,2)+Math.pow(n2,2)); if(n1==0 && n2==0){ ans[i]=0; } else if(num%1==0) { ans[i]=1; } else { ans[i]=2; } } for(int i=0;i<n;i++){ System.out.println(ans[i]); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
16214616f6c17ccb04a49517ab933401
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class moves { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int ans[]=new int[n]; for(int i=0;i<n;i++){ int n1=sc.nextInt(); int n2=sc.nextInt(); double num=Math.pow(n1,2)+Math.pow(n2,2); num=Math.sqrt(num); double num1=(int)num; if(n1==0 && n2==0){ ans[i]=0; } else if(num-num1==0) { ans[i]=1; } else { ans[i]=2; } } for(int i=0;i<n;i++){ System.out.println(ans[i]); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
adc400ac6def1c210f5766676fb5e036
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.time.Instant; import java.util.*; import static java.lang.Math.*; //-------------------------------///////////////****/////////******////////// //------------------------------------///**********//*****//********//*****// //-----------------------------------///**********//*****//********//*****// //----------------------------------///**********//*****//********//*****// //---------------------------------///**********//*****//********//*****// //--------------------------------///**********//*****//********//*****// //--------------------------///**///**********//*****//********//*****// //---------------------------/////***********/////////*******////////// public class CodeForces { final static String no = "NO"; final static String yes = "YES"; static long count = 0; static public OutputWriter w = new OutputWriter(System.out); static public IO sc = new IO(); static HashMap<Integer, Integer> map = new HashMap<>(); static Scanner fc = new Scanner(System.in); //*******************************************Be SANSA*********************************** //************************************Don't stick to single approach******************** //*****************************************You are a slow learner But you learn********* //***************************************Don't fall in rating trap********************** //**********************************Pain in temporary, regret remains forever*********** //////////////////////////////////////////////////////////////////////////////////////////// public static void main(String[] args) { int t = sc.nextInt(); in: while(t-->0) { int a = sc.nextInt(); int b = sc.nextInt(); if(a==b && a==0) { w.writer.println(0); continue in; } double x ,y; x =y= sqrt(pow(a,2)+pow(b,2)); if(Math.ceil(x)!=Math.floor(y)) { w.writer.println(2); }else { w.writer.println(1); } } w.writer.flush(); } static boolean res(long sum, TreeMap<Long,Integer> tm) { int val = tm.getOrDefault(sum, 0); if(val>0) { tm.put(sum, tm.get(sum)-1); return true; }else if(sum==1) { return false; } else { return res(sum/2,tm)&&res((sum+1)/2, tm); } } ////////////////////////////////////////////////////////////////////////////////////////// static int floorPowerOf2(int n) { int p = (int)(Math.log(n) / Math.log(2)); return (int)Math.pow(2, p); } static int ceilPowerOf2(int n) { int p = (int)(Math.log(n) / Math.log(2)); return (int)Math.pow(2, p+1); } static List<Integer> printDivisors(int n) { // Note that this loop runs till square root List<Integer> sl = new ArrayList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { // If divisors are equal, print only one if (n / i == i) sl.add(i); else // Otherwise print both { sl.add(i); sl.add(n / i); } } } return sl; } static class Pair { int x, y,z; Pair(int x,int y){ this.x = x; this.y = y; } Pair(int x, int y,int z) { this.x = x; this.y = y; this.z = z; } } 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); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sort(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sortDec(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static void sortDec(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static class IO { 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()); } long[] longArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } } static public class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
ca2d4815266713b5ee287616a22a2e2e
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; import java.time.*; import static java.lang.Math.*; @SuppressWarnings("unused") public class A { static boolean DEBUG = false; static Reader fs; static PrintWriter pw; static TreeSet<Integer> p_square = new TreeSet<>(); static void solve() { int x = fs.nextInt(); int y = fs.nextInt(); if (x == 0 && y == 0) { pw.println(0); return; } if (p_square.contains(x * x + y * y)) { pw.println(1); } else { pw.println(2); } } public static void main(String[] args) throws IOException { for (int i = 1; i <= 1000; i++) { p_square.add(i * i); } if (args.length == 2) { System.setIn(new FileInputStream("D:\\program\\javaCPEclipse\\CodeForces\\src\\input.txt")); System.setErr(new PrintStream("D:\\program\\javaCPEclipse\\CodeForces\\src\\error.txt")); DEBUG = true; } Instant start = Instant.now(); fs = new Reader(); pw = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { solve(); } Instant end = Instant.now(); if (DEBUG) { pw.println(Duration.between(start, end)); } pw.close(); } static void sort(int a[]) { ArrayList<Integer> l = new ArrayList<Integer>(); for (int x : a) l.add(x); Collections.sort(l); for (int i = 0; i < a.length; i++) { a[i] = l.get(i); } } public static void print(long a, long b, long c, PrintWriter pw) { pw.println(a + " " + b + " " + c); return; } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { 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; } int[][] read2Array(int n, int m) { int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextInt(); } } return a; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
8abf6a4c2dd51f9fd17d6665d7ba4da1
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class CodeForcesTest{ public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for (int i = 0; i < t; i++) { double x = s.nextInt(); double y = s.nextInt(); if(x==0 && y==0) System.out.println("0"); else if(Math.pow(x*x + y*y,0.5)%1==0) System.out.println("1"); else System.out.println("2"); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
482c3201a088ef0eb5bd67af7b119c88
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
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 x = sc.nextInt(); int y = sc.nextInt(); int d = (x * x) + (y * y); int r = 0; while (r * r < d) ++r; int ans = 2; if (r * r == d) { ans = 1; } if (x == 0 && y == 0) { ans = 0; } System.out.println(ans); t--; } sc.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
a44ac23ff3e958bbe7506f919098c01c
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.lang.Math; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0) { int x = sc.nextInt(); int y = sc.nextInt(); if (x == 0 && y == 0) { System.out.println(0); } else { int x2 = x * x; int y2 = y * y; double ans = Math.sqrt(x2 + y2); if ((ans - Math.floor(ans)) == 0) { System.out.println(1); } else { System.out.println(2); } } t--; } sc.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
7a2062da12f40db8462eb1b7eeee20c7
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author JuniorAndrade */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { int solve(int x) { for (int i = 0; i * i <= x; ++i) { if (i * i == x) return 0; } return 1; } public void solve(int testNumber, InputReader in, OutputWriter out) { int test = in.readInt(); while (test-- > 0) { int x = in.readInt(); int y = in.readInt(); if (x == 0 && y == 0) { out.printLine(0); } else { out.printLine(1 + solve(x * x + y * y)); } } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } 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 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 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; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
96eeac444eb8d337db4a433a9cb3fd6c
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class MAIN { 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 int eu (int x, int y){ if(x==0 && y ==0){ return 0; } else if (Math.sqrt((x*x)+(y*y))%1==0){ return 1; } else{ return 2; } } public static void main(String[] args) { FastReader s = new FastReader(); int t = s.nextInt(); while(t>0) { int x = s.nextInt(); int y = s.nextInt(); System.out.println(eu(x,y)); --t; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
871874a7a4a3183d11212b0771ed5093
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { // Graph // prefix sums //inputs public static void main(String args[])throws Exception{ Input sc=new Input(); precalculates p=new precalculates(); StringBuilder sb=new StringBuilder(); int t=sc.readInt(); int dp[]=new int[5000+1]; for(int i=1;i<=5000;i++){ dp[i]=Integer.MAX_VALUE; for(int j=1;j<=(int)Math.sqrt(i);j++){ dp[i]=Math.min(dp[i],dp[i-j*j]+1); } } for(int f=0;f<t;f++){ int d[]=sc.readArray(); int a=d[0],b=d[1]; int tot=a*a; tot=tot+(b*b); boolean h=false; for(int i=1;i<=52;i++){ if(i*i==tot){ h=true; break; } } if(h) { sb.append("1\n"); continue; } int count=0; sb.append(dp[tot]+"\n"); } System.out.print(sb); } } class Input{ BufferedReader br; StringTokenizer st; Input(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public int[] readArray() throws Exception{ st=new StringTokenizer(br.readLine()); int a[]=new int[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Integer.parseInt(st.nextToken()); } return a; } public long[] readArrayLong() throws Exception{ st=new StringTokenizer(br.readLine()); long a[]=new long[st.countTokens()]; for(int i=0;i<a.length;i++){ a[i]=Long.parseLong(st.nextToken()); } return a; } public int readInt() throws Exception{ st=new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } public long readLong() throws Exception{ st=new StringTokenizer(br.readLine()); return Long.parseLong(st.nextToken()); } public String readString() throws Exception{ return br.readLine(); } public int[][] read2dArray(int n,int m)throws Exception{ int a[][]=new int[n][m]; for(int i=0;i<n;i++){ st=new StringTokenizer(br.readLine()); for(int j=0;j<m;j++){ a[i][j]=Integer.parseInt(st.nextToken()); } } return a; } } class precalculates{ public long gcd(long p, long q) { if (q == 0) return p; else return gcd(q, p % q); } public int[] prefixSumOneDimentional(int a[]){ int n=a.length; int dp[]=new int[n]; for(int i=0;i<n;i++){ if(i==0) dp[i]=a[i]; else dp[i]=dp[i-1]+a[i]; } return dp; } public int[] postSumOneDimentional(int a[]) { int n = a.length; int dp[] = new int[n]; for (int i = n - 1; i >= 0; i--) { if (i == n - 1) dp[i] = a[i]; else dp[i] = dp[i + 1] + a[i]; } return dp; } public int[][] prefixSum2d(int a[][]){ int n=a.length;int m=a[0].length; int dp[][]=new int[n+1][m+1]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ dp[i][j]=a[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]; } } return dp; } public long pow(long a,long b){ long mod=998244353; long ans=1; if(b<=0) return 1; if(b%2==0){ ans=pow(a,b/2)%mod; return ((ans%mod)*(ans%mod))%mod; }else{ ans=pow(a,b-1)%mod; return ((a%mod)*(ans%mod))%mod; } } } class GraphInteger{ HashMap<Integer,vertex> vtces; class vertex{ HashMap<Integer,Integer> children; public vertex(){ children=new HashMap<>(); } } public GraphInteger(){ vtces=new HashMap<>(); } public void addVertex(int a){ vtces.put(a,new vertex()); } public void addEdge(int a,int b,int cost){ if(!vtces.containsKey(a)){ vtces.put(a,new vertex()); } if(!vtces.containsKey(b)){ vtces.put(b,new vertex()); } vtces.get(a).children.put(b,cost); // vtces.get(b).children.put(a,cost); } public boolean isCyclicDirected(){ boolean isdone[]=new boolean[vtces.size()+1]; boolean check[]=new boolean[vtces.size()+1]; for(int i=1;i<=vtces.size();i++) { if (!isdone[i] && isCyclicDirected(i,isdone, check)) { return true; } } return false; } private boolean isCyclicDirected(int i,boolean isdone[],boolean check[]){ if(check[i]) return true; if(isdone[i]) return false; check[i]=true; isdone[i]=true; Set<Integer> set=vtces.get(i).children.keySet(); for(Integer ii:set){ if(isCyclicDirected(ii,isdone,check)) return true; } check[i]=false; return false; } } class union_find { int n; int[] sz; int[] par; union_find(int nval) { n = nval; sz = new int[n + 1]; par = new int[n + 1]; for (int i = 0; i <= n; i++) { par[i] = i; sz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } boolean find(int a, int b) { return root(a) == root(b); } int union(int a, int b) { int ra = root(a); int rb = root(b); if (ra == rb) return 0; if(a==b) return 0; if (sz[a] > sz[b]) { int temp = ra; ra = rb; rb = temp; } par[ra] = rb; sz[rb] += sz[ra]; return 1; } } /* static int mod=998244353; private static int add(int x, int y) { x += y; return x % MOD; } private static int mul(int x, int y) { int res = (int) (((long) x * y) % MOD); return res; } private static int binpow(int x, int y) { int z = 1; while (y > 0) { if (y % 2 != 0) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } private static int inv(int x) { return binpow(x, MOD - 2); } private static int devide(int x, int y) { return mul(x, inv(y)); } private static int C(int n, int k, int[] fact) { return devide(fact[n], mul(fact[k], fact[n-k])); } */
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
64d47871e5051a76144abaf811e6c839
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class integer_moves{ public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); while(t!=0){ int x=scanner.nextInt(); int y=scanner.nextInt(); int count=0; t--; if(x==0 && y==0) System.out.println(count); else{ double result=Math.sqrt(Math.pow(x, 2)+Math.pow(y, 2)); if(result%1==0){ count++; System.out.println(count); } else{ count=2; System.out.println(count); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
fd94e34a98fd7ce4ad90fc7521f14747
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- > 0) { int x = s.nextInt(), y = s.nextInt(); int ans = Math.sqrt((x*x)+(y*y)) == (int)Math.sqrt((x*x)+(y*y)) ? 1 : 2; System.out.println(x == 0 && y == 0 ? 0 : ans); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
e15db37a373baa4d51ff55a9549cc7bc
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- > 0) { int x = s.nextInt(), y = s.nextInt(); if(x == 0 && y == 0) { System.out.println(0); } else { double r1 = Math.sqrt((x*x)+(y*y)); System.out.println(r1 == (int)r1 ? 1 : 2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
3a72a360e721588c348b8316aa96af9d
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class EDU125_A { public static void main(String[] args) throws IOException{ try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){ int tCases = Integer.parseInt(br.readLine()); while (tCases-- > 0) { StringTokenizer st = new StringTokenizer(br.readLine().trim()); int x2 = Integer.parseInt(st.nextToken()); int y2 = Integer.parseInt(st.nextToken()); int x0 = 0; int y0 = 0; int cont = 0; if (x2 == 0 && y2 == 0) System.out.println(0); else if (nextPoint(x0, y0, x2, y2)) System.out.println(1); else { /*for(int i = 1; i < x2; i++) { for(int j = 1; j < y2; j++) { if (nextPoint(x0, y0, i, j)) { x0 = i; y0 = j; cont++; if (nextPoint(x0, y0, x2, y2)) { cont++; i = x2+1; j = y2+1; }else cont = 0; } } }*/ System.out.println(2); } } } } static boolean nextPoint(int x1, int y1, int x2, int y2) { boolean resultado = false; double x = Math.sqrt( Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2) ); if(x==(int)x) resultado = true; return resultado; } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
849b3f717f2610dccf5448b7f1d60517
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; /* author : Multi-Thread */ public class A { //public class Main { // static int INF = 998244353; static int INF = (int) 1e9 + 7; static int MAX = Integer.MAX_VALUE; static int MIN = Integer.MIN_VALUE; public static void main(String[] args) { int test = fs.nextInt(); // int test = 1; for (int cases = 0; cases < test; cases++) { // solve(); final_answer.append(solve() + "\n"); } out.print(final_answer.toString()); out.flush(); } static StringBuilder final_answer = new StringBuilder(); static String solve() { int x = fs.nextInt(), y = fs.nextInt(); if (x == 0 && y == 0) return 0 + ""; int dist=x*x+y*y; int sq=(int)Math.sqrt(dist); if(sq*sq==dist) return 1 + ""; return 2+""; } static void intSort(int[] a, boolean reverse) { ArrayList<Integer> al = new ArrayList<Integer>(); for (int i : a) al.add(i); Collections.sort(al); if (reverse) { for (int i = 0; i < a.length; i++) a[i] = al.get(a.length - i - 1); } else { for (int i = 0; i < a.length; i++) a[i] = al.get(i); } } static class Pair { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public String toString() { return "[" + first + "," + second + "]"; } } static class LongPair { long first; long second; LongPair(long a, long b) { this.first = a; this.second = b; } public String toString() { return "[" + first + "," + second + "]"; } } 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 OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } 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() { writer.print("\n"); } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } private static final FastReader fs = new FastReader(); private static final OutputWriter out = new OutputWriter(System.out); }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
9ee6eb290287b5deac23f17063e30e1d
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class Practice { static boolean multipleTC = true; final static int mod = 1000000007; final static int mod2 = 998244353; final double E = 2.7182818284590452354; final double PI = 3.14159265358979323846; int MAX = 1000000007; void pre() throws Exception { } // All the best void solve(int TC) throws Exception { int x = ni(),y = ni(); if(x==0 && y==0) { pn("0"); }else { double sq = (x*x) + (y*y); double sqrt = Math.sqrt(sq); int s = (int)sqrt; if(s== sqrt) { pn("1"); }else { pn("2"); } } } double dist(int x1, int y1, int x2, int y2) { double a = x1 - x2, b = y1 - y2; return Math.sqrt((a * a) + (b * b)); } int[] readArr(int n) throws Exception { int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = ni(); } return arr; } void sort(int arr[], int left, int right) { ArrayList<Integer> list = new ArrayList<>(); for (int i = left; i <= right; i++) list.add(arr[i]); Collections.sort(list); for (int i = left; i <= right; i++) arr[i] = list.get(i - left); } void sort(int arr[]) { ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < arr.length; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < arr.length; i++) arr[i] = list.get(i); } public long max(long... arr) { long max = arr[0]; for (long itr : arr) max = Math.max(max, itr); return max; } public int max(int... arr) { int max = arr[0]; for (int itr : arr) max = Math.max(max, itr); return max; } public long min(long... arr) { long min = arr[0]; for (long itr : arr) min = Math.min(min, itr); return min; } public int min(int... arr) { int min = arr[0]; for (int itr : arr) min = Math.min(min, itr); return min; } public long sum(long... arr) { long sum = 0; for (long itr : arr) sum += itr; return sum; } public long sum(int... arr) { long sum = 0; for (int itr : arr) sum += itr; return sum; } String bin(long n) { return Long.toBinaryString(n); } String bin(int n) { return Integer.toBinaryString(n); } static int bitCount(int x) { return x == 0 ? 0 : (1 + bitCount(x & (x - 1))); } static void dbg(Object... o) { System.err.println(Arrays.deepToString(o)); } int bit(long n) { return (n == 0) ? 0 : (1 + bit(n & (n - 1))); } int abs(int a) { return (a < 0) ? -a : a; } long abs(long a) { return (a < 0) ? -a : a; } void p(Object o) { out.print(o); } void pn(Object o) { out.println(o); } void pni(Object o) { out.println(o); out.flush(); } void pn(int[] arr) { int n = arr.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(arr[i] + " "); } pn(sb); } void pn(long[] arr) { int n = arr.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(arr[i] + " "); } pn(sb); } 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()); } public static void main(String[] args) throws Exception { new Practice().run(); } FastReader in; PrintWriter out; void run() throws Exception { in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC) ? ni() : 1; pre(); for (int t = 1; t <= T; t++) solve(t); out.flush(); out.close(); } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
a9f5984071dc8dcfd36e09c0f9e26c32
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
/* Created by Isaac Chen on 2022/03/24 19:06:12*/ import java.util.*; import java.lang.*; import java.io.*; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int cas=sc.nextInt(); for(int z=0;z<cas;z++) { int x=sc.nextInt(),y=sc.nextInt(); Double sq=Math.sqrt(x*x+y*y); int sq1=sq.intValue(); if(x==0&&y==0) System.out.println(0); else if(sq1*sq1==x*x+y*y) System.out.println(1); else System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
2893c626c9ce9aa4d785614775c485d0
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
public class IntegerMoves { private static final java.util.Scanner sc=new java.util.Scanner(System.in); public void solve() { int t=sc.nextInt(); while (t>0) { int x=sc.nextInt(); int y=sc.nextInt(); int ans=Integer.MIN_VALUE; double _temp=(Math.pow(x,2))+Math.pow(y,2); int result=0; while ((result*result)<_temp) ++result; ans=2; if ((result*result)==_temp) ans=1; if (x==0 && y==0) ans=0; System.out.println(ans); t--; } sc.close(); } public static void main(String[] args) { new IntegerMoves().solve(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
bf614794e22d5ff6ea1b0b1a11066548
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Main { private static void solve(InputScanner in, PrintWriter out) throws IOException { int tests = in.nextInt(); for (int test = 0; test < tests; test++) { int x = in.nextInt(); int y = in.nextInt(); int dist = x * x + y * y; if (dist == 0) { out.println(0); } else { int res = 0; while (res * res < dist) { res++; } if (res * res == dist) { out.println(1); } else { out.println(2); } } } } public static class InputScanner { private BufferedReader in; private StringTokenizer st; public InputScanner(InputStream is) { in = new BufferedReader(new InputStreamReader(is)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.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 void close() throws IOException { in.close(); } } private static InputScanner in; private static PrintWriter out; private static void init() throws IOException { in = new InputScanner(System.in); out = new PrintWriter(System.out); solve(in, out); in.close(); out.close(); } public static void main(String[] args) throws IOException { init(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
b40964e38c47443f3dd1f26d3561a312
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import static java.util.Arrays.asList; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.StringTokenizer; /** * A. Integer Moves * @see <a href="https://codeforces.com/contest/1657/problem/A">https://codeforces.com/contest/1657/problem/A</a> */ public class Main { private final InputStream in; private final PrintStream out; public Main( final Boolean sample, final InputStream in, final PrintStream out) { this.in = in; this.out = out; } private boolean isSquare(final int a, final int b) { final double d = Double.valueOf(Math.sqrt(a * a + b * b)); return d == Math.floor(d) && !Double.isInfinite(d); } private void handleTestCase(final Integer i, final FastScanner sc) { final int x = sc.nextInt(); final int y = sc.nextInt(); int ans = 2; if (x == 0 && y == 0) { ans = 0; } else if (isSquare(x, y)) { ans = 1; } this.out.println(ans); } public void solve() { try (final FastScanner sc = new FastScanner(this.in)) { final int numberOfTestCases = sc.nextInt(); for (int i = 0; i < numberOfTestCases; i++) { handleTestCase(i, sc); } } } public static void main(final String[] args) throws IOException, URISyntaxException { final boolean sample = isSample(); final InputStream is; final PrintStream out; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); long timerStart = 0; if (sample) { is = Main.class.getResourceAsStream("sample.in"); out = new PrintStream(baos, true); timerStart = System.nanoTime(); } else { is = System.in; out = System.out; } new Main(sample, is, out).solve(); out.flush(); if (sample) { final long timeSpent = (System.nanoTime() - timerStart) / 1_000; final double time; final String unit; if (timeSpent < 1_000) { time = timeSpent; unit = "µs"; } else if (timeSpent < 1_000_000) { time = timeSpent / 1_000.0; unit = "ms"; } else { time = timeSpent / 1_000_000.0; unit = "s"; } final Path path = Paths.get(Main.class.getResource("sample.out").toURI()); final List<String> expected = Files.readAllLines(path); final List<String> actual = asList(baos.toString().split("\\r?\\n")); if (!expected.equals(actual)) { throw new AssertionError(String.format( "Expected %s, got %s", expected, actual)); } actual.forEach(System.out::println); System.out.println(String.format("took: %.3f %s", time, unit)); } } private static boolean isSample() { try { return "sample".equals(System.getProperty("codeforces")); } catch (final SecurityException e) { return false; } } private static final class FastScanner implements Closeable { private final BufferedReader br; private StringTokenizer st; public FastScanner(final InputStream in) { this.br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } public String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (final IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } @Override public void close() { try { this.br.close(); } catch (final IOException e) { // ignore } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
c6f218ffd928a6c483ef9f574ecabbfb
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int tt=0; tt<t; tt++){ int a=in.nextInt(); int b=in.nextInt(); if(a==0 && b==0) System.out.println(0); else if((int)Math.sqrt(a*a+b*b)*(int)Math.sqrt(a*a+b*b)==a*a+b*b) System.out.println(1); else System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
b3f9a75fc2f3f7518f5626d04ef5b516
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class cfintegermoves{ public static void main(String[] args) throws Exception{ Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t--!=0){ int x=scn.nextInt(); int y=scn.nextInt(); if(x==0 && y==0){ System.out.println(0); continue; } else if(Math.sqrt(x*x+y*y)%1==0){ System.out.println(1); continue; } System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
11c1f60753525b22b9cdfe258d055b8d
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
// * * * the goal is to be worlds best * * * // import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class first { static class Pair implements Comparable<Pair> { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } public int compareTo(Pair o) { return this.a - o.a; } } public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); int T = t; while (T-- > 0) { int x = sc.nextInt(); int y = sc.nextInt(); int z = x * x + y * y; if(z == 0) System.out.println(0); else if(cp(z)) System.out.println(1); else System.out.println(2); } } static boolean cp(int n) { // If ceil and floor are equal // the number is a perfect // square if (Math.ceil((double) Math.sqrt(n)) == Math.floor((double) Math.sqrt(n))) { return true; } else { return false; } } static boolean pal(char ca[]) { String ss = new String(ca); int lrg = longe(ss); if (lrg >= 5) return true; return false; } static int longe(String str) { // get length of input string int n = str.length(); // table[i][j] will be false if // substring str[i..j] is not palindrome. // Else table[i][j] will be true boolean table[][] = new boolean[n][n]; // All substrings of length 1 are palindromes int maxLength = 1; for (int i = 0; i < n; ++i) table[i][i] = true; // check for sub-string of length 2. int start = 0; for (int i = 0; i < n - 1; ++i) { if (str.charAt(i) == str.charAt(i + 1)) { table[i][i + 1] = true; start = i; maxLength = 2; } } // Check for lengths greater than 2. // k is length of substring for (int k = 3; k <= n; ++k) { // Fix the starting index for (int i = 0; i < n - k + 1; ++i) { // Get the ending index of substring from // starting index i and length k int j = i + k - 1; // checking for sub-string from ith index to // jth index iff str.charAt(i+1) to // str.charAt(j-1) is a palindrome if (table[i + 1][j - 1] && str.charAt(i) == str.charAt(j)) { table[i][j] = true; if (k > maxLength) { start = i; maxLength = k; } } } } return maxLength; } static long sum(long n) { long temp = n; long sum = 0; while (temp > 0) { sum += temp % 10; temp /= 10; } return sum; } // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2 // worst case since it uses a version of quicksort. Although this would never // actually show up in the real world, in codeforces, people can hack, so // this is needed. static void ruffleSort(int[] a) { // ruffle 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; } // then sort Arrays.sort(a); } // Use this to input code since it is faster than a Scanner 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()); } double nextDouble() { return Double.parseDouble(next()); } String str = ""; String nextLine() { 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[] 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()); } } // use this to find the index of any element in the array +1 /// // returns an array that corresponds to the index of the i+1th in the array a[] // runs only for array containing different values enclosed btw 0 to n-1 static int[] indexOf(int[] a) { int[] toRet = new int[a.length]; for (int i = 0; i < a.length; i++) { toRet[a[i]] = i + 1; } return toRet; } static long gcd(long n, long l) { if (l == 0) return n; return gcd(l, n % l); } static long sol(long a[], long b[], long x[]) { int n = a.length; long res = Math.abs(a[0] - b[0]) + Math.abs(a[n - 1] + b[n - 1]); if (Math.abs(a[0] - b[0]) + x[1] + x[3] < res) { res = Math.abs(a[0] - b[0]) + x[1] + x[3]; } if (Math.abs(a[n - 1] - b[n - 1]) + x[0] + x[2] < res) { res = Math.abs(a[n - 1] - b[n - 1]) + x[0] + x[2]; } if (Math.abs(a[n - 1] - b[0]) + Math.abs(a[0] - b[n - 1]) < res) { res = Math.abs(a[n - 1] - b[0]) + Math.abs(a[0] - b[n - 1]); } if (Math.abs(a[0] - b[n - 1]) + x[0] + x[3] < res) { res = Math.abs(a[0] - b[n - 1]) + x[0] + x[3]; } if (Math.abs(a[n - 1] - b[0]) + x[2] + x[1] < res) { res = Math.abs(a[n - 1] - b[0]) + x[2] + x[1]; } res = Math.min(res, x[0] + x[1] + x[2] + x[3]); return res; } // generates all the prime numbers upto n static void sieveOfEratosthenes(int n, ArrayList<Integer> al) { 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; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) al.get(i); } } static final int mod = 100000000 + 7; static final int max_val = 2147483647; static final int min_val = max_val + 1; // fastPow static long fastPow(long base, long exp) { if (exp == 0) return 1; long half = fastPow(base, exp / 2); if (exp % 2 == 0) return mul(half, half); return mul(half, mul(half, base)); } // multiply two long numbers static long mul(long a, long b) { return a * b % mod; } static int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } // Returns factorial of n static int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } // to generate the lps array // lps means longest preffix that is also a suffix static void generateLPS(int lps[], String p) { int l = 0; int r = 1; while (l < p.length() && l < r && r < p.length()) { if (p.charAt(l) == p.charAt(r)) { lps[r] = l + 1; l++; r++; } else { if (l > 0) l = lps[l - 1]; else r++; } } } // count sort --> it runs in O(n) time but compromises in space static ArrayList<Integer> countSort(int a[]) { int max = Integer.MIN_VALUE; for (int i = 0; i < a.length; i++) { max = Math.max(max, a[i]); } int posfre[] = new int[max + 1]; boolean negPres = false; for (int i = 0; i < a.length; i++) { if (a[i] >= 0) { posfre[a[i]]++; } else { negPres = true; } } ArrayList<Integer> res = new ArrayList<>(); if (negPres) { int min = Integer.MAX_VALUE; for (int i = 0; i < a.length; i++) { min = Math.min(min, a[i]); } int negfre[] = new int[-1 * min + 1]; for (int i = 0; i < a.length; i++) { if (a[i] < 0) { negfre[-1 * a[i]]++; } } for (int i = min; i < 0; i++) { for (int j = 0; j < negfre[-1 * i]; j++) { res.add(i); } } for (int i = 0; i <= max; i++) { for (int j = 0; j < posfre[i]; j++) { res.add(i); } } return res; } for (int i = 0; i <= max; i++) { for (int j = 0; j < posfre[i]; j++) { res.add(i); } } return res; } // returns the index of the element which is just smaller than or // equal to the tar in the given arraylist static int lowBound(ArrayList<Integer> ll, long tar, int l, int r) { if (l > r) return l; int mid = l + (r - l) / 2; if (ll.get(mid) >= tar) { return lowBound(ll, tar, l, mid - 1); } return lowBound(ll, tar, mid + 1, r); } // returns the index of the element which is just greater than or // equal to the tar in the given arraylist static int upBound(ArrayList<Integer> ll, long tar, int l, int r) { if (l > r) return l; int mid = l + (r - l) / 2; if (ll.get(mid) <= tar) { return upBound(ll, tar, l, mid - 1); } return upBound(ll, tar, mid + 1, r); } static void swap(int i, int j, int a[]) { int x = a[i]; int y = a[j]; a[j] = x; a[i] = y; } // a -> z == 97 -> 122 // String.format("%.9f", ans) ,--> to get upto 9 decimal places , (ans is // double) // write }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
01035b29cc4a0e2bc0e6cdca3d94eb25
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static FastReader sc = new FastReader(); public static void main (String[] args) throws java.lang.Exception { int t = sc.nextInt(); while(t-->0){ solve(sc); } } public static void solve(FastReader sc) throws IOException{ int x = i(); int y = i(); if(x==0&&y==0){ out.println(0);out.flush();return; } int num = (x*x) + (y*y); double root = Math.sqrt(num); boolean pf = false; if(root - (Math.floor(root))==0){ pf=true; } out.println(pf ? 1 : 2); out.flush(); } /* int [] arr = new int[n]; for(int i = 0;i<n;++i){ arr[i] = sc.nextInt(); } */ static void mysort(int[] arr) { for(int i=0;i<arr.length;i++) { int rand = (int) (Math.random() * arr.length); int loc = arr[rand]; arr[rand] = arr[i]; arr[i] = loc; } Arrays.sort(arr); } static class Pair implements Comparable<Pair>{ int ind;int val; Pair(int ind, int val){ this.ind=ind; this.val=val; } public int compareTo(Pair o){ return this.val-o.val; } } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
25849f4bdb78f63320d5915a858df8a6
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static class Edge{ int start; int end; Edge(int start,int end) { this.start = start; this.end = end; } } static boolean[] primecheck = new boolean[1000002]; static ArrayList<Long> lucky = new ArrayList<>(); public static void main(String[] args) throws IOException { OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); PROBLEM solver = new PROBLEM(); int t = in.nextInt(); while(t-->0) solver.solve(in, out); out.close(); } public static void luckIsCalling(long n){ long a = n*10 + 4; long b = n*10 + 7; lucky.add(a); lucky.add(b); if(a<=4444444444L) luckIsCalling(a); if(b<=4444444444L) luckIsCalling(b); } static class PROBLEM { static class Pair{ int a; int b; Pair(int a,int b){ this.a = a; this.b = b; } } public void solve(FastReader sc, PrintWriter out) { int x = sc.nextInt(); int y = sc.nextInt(); if(x==0&&y==0){ System.out.println(0); return; } else if(isPerfectSquare(x*x+y*y)){ System.out.println(1); return; } else{ System.out.println(2); return; } } public boolean isPerfectSquare(int x) { if (x >= 0) { int sr = (int)Math.sqrt(x); return ((sr * sr) == x); } return false; } public long sumPairs(long arr[],int n) { // final result long sum = 0; for (int i=n-1; i>=0; i--) sum += i*arr[i] - (n-1-i)*arr[i]; return sum; } } static int helper(ArrayList<Integer> lt ,int k) { int arr[] = new int[lt.size()]; arr[0]=lt.get(0); for(int i=1;i<k&&i<arr.length;i++) { arr[i]=arr[i-1]+lt.get(i); } for(int i=k;i<arr.length;i++) { arr[i] = arr[i-1]+lt.get(i)-arr[i-k]; } Arrays.sort(arr); return arr[arr.length-1]; } static boolean isPalindrome(char[] s) { int flag = 1; for (int i = 0; i < s.length; i++) { if (s[i] != s[s.length - 1 - i]) { flag = 0; break; } } if (flag == 1) return true; else return false; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static int exponentMod(int A, int B, int C) { // Base cases if (A == 0) return 0; if (B == 0) return 1; // If B is even long y; if (B % 2 == 0) { y = exponentMod(A, B / 2, C); y = (y * y) % C; } else { y = A % C; y = (y * exponentMod(A, B - 1, C) % C) % C; } return (int) ((y + C) % C); } public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int hashCode() { return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<U, V> p = (Pair<U, V>) o; return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); } public int compareTo(Pair<U, V> b) { int cmpU = x.compareTo(b.x); return cmpU != 0 ? cmpU : y.compareTo(b.y); } public String toString() { return String.format("(%s, %s)", x.toString(), y.toString()); } } 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()); } char nextChar() { return next().charAt(0); } boolean nextBoolean() { return !(nextInt() == 0); } // boolean nextBoolean(){return Boolean.parseBoolean(next());} String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] readArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } } private static int[] mergeSort(int[] array) { if (array.length <= 1) { return array; } int midpoint = array.length / 2; int[] left = new int[midpoint]; int[] right; if (array.length % 2 == 0) { right = new int[midpoint]; } else { right = new int[midpoint + 1]; } for (int i = 0; i < left.length; i++) { left[i] = array[i]; } for (int i = 0; i < right.length; i++) { right[i] = array[i + midpoint]; } int[] result = new int[array.length]; left = mergeSort(left); right = mergeSort(right); result = merge(left, right); return result; } private static int[] merge(int[] left, int[] right) { int[] result = new int[left.length + right.length]; int leftPointer = 0, rightPointer = 0, resultPointer = 0; while (leftPointer < left.length || rightPointer < right.length) { if (leftPointer < left.length && rightPointer < right.length) { if (left[leftPointer] < right[rightPointer]) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } else if (leftPointer < left.length) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } return result; } public static void Sieve(int n) { Arrays.fill(primecheck, true); primecheck[0] = false; primecheck[1] = false; for (int i = 2; i * i < n + 1; i++) { if (primecheck[i]) { for (int j = i * 2; j < n + 1; j += i) { primecheck[j] = false; } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
0fe6daf64f82d56279e8941aa6969ef3
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class Forces { static int max=Integer.MIN_VALUE; public static void main(String args[]) { Scanner input=new Scanner(System.in); int t=input.nextInt(); while (t-->0) { int x=input.nextInt(); int y=input.nextInt(); double innerVal=(x*x)+(y*y); double val= Math.sqrt(innerVal); int floor=(int) val; if(x==0 && y==0){ System.out.println(0); }else if((val-floor)==0){ System.out.println(1); }else{ System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
1ccef71f3f3de7b33ab545ff9102d84d
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class CFE125_A{ public static void main(String...k){ Scanner cs=new Scanner(System.in); int t=cs.nextInt(); while(t-->0){ int x=cs.nextInt(); int y=cs.nextInt(); int p=(int)Math.sqrt(x*x+y*y); if(x==0 && y==0) System.out.println(0); else if(x*x+y*y==p*p){ System.out.println(1); } else System.out.println(2); } cs.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
a5f61f9c0eba67ad4278d41e7fd10e0a
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { final static int mod = 1000000007; final static String yes = "YES"; final static String no = "NO"; public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); int t = sc.nextInt(); HashSet<Integer> set = new HashSet<>(); for (int i = 1; i < 51; i++) { set.add(i * i); } outer: while (t-- > 0) { int x = sc.nextInt(); int y = sc.nextInt(); if (x == 0 && y == 0) { System.out.println(0); continue outer; } int sq = x * x + y * y; double sqr = Math.sqrt(sq); double rem = sqr - Math.floor(sqr); System.out.println(rem == 0 ? 1 : 2); } } static void sortLong(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 sortInt(Integer[] a) // check for int { 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 boolean isSorted(int[] nums, int n) { for (int i = 1; i < n; i++) { if (nums[i] < nums[i - 1]) return false; } return true; } public static boolean isPalindrome(String s) { int i = 0, j = s.length() - 1; while (i <= j) { if (s.charAt(i) != s.charAt(j)) return false; i++; j--; } return true; } static long kadane(long A[]) { long lsum = A[0], gsum = 0; gsum = Math.max(gsum, lsum); for (int i = 1; i < A.length; i++) { lsum = Math.max(lsum + A[i], A[i]); gsum = Math.max(gsum, lsum); } return gsum; } public static void sortByColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator if (entry1[col] > entry2[col]) return 1; else return -1; } }); } public static void backtrack(String[] letters, int index, String digits, StringBuilder build, List<String> result) { if (build.length() >= digits.length()) { result.add(build.toString()); return; } char[] key = letters[digits.charAt(index) - '2'].toCharArray(); for (int j = 0; j < key.length; j++) { build.append(key[j]); backtrack(letters, index + 1, digits, build, result); build.deleteCharAt(build.length() - 1); } } public static String get(String s, int k) { int n = s.length(); int rep = k % n == 0 ? k / n : k / n + 1; s = s.repeat(rep); return s.substring(0, k); } public static int diglen(Long y) { int a = 0; while (y != 0L) { y /= 10; a++; } return a; } static class FastReader { BufferedReader br; StringTokenizer st; // StringTokenizer() is used to read long strings 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 class Pair implements Comparable<Pair> { public final int index; public final int value; public Pair(int index, int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { // multiplied to -1 as the author need descending sort order return -1 * Integer.valueOf(this.value).compareTo(other.value); } } static String reverseString(String str) { StringBuilder input = new StringBuilder(); return input.append(str).reverse().toString(); } static void printArray(int[] nums) { for (int i = 0; i < nums.length; i++) { System.out.print(nums[i] + "->"); } System.out.println(); } static long factorial(int n, int b) { if (n == b) return 1; return n * factorial(n - 1, b); } static int lcm(int ch, int b) { return ch * b / gcd(ch, b); } static int gcd(int ch, int b) { return b == 0 ? ch : gcd(b, ch % b); } static double ceil(double n, double k) { return Math.ceil(n / k); } static int sqrt(double n) { return (int) Math.sqrt(n); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
0f2efede12d5807cf52971a4016a8eb8
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class IntegerMoves { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int t =scanner.nextInt(); int best=0; for (int i = 0; i < t; i++) { int x=scanner.nextInt(); int y=scanner.nextInt(); double p = Math.sqrt(x*x+y*y); int counter=1; if (x==0 && y==0) System.out.println(0); else if (p == (int)p) System.out.println(1); else{ System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
3f6b7630e660473ce16784b629dcb273
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.math.*; import java.net.URL; import java.util.*; import java.lang.*; import java.io.*; //author **YOU KNOW WHO** public class problemSolving { public static void main(String[] args) throws ArrayIndexOutOfBoundsException { Scanner input = new Scanner(System.in); int n = input.nextInt(); int x1 = 0, y1 = 0, counter = 0; for (int i = 1; i <= n; i++) { int x2 = input.nextInt(), y2 = input.nextInt(); if (x2 == 0 && y2 == 0) { counter = 0; } else if (Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2)) == (int) (Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2)))) { counter = 1; } else { counter = 2; } System.out.println(counter); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
9a79c14ef4f9cafadc14a9d7c6a70772
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class practice{ public static void main(String[] args) { FastReader sc = new FastReader(); int t=sc.nextInt(); for(int i=0;i<t;i++){ int a=sc.nextInt(); int b=sc.nextInt(); String s=""; if(a==0 && b==0){ System.out.println(0); } else{ double n=Math.sqrt((a*a+b*b)); int m=(int)n; if(m*m==a*a+b*b){ System.out.println(1); } else { System.out.println(2); } } } } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
31f9323304411dc1685499cf296e1865
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ int a=sc.nextInt(); int b=sc.nextInt(); if(a==0 && b==0){ System.out.println(0); } else{ double n=Math.sqrt((a*a+b*b)); int m=(int)n; if(m*m==a*a+b*b){ System.out.println(1); } else { System.out.println(2); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
be7af75b99932fd7b91be2f904923982
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; import java.lang.Math; public class questions { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int x=sc.nextInt(); int y=sc.nextInt(); if(x==0 && y==0) { System.out.println("0"); continue; } float num=(float) Math.sqrt((x*x)+(y*y)); if(num%1==0) { System.out.println("1"); } else { System.out.println("2"); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
d592991328e2a76edadcc042358099b2
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int t=scan.nextInt(); while(t>0){ int x=scan.nextInt(); int y=scan.nextInt(); int p=x*x+y*y; int q=(int)Math.sqrt(p); if(x==0 && y==0){ System.out.println("0"); } else if(q*q==p){ System.out.println("1"); } else{ System.out.println("2"); } t--; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
3b5ce6d8c2e1c4945e20b191c665241c
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; /** * * @author eslam */ public class IceCave { 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; } } public static void main(String[] args) throws IOException { FastReader input = new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t = input.nextInt(); loop: while (t-- > 0) { int x = input.nextInt(); int y = input.nextInt(); int d = (int) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); if (x == 0 && y == 0) { log.write("0\n"); } else if (d*d == x*x+y*y) { log.write(1 + "\n"); } else { log.write(2 + "\n"); } } log.flush(); } static class pair { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
b8ad7a95eaacd3153edc97215cc0e4ad
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.PriorityQueue; import java.util.StringTokenizer; /** * * @author eslam */ public class IceCave { 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; } } public static void main(String[] args) throws IOException { FastReader input = new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t = input.nextInt(); loop: while (t-- > 0) { int x = input.nextInt(); int y = input.nextInt(); double d = Math.sqrt(Math.pow(x, 2)+Math.pow(y, 2)); int z = (int)d; if(x==0&&y==0){ log.write("0\n"); } else if(z==d){ log.write(1+"\n"); }else{ log.write(2+"\n"); } } log.flush(); } static class pair { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
f6d3eb24e9fb04688036bffe752d98ec
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class IntegerMoves { public static void main(String[] args) { Scanner sc = new Scanner(System.in); for (int t = sc.nextInt(); t > 0; t--) { int x = sc.nextInt(), y = sc.nextInt(); if (x == 0 && y == 0) { System.out.println(0); continue; } int tries = 1; if (!canGoBul(x, y, 0, 0)) tries++; System.out.println(tries); } } // public static int canGo(int x, int y, int dx, int dy) { // if (dx < 0 || dy < 0) return 0; // int sqr = (dx - x) * (dx - x) + (dy - y) * (dy - y); // double root = Math.sqrt(sqr); // int res = 0; // if (root * root == sqr) { // res++; // res += canGo(dx, dy, 0, 0); // } // int ys = canGo(x, y, dx, dy + 1); // int xs = canGo(x, y, dx + 1, dy); // // } public static boolean canGoBul(int x, int y, int dx, int dy) { int sqr = (dx - x) * (dx - x) + (dy - y) * (dy - y); double root = (int) Math.sqrt(sqr); return (root * root == sqr); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
3c110e5ad916cb8957577d7715b914f9
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
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 Codeforces { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ int x = sc.nextInt(); int y = sc.nextInt(); double z = Math.sqrt((x*x) + (y*y)); int value = (int)z; if(x == 0 && y ==0){ System.out.println(0); }else if(z == value){ System.out.println(1); }else{ System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
8e5ab48dfbb79a16d314660e87dd1091
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class codeforce { public static void main(String Args[]) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=1;i<=t;i++) { int x=sc.nextInt(); int y=sc.nextInt(); double z=Math.sqrt((x*x+y*y)); if(x==0&&y==0) System.out.println("0"); else if(z%1==0) System.out.println("1"); else System.out.println("2"); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
e7b7aca0913357a78bb14767faa99f6d
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
//Abhishek Mallick import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.CollationElementIterator; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { try { /*--------------------------------------------------------------------------------------------------------------------------*/ // System.setIn(new FileInputStream("input.txt")); // System.setOut(new PrintStream(new FileOutputStream("output.txt"))); Scanner sc = new Scanner(System.in); int T; T=sc.nextInt(); for(int i=1;i<=T;i++) { int x1=0,y1=0,count=0; int x2,y2; x2=sc.nextInt(); y2=sc.nextInt(); double dis=0; dis=Math.sqrt((x2*x2)+(y2*y2)); if(x2==0 && y2==0) count=0; else if(dis%1==0) count=1; else count=2; System.out.println(count); } /*--------------------------------------------------------------------------------------------------------------------------*/ } catch (Exception e) { System.err.println("Errorrr"); } } } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
91239b1c25cca10f94cbb6770a7a8b8e
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class IntegerMoves{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t-->0){ int a = scan.nextInt(); int b = scan.nextInt(); int x = a*a,y=b*b; int sqrt = (int)Math.sqrt(x+y); if(a==0 && b==0) System.out.println(0); else{ if(sqrt*sqrt == x+y) System.out.println(1); else System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
668b70156db8200f5daf1f7558f76949
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class check1 { public static void main(String[] args) throws IOException{ Reader sc=new Reader(); PrintWriter out = new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { long a = sc.nextLong(); long b = sc.nextLong(); long c = a*a+b*b; long d = (long) Math.sqrt(c); long e = d*d; int cnt=0; if(a!=0) cnt++; if(b!=0) cnt++; if(c==e) cnt = Math.min(cnt,1); else cnt = Math.min(cnt,2); out.println(cnt); } out.flush(); } public static long power(long x,long power) { if(power==0) return 1; long ans1 = power(x,power/2); ans1=ans1*ans1; if(power%2==0) return ans1; return x*ans1; } // (a*a_inverse) = 1(mod m) // finding a_inverse public static long modInverse(long a,long m) { // works only when m is prime long g=gcd(a,m); if(g==1) return power(a,m-2,m); else return -1; } // (x^power)mod(m) public static long power(long x,long power,long m) { if(power==0) return 1; long p = power(x,power/2,m)%m; p = (p*p)%m; if(power%2==0) return p; return (x*p)%m; } public static long gcd(long small,long large) { if(small==0) return large; return gcd(large % small,small); } public static boolean isprime(long no) { if(no<=1) return false; if(no<=3) return true; if(no%2==0 || no%3==0) return false; // 6k+1 6k+5 can be prime for(long i=5;i*i<=no;i+=6) { if(no%(i)==0 || no%(i+2)==0) return false; } return true; } // prime no smaller than or equal to n public static boolean[] prime_nos_till_no(int no) { boolean prime[]=new boolean[no+1]; // prime[i]== true means prime // prime[i]== false means not a prime // initialize prime array as true Arrays.fill(prime,true); prime[0]=false; for(int i=2;i*i<=no;i++) { if(prime[i]==true) { for(int j=i*i;j<=no;j+=i) { prime[j]=false; } } } return prime; } public static void shufflearray(long arr[]) { int n=arr.length; Random rand=new Random(); for(int i=0;i<n;i++) { long temp=arr[i]; int randomPos=i+rand.nextInt(n-i); arr[i]=arr[randomPos]; arr[randomPos]=temp; } } // Arrays.sort(arr, new Comparator<pair>() { // //@Override // public int compare(pair o1, pair o2) { // long l1=o1.a-o2.a; // if(l1<0L) return -1; // if(l1==0) return 0; // return 1; // } // }); 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 nextLine() 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 boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() throws IOException{ 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 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(); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
0a0ea071207c5569126371a1f9975d1f
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String args[]){ Scanner scan=new Scanner(System.in); int t = scan.nextInt(); while(t-->0){ int a[]=new int[2]; a[0]=scan.nextInt(); a[1]=scan.nextInt(); System.out.println(solve(a[0],a[1])); } } public static int solve(int a,int b){ if(a==0&&b==0) return 0; else{ int x=a*a,y=b*b; int t = (int)Math.sqrt(x+y); if(t*t==x+y) return 1; else return 2; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
44a0c877dabb9ce158ff55a11c33417f
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.io.*; import java.util.*; import java.text.DecimalFormat; import java.math.*; public class Main { static int mod = 1000000007; /*****************code By Priyanshu *******************************************/ 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; } } // this > other return +ve // this < other return -ve // this == other return 0 public static class Pair implements Comparable<Pair> { long st; long et; public Pair(long st, long et) { this.st = st; this.et = et; } public int compareTo(Pair other) { if (this.st != other.st) { return (int)(this.st - other.st); } else { return (int)(this.et - other.et); } } } static long fastPower(long a, long b, int n) { long res = 1; while ( b > 0) { if ( (b&1) != 0) { res = (res * a % n) % n; } a = (a % n * a % n) % n; b = b >> 1; } return res; } // function to find // the rightmost set bit static int PositionRightmostSetbit(int n) { // Position variable initialize // with 1 m variable is used to // check the set bit int position = 1; int m = 1; while ((n & m) == 0) { // left shift m = m << 1; position++; } return position; } // used for swapping ith and jth elements of array // public static void swap(int[] arr, int i, int j) { // int temp = arr[i]; // arr[i] = arr[j]; // arr[j] = temp; // } public static void swap(long i, long j) { long temp = i; i = j; j = temp; } static boolean palindrome(String s) { return new StringBuilder(s).reverse().toString().equals(s); } // static boolean isPerfectSquare(double x) // { // double sr = Math.sqrt(x); // return ((sr * sr) == x); // } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static int nod(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>=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; } // Arrays.sort(a,(c,d) -> Integer.compare(c[0],d[0])); public static boolean areAllBitsSet(int n ) { // all bits are not set if (n == 0) return false; // if true, then all bits are set if (((n + 1) & n) == 0) return true; // else all bits are not set return false; } public static long[] sort(long[] arr) { List<Long> temp = new ArrayList(); for (long i : arr) temp.add(i); Collections.sort(temp); int start = 0; for (long i : temp) arr[start++] = i; return arr; } 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; } public static void print( int arr[] ){ Arrays.stream(arr).forEach(str -> System.out.print(str + " ")); } static boolean isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x!=0 && ((x&(x-1)) == 0); } static boolean isPerfectSquare(int x) { if (x >= 0) { // Find floating point value of // square root of x. int sr = (int)Math.sqrt(x); // if product of square root // is equal, then // return T/F return ((sr * sr) == x); } return false; } public static void main( String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } FastReader sc = new FastReader(); int t = Integer.parseInt(sc.next()); // int t = 1; // StringBuilder ans = new StringBuilder(); // ArrayList<Integer> a = new ArrayList<>(); // int l = 1; while(t-->0){ // int n = sc.nextInt(); // int b = sc.nextInt(); // int x = sc.nextInt(); // int y = sc.nextInt(); // long a[] = new long[n+1]; // for(int i = 1;i<=n;i++){ // if(a[i-1] + x <= b){ // a[i] = a[i-1] + x; // }else{ // a[i] = a[i-1] -y; // } // } // long sum = 0; // for(long i:a){ // sum += i; // } // System.out.println(sum); //que 1 int x = sc.nextInt(); int y = sc.nextInt(); int val = (x*x) + (y*y); if(x == 0 && y == 0){ System.out.println("0"); }else if(isPerfectSquare(val)){ System.out.println("1"); }else{ System.out.println("2"); } } } } //code By Priyanshu
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
ddbeca850bf249424b264a483a32e748
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class tp1 { static boolean check_sq(int x, int y) { double a=x*x+y*y; return((Math.sqrt(a)-Math.floor(Math.sqrt(a))==0)); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int[] x=new int[t]; int[] y=new int[t]; for(int i=0;i<t;i++) { x[i]=sc.nextInt(); y[i]=sc.nextInt(); } for(int i=0;i<t;i++) { if(x[i]==0 && y[i]==0) { System.out.println("0"); continue; } if(x[i]==0 && y[i]!=0) { System.out.println("1"); continue; } if(x[i]!=0 && y[i]==0) { System.out.println("1"); continue; } if(check_sq(x[i], y[i])) { System.out.println("1"); } else { System.out.println("2"); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
2d85488b98316659622a26ab88568368
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static class FastReader{ BufferedReader br; StringTokenizer st; 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 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) { return this.y-o.y; } } static int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } static List primeFactors(int n){ List<Integer> ar=new ArrayList<>(); int ct=0; for(int i=2;i*i<=n;i++) { if(n%i==0) { ar.add(i); ct++; while(n%i==0) { n/=i; } } } if(n>1) { ct++; ar.add(n); } return ar; } static int lb(ArrayList<Integer>ar,int k) { int s=0; int e=ar.size(); while(s!=e) { int mid=s+e>>1; if(ar.get(mid)<k) s=mid+1; else e=mid; } if(s==ar.size()) return -1; return ar.get(s); } static long powM(long x,long y,long mod) { if(y==0) return 1; long k=powM(x,y/2,mod); if(y%2==1) { return (((((long)1*k*k)%mod)*x)%mod); } else { return (((long)1*k*k)%mod); } } static int ub(ArrayList<Integer>ar,int k) { int s=0; int e=ar.size(); while(s!=e) { int mid=s+e>>1; if(ar.get(mid)<=k) s=mid+1; else e=mid; } if(s==ar.size()) return -1; return s; } static boolean isPrime(long n) { boolean flag=true; if(n<2) flag=false; else { for(int i=2;i*i<=n;i++){ if(n%i==0) { flag=false; break; } } } return flag; } static void pArray(int a[]) { for(int i=0;i<a.length;i++) { System.out.print(a[i]+" "); } System.out.println(); } static String sort(String s) { char ch[]=s.toCharArray(); Arrays.sort(ch); return new String(ch); } // static int[] dij(int n,int src, ArrayList<Edge> ar[]) { // PriorityQueue<Pair>pq=new PriorityQueue<>(); // pq.add(new Pair(src,0)); // Set<Integer>vis=new HashSet<>(); // int dist[]=new int[n+1]; // dist[src]=0; // Arrays.fill(dist, Integer.MAX_VALUE); // // while(pq.size()>0) { // // Pair cur=pq.poll(); // if(!vis.contains(cur.x)){ // // vis.add(cur.x); // // dist[cur.x]=cur.y; // // for(Edge e:ar[cur.x]) { // if(!vis.contains(e.dest)&&dist[e.dest]>cur.y+e.w ) // pq.add(new Pair(e.dest,cur.y+e.w)); // } // } // } // return dist; // } // public static String addCharToString(String str, char c, int pos) { StringBuffer stringBuffer = new StringBuffer(str); stringBuffer.insert(pos, c); return stringBuffer.toString(); } static int BigMod(String num, int a) { int res = 0; for (int i = 0; i < num.length(); i++) res = (res * 10 + (int)num.charAt(i)); return res; } static boolean isSquare(int n) { for(int i=1;i*i<=n;i++) { if((i*i)==n) return true; } return false; } public static void main(String[] args) { try { FastReader sc = new FastReader(); int t=sc.nextInt(); while(t-->0) { int x=sc.nextInt(); int y=sc.nextInt(); if(x==0&&y==0) { System.out.println("0"); continue; } if(isSquare((x*x)+(y*y))) System.out.println("1"); else System.out.println("2"); } }catch(Exception e) {return;} } } //https://www.codechef.com/MP3TO401?order=desc&sortBy=successful_submissions
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
73c8006b88829c26085209391734c724
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class integermovesmar22{ public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); for(int i = 0 ; i < n ; i++){ int a = scn.nextInt(); int b = scn.nextInt(); checkPossibleMove(a,b); } } public static void checkPossibleMove(int a , int b){ if(a == 0 && b == 0) System.out.println('0'); else if(Math.sqrt(a*a+b*b)%1==0){ System.out.println("1"); } else{ System.out.println("2"); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
b765b876fefcd7593fc7e5dfb1309d22
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
//not all import are used to solve every problem .. but these are the most important one import java.io.DataInputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Random; public class CodeforcesEducationalRound_125_A { @SuppressWarnings("FieldCanBeLocal") private static Reader in; private static PrintWriter out; private static void solve() throws IOException { //Your Code Goes Here; int n = in.nextInt(), m = in.nextInt(); int k = 0, l = 0; double ans = Math.sqrt(Math.pow(k-n, 2) + Math.pow(l-m, 2)); int ansTwo = (int)ans; if(n == 0 && m == 0){ System.out.println(0); } else if(ans == ansTwo){ System.out.println(1); } else{ System.out.println(2); } } public static void main(String[] args) throws IOException { //FastScaner fs = new FastScaner();//There is a class below .. uncomment that class to instantiate an object from that class; //int t = fs.nextInt();//uncomment this line when you're using the fastscaner class; in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int T = in.nextInt(); while(T-->0){ solve(); } out.flush(); in.close(); out.close(); } static final double INF = 1e18; static final Random random = new Random(); static final int mod = 1_000_000_007; //Taken From "Second Thread" static void ruffleSort(int[] a){ int n = a.length;//shuffles, then sort; for(int i=0; i<n; i++){ int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } sort(a); } public static boolean primeFinder(int n){ int m = 0; int flag = 0; m = n / 2; if(n == 0 ||n == 1){ return false; } else{ for(int i=2;i<=m;i++){ if(n % i == 0){ return false; } } return true; } } private static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int)n + 1]; for (int i = 0; i <= n; i++) { prime[i] = true; } for (long p = 2; p * p <= n; p++) { if (prime[(int)p] == true) { for (long i = p * p; i <= n; i += p) prime[(int)i] = false; } } return prime; } private static long add(long a, long b){ return (a + b) % mod; } private static int gcd(int a, int b) { if (a == 0 || b == 0) return 0; while (b != 0) { int tmp; tmp = a % b; a = b; b = tmp; } return a; } private static long lcm(long a, long b){ return (a / gcd((int) a, (int) b) * b); } private 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[][] prefixSum( int n , int m , int[][] arr){ int[][] prefixSum = new int[n+1][m+1]; for( int i = 1 ;i <= n ;i++) { for( int j = 1 ; j<= m ; j++) { int toadd = 0; if( arr[i-1][j-1] == 1) { toadd = 1; } prefixSum[i][j] = toadd + prefixSum[i][j-1] + prefixSum[i-1][j] - prefixSum[i-1][j-1]; } } return prefixSum; } private static int sumOfArrayElements(int[] arr){ int sum = 0; // Initialize sum ; //Iterate through all elements and add them to sum; for(int i=0;i<arr.length;i++){ sum += arr[i]; } return sum; } //call this method when you want to read an integer array; private static int[] readArray(int len) throws IOException{ int[] a = new int[len]; for(int i=0;i<len;i++)a[i] = in.nextInt(); return a; } //call this method when you want to read an Long array; private static long[] readLongArray(int len) throws IOException{ long[] a = new long[len]; for(int i=0;i<len;i++) a[i] = in.nextLong(); return a; } //call this method to print the integer array; private static void printArray(int[] array){ for(int now : array) out.print(now);out.print(' ');out.close(); } //call this method to print the long array; private static void printLongArray(long[] array){ for(long now:array) out.print(now); out.print(' '); out.close(); } /*Another way of Reading input...collected from a online blog from here => https://codeforces.com/contest/1625/submission/144334744;*/ static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() {//Constructor; din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException {//To take user input for String values; final byte[] buf = new byte[1024]; // 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 nextSign() throws IOException {//For taking the signs like plus or minus ... byte c = read(); while ('+' != c && '-' != c) { c = read(); } return '+' == c ? 0 : 1; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final 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(); } final 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(); } final 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 { din.close(); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
e41a59ed7380d3b88fb0d6dbb6bd5cd3
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class cf2 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T=sc.nextInt(); while(T-->0){ int x=sc.nextInt(); int y=sc.nextInt(); double distance=Math.sqrt(Math.pow(0-x, 2)+Math.pow(0-y, 2)); if(x == 0 && y == 0){ System.out.println(0); }else if(distance == (int)distance){ System.out.println(1); }else{ System.out.println(2); } } sc.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
931b7719e76d6ea2e3806e9d622cb230
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { private static int solve(int x, int y){ if (x == 0 && y == 0) return 0; if (x == 0 || y == 0 || isSquare(x, y)) return 1; return 2; } private static boolean isSquare(int x, int y) { int temp = (int)(Math.pow(x, 2) + Math.pow(y, 2)); return (int)Math.pow((int)Math.sqrt(temp), 2) == temp; } public static void main(String args[]) { FastReader fs = new FastReader(); int t = fs.nextInt(); while(t-- >0) { int x = fs.nextInt(); int y = fs.nextInt(); System.out.println(solve(x, y)); } } } class FastReader{ BufferedReader br; StringTokenizer st; 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[] nextArr(int n){ int[] a = new int[n]; for(int i=0; i<n; i++){ a[i] = nextInt(); } return a; } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
ef227e2fe1b2184a63601f8399c4c418
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class read { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0) { int a = s.nextInt(); int b = s.nextInt(); boolean check = true; if(a==0 && b==0) { System.out.println("0"); check = false; } if(check) { double c = Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)); if(c == (int)c) { System.out.println("1"); } else { System.out.println("2"); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 11
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
93b45695e18509ebd78c7dbf0743d675
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class cp1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); for (int tt = 0; tt < t; tt++) { int x =sc.nextInt(); int y =sc.nextInt(); double k = x*x+y*y; double z = Math.sqrt(k); if(x==0 &&y==0){ System.out.println("0"); continue; } if( x==0 ||y==0){ System.out.println("1"); continue; } if(isInteger(z)){ System.out.println("1"); }else{ System.out.println("2"); } } sc.close(); } private static boolean isInteger(double x) { if(Math.floor(x)==x){ return true; } return false; } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
731e664f5f0c97b1a2959ca38a41474f
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class integerMoves { public static void p(Object o) { PrintWriter p = new PrintWriter(System.out); p.println(o); p.flush(); } public static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int testCases = sc.nextInt(); while (testCases --> 0) { int x = sc.nextInt() , y = sc.nextInt() , xy = (x*x)+(y*y) , z = (int) Math.sqrt(xy); p( (x== 0 && y == 0) ? 0 : xy == z*z ? 1 : 2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
dadd2dce373cd3c2186f7bab71b71dff
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class code { public static void main(String args[]){ Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0){ int x = s.nextInt(); int y = s.nextInt(); double d1 = x*x+y*y; if(d1==0){ System.out.println(0); }else{ int val = (int)Math.sqrt(d1); if(val*val==d1){ System.out.println(1); }else{ System.out.println(2); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
ddddd2d4bf90c125ab43d1aca03c0030
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
// package com.sameer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int T= fs.nextInt(); for (int tt=0; tt<T; tt++) { int x = fs.nextInt(); int y = fs.nextInt(); double distance = Math.sqrt(x * x + y * y); if (distance != (int)distance) { out.println(2); } else if (distance == 0) { out.println(0); } else { out.println(1); } } out.close(); } static final Random random=new Random(); static final int mod=1_000_000_007; 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 long add(long a, long b) { return (a+b)%mod; } static long sub(long a, long b) { return ((a-b)%mod+mod)%mod; } static long mul(long a, long b) { return (a*b)%mod; } static long exp(long base, long exp) { if (exp==0) return 1; long half=exp(base, exp/2); if (exp%2==0) return mul(half, half); return mul(half, mul(half, base)); } static long[] factorials=new long[2_000_001]; static long[] invFactorials=new long[2_000_001]; static void precompFacts() { factorials[0]=invFactorials[0]=1; for (int i=1; i<factorials.length; i++) factorials[i]=mul(factorials[i-1], i); invFactorials[factorials.length-1]=exp(factorials[factorials.length-1], mod-2); for (int i=invFactorials.length-2; i>=0; i--) invFactorials[i]=mul(invFactorials[i+1], i+1); } static long nCk(int n, int k) { return mul(factorials[n], mul(invFactorials[k], invFactorials[n-k])); } 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()); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
956180563386c5d1ecb1758ca6012403
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; import static java.lang.System.*; import static java.util.Arrays.*; import static java.util.stream.IntStream.iterate; public class Template { private static final FastScanner scanner = new FastScanner(); private static void solve() { int a = i(), b = i(); if (a == 0 && b == 0) { out.println(0); } else { int x = (a*a+b*b), sqrt = (int) sqrt(x); if (sqrt*sqrt == x) out.println(1); else out.println(2); } } private static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void main(String[] args) { int t = i(); while (t-->0) { solve(); } } private static long fac(int n) { long res = 1; for (int i = 2; i<=n; i++) { res*=i; } return res; } private static BigInteger factorial(int n) { BigInteger res = BigInteger.valueOf(1); for (int i = 2; i <= n; i++){ res = res.multiply(BigInteger.valueOf(i)); } return res; } private static long l() { return scanner.nextLong(); } private static int i() { return scanner.nextInt(); } private static String s() { return scanner.next(); } private static void yes() { out.println("YES"); } private static void no() { out.println("NO"); } private static int toInt(char c) { return Integer.parseInt(c+""); } private static void printArray(long[] a) { StringBuilder builder = new StringBuilder(); for (long i : a) builder.append(i).append(' '); out.println(builder); } private static void printArray(int[] a) { StringBuilder builder = new StringBuilder(); for (int i : a) builder.append(i).append(' '); out.println(builder); } private static int binPow(int a, int n) { if (n == 0) return 1; if (n % 2 == 1) return binPow(a, n-1) * a; else { int b = binPow(a, n/2); return b * b; } } private static boolean isPrime(long n) { return iterate(2, i -> (long) i * i <= n, i -> i + 1).noneMatch(i -> n % i == 0); } private static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } private static void stableSort(int[] a) { List<Integer> list = stream(a).boxed().sorted().toList(); setAll(a, list::get); } private static int getKthMax(int[] a, int low, int high, int k) { int pivot = low; for (int j = low; j < high; j++) { if (a[j] <= a[high]) { swap(a, pivot++, j); } } swap(a, pivot, high); int count = high - pivot + 1; if (count == k) return a[pivot]; if (count > k) return getKthMax(a, pivot + 1, high, k); return getKthMax(a, low, pivot - 1, k - count); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(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[] readLong(int n) { long[] a = new long[n]; for (int i = 0; i<n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } static class SegmentTreeRMXQ { static int getMid(int s, int e) { return s + (e - s) / 2; } static int MaxUtil(int[] st, int ss, int se, int l, int r, int node) { if (l <= ss && r >= se) return st[node]; if (se < l || ss > r) return -1; int mid = getMid(ss, se); return max( MaxUtil(st, ss, mid, l, r, 2 * node + 1), MaxUtil(st, mid + 1, se, l, r, 2 * node + 2)); } static void updateValue(int[] arr, int[] st, int ss, int se, int index, int value, int node) { if (index < ss || index > se) { System.out.println("Invalid Input"); return; } if (ss == se) { arr[index] = value; st[node] = value; } else { int mid = getMid(ss, se); if (index <= mid) updateValue(arr, st, ss, mid, index, value, 2 * node + 1); else updateValue(arr, st, mid + 1, se, index, value, 2 * node + 2); st[node] = max(st[2 * node + 1], st[2 * node + 2]); } } static int getMax(int[] st, int n, int l, int r) { if (l < 0 || r > n - 1 || l > r) { System.out.print("Invalid Input\n"); return -1; } return MaxUtil(st, 0, n - 1, l, r, 0); } static int constructSTUtil(int[] arr, int ss, int se, int[] st, int si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } int mid = getMid(ss, se); st[si] = max( constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2)); return st[si]; } static int[] constructST(int[] arr, int n) { int x = (int)Math.ceil(Math.log(n) / Math.log(2)); int max_size = 2 * (int)Math.pow(2, x) - 1; int[] st = new int[max_size]; constructSTUtil(arr, 0, n - 1, st, 0); return st; } } static class SegmentTreeRMNQ { int[] st; int minVal(int x, int y) { return min(x, y); } int getMid(int s, int e) { return s + (e - s) / 2; } int RMQUtil(int ss, int se, int qs, int qe, int index) { if (qs <= ss && qe >= se) return st[index]; if (se < qs || ss > qe) return Integer.MAX_VALUE; int mid = getMid(ss, se); return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); } int RMQ(int n, int qs, int qe) { if (qs < 0 || qe > n - 1 || qs > qe) { System.out.println("Invalid Input"); return -1; } return RMQUtil(0, n - 1, qs, qe, 0); } int constructSTUtil(int[] arr, int ss, int se, int si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } int mid = getMid(ss, se); st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), constructSTUtil(arr, mid + 1, se, si * 2 + 2)); return st[si]; } void constructST(int[] arr, int n) { int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); int max_size = 2 * (int) Math.pow(2, x) - 1; st = new int[max_size]; // allocate memory constructSTUtil(arr, 0, n - 1, 0); } } static class SegmentTreeRSQ { int[] st; // The array that stores segment tree nodes /* Constructor to construct segment tree from given array. This constructor allocates memory for segment tree and calls constructSTUtil() to fill the allocated memory */ SegmentTreeRSQ(int[] arr, int n) { // Allocate memory for segment tree //Height of segment tree int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); //Maximum size of segment tree int max_size = 2 * (int) Math.pow(2, x) - 1; st = new int[max_size]; // Memory allocation constructSTUtil(arr, 0, n - 1, 0); } // A utility function to get the middle index from corner indexes. int getMid(int s, int e) { return s + (e - s) / 2; } /* A recursive function to get the sum of values in given range of the array. The following are parameters for this function. st --> Pointer to segment tree si --> Index of current node in the segment tree. Initially 0 is passed as root is always at index 0 ss & se --> Starting and ending indexes of the segment represented by current node, i.e., st[si] qs & qe --> Starting and ending indexes of query range */ int getSumUtil(int ss, int se, int qs, int qe, int si) { // If segment of this node is a part of given range, then return // the sum of the segment if (qs <= ss && qe >= se) return st[si]; // If segment of this node is outside the given range if (se < qs || ss > qe) return 0; // If a part of this segment overlaps with the given range int mid = getMid(ss, se); return getSumUtil(ss, mid, qs, qe, 2 * si + 1) + getSumUtil(mid + 1, se, qs, qe, 2 * si + 2); } /* A recursive function to update the nodes which have the given index in their range. The following are parameters st, si, ss and se are same as getSumUtil() i --> index of the element to be updated. This index is in input array. diff --> Value to be added to all nodes which have I in range */ void updateValueUtil(int ss, int se, int i, int diff, int si) { // Base Case: If the input index lies outside the range of // this segment if (i < ss || i > se) return; // If the input index is in range of this node, then update the // value of the node and its children st[si] = st[si] + diff; if (se != ss) { int mid = getMid(ss, se); updateValueUtil(ss, mid, i, diff, 2 * si + 1); updateValueUtil(mid + 1, se, i, diff, 2 * si + 2); } } // The function to update a value in input array and segment tree. // It uses updateValueUtil() to update the value in segment tree void updateValue(int arr[], int n, int i, int new_val) { // Check for erroneous input index if (i < 0 || i > n - 1) { System.out.println("Invalid Input"); return; } // Get the difference between new value and old value int diff = new_val - arr[i]; // Update the value in array arr[i] = new_val; // Update the values of nodes in segment tree updateValueUtil(0, n - 1, i, diff, 0); } // Return sum of elements in range from index qs (query start) to // qe (query end). It mainly uses getSumUtil() int getSum(int n, int qs, int qe) { // Check for erroneous input values if (qs < 0 || qe > n - 1 || qs > qe) { System.out.println("Invalid Input"); return -1; } return getSumUtil(0, n - 1, qs, qe, 0); } // A recursive function that constructs Segment Tree for array[ss..se]. // si is index of current node in segment tree st int constructSTUtil(int arr[], int ss, int se, int si) { // If there is one element in array, store it in current node of // segment tree and return if (ss == se) { st[si] = arr[ss]; return arr[ss]; } // If there are more than one elements, then recur for left and // right subtrees and store the sum of values in this node int mid = getMid(ss, se); st[si] = constructSTUtil(arr, ss, mid, si * 2 + 1) + constructSTUtil(arr, mid + 1, se, si * 2 + 2); return st[si]; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
77a9cadd1a5dc758157f533cf0cb8822
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-- > 0){ int y = sc.nextInt(); int x = sc.nextInt(); int i = (x*x)+(y*y); int j = (int)Math.sqrt(i); if(x == 0 && y == 0){ System.out.println(0); }else if(j*j == i){ System.out.println(1); }else{ System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
399201ca3d6515e3e0fa7479a976fec7
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.Scanner; public class myjava{ public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t--!=0) { int x = sc.nextInt(); int y = sc.nextInt(); int sumofsqr = x*x + y*y; int sqr = (int)Math.sqrt(sumofsqr); if(x==0 && y==0) { System.out.println("0"); } else if(sumofsqr==(sqr*sqr)) { System.out.println("1"); } else { System.out.println("2"); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 17
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
1c81d3e0c02ae9ae6ce6afcc7781ae24
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.util.Scanner; import java.io.*; public class main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t; t=sc.nextInt(); while(t-->0) { int x=sc.nextInt(); int y=sc.nextInt(); double z= Math.sqrt(Math.pow(0-x,2)+Math.pow(0-y,2)); if(x==0&&y==0) { System.out.println(0); } else if(z==(int)z)System.out.println(1); else System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
05aacabc51a6d44220ac6cce6e0a4203
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class Moves { public static void main(String[] args) throws Exception{ Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); int x,y; double sqrt; while(t-->0){ x=scanner.nextInt(); y=scanner.nextInt(); sqrt=Math.sqrt(x*x+y*y); if(x==0&&y==0){ System.out.println(0); } else if((int)sqrt==Math.ceil(sqrt)){ System.out.println(1); }else System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
5cbda5f9d664396fec8cddfcea202c3f
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class IntegerMoves { 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 fr = new FastReader(); int T = fr.nextInt(); while(T--!= 0) { int a = fr.nextInt(); int b = fr.nextInt(); int sum = (int)Math.sqrt(a * a + b * b); if( sum > 0) { if (sum * sum == (a * a + b * b)) { System.out.println("1"); } else { System.out.println("2"); } } else { System.out.println("0"); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
056ff54e38bde82984f80a7308ae4676
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { FastReader sc = new FastReader(); int T = sc.nextInt(); while(T-- != 0) { int a = sc.nextInt(); int b = sc.nextInt(); int sum = (int)Math.sqrt(a*a + b*b); if(sum > 0) { if ((sum*sum) == (a*a + b*b)) { System.out.println("1"); } else { System.out.println("2"); } } else { System.out.println("0"); } } } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
c7c5fab98f39418f15d49a2b66680969
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class codeforces1657A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); for (int i = 0; i<numCases;i++) { StringTokenizer st = new StringTokenizer(br.readLine()); int X = Integer.parseInt(st.nextToken()); int Y = Integer.parseInt(st.nextToken()); if (X>0 || Y>0) { if (X==0 || Y==0) { System.out.println("1"); } else { int distance = (int) (Math.pow(X,2)+Math.pow(Y,2)); boolean bo = false; for (int a = 2; a<=71;a++) { if(a*a == distance) { bo = true; break; } } if (bo) { System.out.println("1"); } else { System.out.println("2"); } } } else { System.out.println("0"); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
0e30dce7ef5824e039ad4cb49c3a1862
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-- > 0) { int x = in.nextInt(); int y = in.nextInt(); int a = (int) (Math.pow(x, 2) + Math.pow(y, 2)); if(x == 0 && y == 0) System.out.println(0); else if((int)Math.sqrt(a) * (int)Math.sqrt(a) == a) System.out.println(1); else System.out.println(2); } } public static void sort(int[] arr){ ArrayList<Integer> ls = new ArrayList<>(); for(int x : arr){ ls.add(x); } Collections.sort(ls); for(int i = 0;i < arr.length;i++){ arr[i] = ls.get(i); } } public static int binSearch(int[] arr,int a){ int l = 0; int r = arr.length-1; int mid = 0; while (l <= r){ if(arr[mid] > a){ r = mid - 1; } else{ l = mid + 1; } mid = (r+l)/2; } return l; } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
5596cfb97d2109bf2c2f6a8d9c74eb70
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.math.BigDecimal; import java.util.*; public class Example{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int x = sc.nextInt(); int y = sc.nextInt(); if (x == 0 && y == 0) { System.out.println(0); continue; } double c = Math.sqrt(Math.pow(x, 2) + Math.pow(y,2)); int i = BigDecimal.valueOf(c).scale(); if (i == 1) { System.out.println(1); } else { System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
c5a7ed2b611e6352c1ce5b70cef57494
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st; int t = Integer.parseInt(br.readLine()); while (t --> 0) { st = new StringTokenizer(br.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); if (x == 0 && y == 0) { pw.println(0); } else if (x == 0 || y == 0) { pw.println(1); } else if ((int) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) == (double) Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))) { pw.println(1); } else { pw.println(2); } } pw.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
c7ef3b7779bd0a62fd7d8562cf9a3dec
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; public class A { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); in.nextLine(); Set<Integer> squares = new HashSet<>(); for (int a = 1; a <= 250; a++) { squares.add(a*a); } while (n-- > 0) { int x = in.nextInt(); int y = in.nextInt(); in.nextLine(); ArrayDeque<List<Integer>> queue = new ArrayDeque<>(); if (x == 0 && y == 0) { out.println(0); } else if (squares.contains(x*x+y*y)) { out.println(1); } else { out.println(2); } } out.close(); in.close(); } } // 4 => 0&2 // 9 => 0&3 // 9 => 0&3 // 16 => 0&4
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
9225853ca70586211b122f8f296cfe31
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.TreeSet; import java.util.TreeMap; import java.util.PriorityQueue; import java.util.Collections; import java.util.Stack; import java.math.BigInteger; import java.util.LinkedList; import java.util.Iterator; public class First { public static void main(String[] args) { FastScanner fs = new FastScanner(); int T = fs.nextInt(); set=new HashSet<>(); for(int i=1;i<=100;++i) { for(int j=1;j<=100;++j) { double val = Math.sqrt((i*i)+(j*j)); double ceil = Math.ceil(val); double floor = Math.floor(val); if(ceil==floor) { set.add((int)(val*val)); } } } // System.out.println(set); for (int tt = 0; tt < T; tt++) { solve(fs); } } static HashSet<Integer> set; static void solve(FastScanner fs) { int x=fs.nextInt(), y=fs.nextInt(); if(x==0 && y==0) { pn(0); return; } if(x==0 || y==0 || set.contains((x*x)+(y*y))) { pn(1); } else pn(2); } static long MOD=(long)(1e9+7); static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void pn(Object o) { System.out.println(o); } static void p(Object o) { System.out.print(o); } static void flush() { System.out.flush(); } static void debugInt(int[] arr) { for(int i=0;i<arr.length;++i) System.out.print(arr[i]+" "); System.out.println(); } static void debugIntInt(int[][] arr) { for(int i=0;i<arr.length;++i) { for(int j=0;j<arr[0].length;++j) System.out.print(arr[i][j]+" "); System.out.println(); } System.out.println(); } static void debugLong(long[] arr) { for(int i=0;i<arr.length;++i) System.out.print(arr[i]+" "); System.out.println(); } static void debugLongLong(long[][] arr) { for(int i=0;i<arr.length;++i) { for(int j=0;j<arr[0].length;++j) System.out.print(arr[i][j]+" "); System.out.println(); } System.out.println(); } static long[] takeLong(int n, FastScanner fs) { long[] arr=new long[n]; for(int i=0;i<n;++i) arr[i]=fs.nextLong(); return arr; } static long[][] takeLongLong(int m, int n, FastScanner fs) { long[][] arr=new long[m][n]; for(int i=0;i<m;++i) for(int j=0;j<n;++j) arr[i][j]=fs.nextLong(); return arr; } static int[] takeInt(int n, FastScanner fs) { int[] arr=new int[n]; for(int i=0;i<n;++i) arr[i]=fs.nextInt(); return arr; } static int[][] takeIntInt(int m, int n, FastScanner fs) { int[][] arr=new int[m][n]; for(int i=0;i<m;++i) for(int j=0;j<n;++j) arr[i][j]=fs.nextInt(); return arr; } 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 int getDecimalFromBinary(String s) { long no=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='1') no++; no=no<<1; } return (int)(no>>1); } static String getBinaryFromDecimal(int x) { StringBuilder sb=new StringBuilder(); for(int i=0;i<31;++i) { if((x&1)==0) sb.append('0'); else sb.append('1'); x=x>>1; } return sb.reverse().toString(); } static boolean[] sieve() { int size=(int)(1e5+5); boolean[] isPrime=new boolean[size]; Arrays.fill(isPrime, true); for(int i=2;i<size;++i) for(int j=2*i;isPrime[i]==true && j<size;j+=i) isPrime[j]=false; return isPrime; } 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()); } long nextLong() { return Long.parseLong(next()); } } } class Pair { }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
3f8e9d827543a565aceee7ce536fbd2e
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.util.stream.Collectors; import java.io.*; import java.math.*; public class ER125_A{ public static FastScanner sc; public static PrintWriter pw; public static StringBuilder sb; public static int MOD= 1000000007; public 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()); } } public static void printList(List<Long> al) { System.out.println(al.stream().map(it -> it.toString()).collect(Collectors.joining(" "))); } public static void printList(Deque<Long> al) { System.out.println(al.stream().map(it -> it.toString()).collect(Collectors.joining(" "))); } public static void printArr(long[] arr) { System.out.println(Arrays.toString(arr).trim().replace("[", "").replace("]","").replace(","," ")); } 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 void decreasingOrder(ArrayList<Long> al) { Comparator<Long> c = Collections.reverseOrder(); Collections.sort(al,c); } public static boolean[] sieveOfEratosthenes(int n) { boolean isPrime[] = new boolean[n+1]; Arrays.fill(isPrime, true); isPrime[0]=false; isPrime[1]=false; for(int i=2;i*i<n;i++) { for(int j=2*i;j<n;j+=i) { isPrime[j]=false; } } return isPrime; } public static long nCr(long N, long R) { double result=1; for(int i=1;i<=R;i++) result=((result*(N-R+i))/i); return (long) result; } public static long fastPow(long a, long b, int n) { long result=1; while(b>0) { if((b&1)==1) result=(result*a %n)%n; a=(a%n * a%n)%n; b>>=1; } return result; } public static int BinarySearch(long[] arr, long key) { int low=0; int high=arr.length-1; while(low<=high) { int mid=(low+high)/2; if(arr[mid]==key) return mid; else if(arr[mid]>key) high=mid-1; else low=mid+1; } return low; //High=low-1 } public static void solve(int t) { double x=sc.nextInt(); double y=sc.nextInt(); // 0,0 --> 0 // root(x^2 + y^2) perfect square -->1 // else -->2 if(x==0 && y==0) { System.out.println(0); } else { double temp=Math.sqrt((double)(x*x) +(double)(y*y)); if(temp==(int) temp) { System.out.println(1); } else System.out.println(2); } } public static void main(String[] args) { sc = new FastScanner(); pw = new PrintWriter(new OutputStreamWriter(System.out)); sb= new StringBuilder(""); int t=sc.nextInt(); for(int i=1;i<=t;i++) solve(i); System.out.println(sb); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
403aac08b82cc2cca41d29774314f3a4
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static FastReader scan = new FastReader(); // static Scanner scan= new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int n = scan.nextInt();while (n-->0) A(); out.close(); } static void A(){ int n = scan.nextInt(); int m = scan.nextInt(); if(n==0 && m==0) out.println(0); else if(asd(n,m)==0) out.println(1); else out.println(2); } static int asd(int a , int b){ int m = a*a + (b*b); int s = (int)Math.sqrt(m); if(m == s*s)return 0; return -1; } } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
4b0e099fab4c72485fc5df27822f86e2
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class IntegerMoves { public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); HashSet<Integer> hs = new HashSet<>(); for(int i=0; i<=100 ;i++) hs.add((int)Math.pow(i,2)); while(t-->0){ int x = sc.nextInt() , y = sc.nextInt(); int z = (int) Math.pow(x , 2) + (int) Math.pow(y,2); if(hs.contains(z)){ if(x == 0 && y == 0) pw.println(0); else pw.println(1); } else pw.println(2); } pw.flush(); } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
903af2fe0a61f2c441493b44b0f769c0
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class IntegerMoves { public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } 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 x = sc.nextInt() , y = sc.nextInt(); int z = (int) Math.sqrt(x*x + y*y); if(x == 0 && y == 0) pw.println(0); else if(z*z == x*x+y*y) pw.println(1); else pw.println(2); } pw.flush(); } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
5912321e326301ebfdc16bc265a17214
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args) { new Thread(null, new Main(), "", 256 * (1L << 20)).start(); } public void run() { try { long t1 = System.currentTimeMillis(); if (System.getProperty("ONLINE_JUDGE") != null) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } Locale.setDefault(Locale.US); solve(); in.close(); out.close(); long t2 = System.currentTimeMillis(); System.err.println("Time = " + (t2 - t1)); } catch (Throwable t) { t.printStackTrace(System.err); System.exit(-1); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } void solveTest() throws IOException { int x2 = readInt(); int y2 = readInt(); int x1 = 0; int y1 = 0; int[] roots = new int[]{4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481,3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329,}; int interior = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); boolean found = false; if (interior == 0) { out.println(0); return; } if (x2 == 0 || y2 == 0) { out.println(1); return; } for (int i = 0; i < roots.length; i++) { if (interior == roots[i]) { out.println(1); return; } } out.println(2); } void solve() throws IOException { int testCases = readInt(); for (int tests = 0; tests < testCases; tests++) { solveTest(); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
fe6da97354d4d2d19805d1f097250a8c
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class PyTriplets { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ int x=sc.nextInt(); int y=sc.nextInt(); if(x==0 && y==0) System.out.println(0); else if(x==0 && y!=0) System.out.println(1); else if(x!=0 && y==0) System.out.println(1); else{ double sum=Math.sqrt(x*x+y*y); if(Math.floor(sum)==sum) System.out.println(1); else System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
538f5197b44d372736d6c22d624e43f2
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class CodeForces { public static void main(String[] args) throws FileNotFoundException { FastScanner fs = new FastScanner(); int tt = fs.nextInt(); while(tt-- > 0) { int x = fs.nextInt(), y = fs.nextInt(); if(x == 0 && y == 0) { System.out.println(0); }else { double d = Math.sqrt(x*x + y*y); if(d == (int)d && d*d == (x*x + y*y)) { System.out.println(1); }else { System.out.println(2); } } } } public static int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a%b); } 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()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
07f113254c9d931cf224a23304097e2f
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ /* Template created by Jabra Ram - @hack41 */ public class Solution { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int t = Integer.parseInt(s); while(t-->0){ // int n = Integer.parseInt(br.readLine()); String [] str = br.readLine().split(" "); // String [] array = br.readLine().split(" "); int n = Integer.parseInt(str[0]); int m = Integer.parseInt(str[1]); // int b = Integer.parseInt(str[2]); // int [] arr1 = new int[n]; // int [] arr2 = new int[n]; // for(int i=0;i<n;i++){ // arr1[i] = Integer.parseInt(str[i]); // arr2[i] = Integer.parseInt(array[i]); // } if(n==0 && m==0){ System.out.println(0); } else if((int)Math.sqrt(n*n + m*m)*(int)Math.sqrt(n*n + m*m) == n*n + m*m){ System.out.println(1); } else { System.out.println(2); } } } public static int gcd(int a, int b){ if(b>a){ return gcd(b,a); } if(b==0) return a; return gcd(b, a%b); } public static long factMod(int n, int mod){ long ans = 1; for(long i=1;i<=n/2;i++){ ans = ans*i*i%mod; ans = ans%mod; } return ans; } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
4fb2b7b7c4c72adbd35403f49ace8aec
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.util.*; public class Main implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args) { new Thread(null, new Main(), "", 256 * (1L << 20)).start(); } public void run() { try { long t1 = System.currentTimeMillis(); if (System.getProperty("ONLINE_JUDGE") != null) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } Locale.setDefault(Locale.US); solve(); in.close(); out.close(); long t2 = System.currentTimeMillis(); System.err.println("Time = " + (t2 - t1)); } catch (Throwable t) { t.printStackTrace(System.err); System.exit(-1); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } void solve() throws IOException { int n = readInt(); ArrayList<Integer> squares = new ArrayList<>(); for(int i = 0; i < n; i++) { int x = readInt(), y = readInt(), moves = 0; findSquares(squares, x, y); int squareDistance = x * x + y * y; if(squareDistance == 0) out.print("0\n"); else if(x == 0 || y == 0) out.print("1\n"); else if(squares.contains(squareDistance)) out.print("1\n"); else out.print("2\n"); } } int binarySearch(ArrayList<Integer> arr, int x) { int l = 0, r = arr.size() - 1, smallest = arr.get(arr.size() - 1); while (l <= r) { int m = l + (r - l) / 2; if (arr.get(m) == x) return m; if (arr.get(m) < x) { smallest = m; l = m + 1; } else { r = m - 1; } } return smallest; } void findSquares(ArrayList<Integer> squares, int x, int y) { int max = x * x + y * y; int squareSizePrev = squares.size(); for(int square = 0, i = squareSizePrev; square <= max; i++) { square = i * i; squares.add(square); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
998533dbd2c37aff0093d36ca0b84dd4
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.PrintWriter; import java.util.Scanner; public class A { public void solve(Scanner in, PrintWriter out) { int t = in.nextInt(); for (int c = 0; c < t; c++) { int goalI = in.nextInt(); int goalJ = in.nextInt(); int result; if (goalI == 0 && goalJ == 0) { result = 0; } else { double distance = Math.sqrt(goalI * goalI + goalJ * goalJ); if ((int) distance == distance) { result = 1; } else { result = 2; } } out.println(result); } } public void run() { try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out)) { solve(in, out); } } public static void main(String[] args) { new A().run(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
a41169008a571cef68ae19958f35b126
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class Solution{ static Scanner sc = new Scanner(System.in); public static void main(String args[]){ int t = sc.nextInt(); while(t-- > 0){ int x = sc.nextInt(), y = sc.nextInt(); int d = x * x + y * y; int moves = 0; if(x != 0 || y != 0) if((int)Math.sqrt(d) * (int)Math.sqrt(d) == d) moves = 1; else moves = 2; System.out.println(moves); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
dcf67d64d7e80cd3b150d922e649df44
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class cf { public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stz; double T = Integer.parseInt(br.readLine()); while(T-->0) { stz = new StringTokenizer(br.readLine()); int x = Integer.parseInt(stz.nextToken()); int y = Integer.parseInt(stz.nextToken()); if(x==0 && y==0) { System.out.println("0"); } else { int p = x*x; int q = y*y; int ans = (int)Math.sqrt(p+q); if(ans*ans == p+q) { System.out.println("1"); } else { System.out.println("2"); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
cccef9d2404e088387283a52bd85f1e2
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.lang.*; import java.io.InputStreamReader; import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.File; import java.io.PrintStream; import java.io.PrintWriter; import java.math.BigInteger; public class Main { /* 10^(7) = 1s. * ceilVal = (a+b-1) / b */ static final int mod = 1000000007; static final long temp = 998244353; static final long MOD = 1000000007; static final long M = (long)1e9+7; static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair ob) { return (int)(first - ob.first); } } static class Tuple implements Comparable<Tuple> { long first, second,third; public Tuple(long first, long second, long third) { this.first = first; this.second = second; this.third = third; } public int compareTo(Tuple o) { return (int)(o.third - this.third); } } public static class DSU { int count = 0; int[] parent; int[] rank; public DSU(int n) { count = n; parent = new int[n]; rank = new int[n]; Arrays.fill(parent, -1); Arrays.fill(rank, 1); } public int find(int i) { return parent[i] < 0 ? i : (parent[i] = find(parent[i])); } public void union(int a, int b) //Union Find by Rank { a = find(a); b = find(b); if(a == b) return; if(rank[a] < rank[b]) { parent[a] = b; } else if(rank[a] > rank[b]) { parent[b] = a; } else { parent[b] = a; rank[a] = 1 + rank[a]; } count--; } public int countConnected() { return count; } } static class Reader { 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) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] longReadArray(int n) throws IOException { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static long lcm(long a, long b) { return (a / LongGCD(a, b)) * b; } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static long LongLCM(long a, long b) { return (a / LongGCD(a, b)) * b; } //Count the number of coprime's upto N public static long phi(long n) //euler totient/phi function { long ans = n; // for(long i = 2;i*i<=n;i++) // { // if(n%i == 0) // { // while(n%i == 0) n/=i; // ans -= (ans/i); // } // } // // if(n > 1) // { // ans -= (ans/n); // } for(long i = 2;i<=n;i++) { if(isPrime(i)) { ans -= (ans/i); } } return ans; } public static long fastPow(long x, long n) { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } public 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; } static long modInverse(long n, long p) { return powMod(n, p - 2, p); } // Returns nCr % p using Fermat's little theorem. public static long nCrModP(long n, long r,long p) { if (n<r) return 0; if (r == 0) return 1; 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 - r)], p) % p) % p; } public static long fact(long n) { long[] fac = new long[(int)(n) + 1]; fac[0] = 1; for (long i = 1; i <= n; i++) fac[(int)(i)] = fac[(int)(i - 1)] * i; return fac[(int)(n)]; } public static long nCr(long n, long k) { long ans = 1; for(long i = 0;i<k;i++) { ans *= (n-i); ans /= (i+1); } return ans; } //Modular Operations for Addition and Multiplication. public static long perfomMod(long x) { return ((x%M + M)%M); } public static long addMod(long a, long b) { return perfomMod(perfomMod(a)+perfomMod(b)); } public static long subMod(long a, long b) { return perfomMod(perfomMod(a)-perfomMod(b)); } public static long mulMod(long a, long b) { return perfomMod(perfomMod(a)*perfomMod(b)); } public static boolean isPrime(long n) { if(n == 1) { return false; } //check only for sqrt of the number as the divisors //keep repeating so only half of them are required. So,sqrt. for(int i = 2;i*i<=n;i++) { if(n%i == 0) { return false; } } return true; } public static List<Long> SieveList(int n) { boolean prime[] = new boolean[(int)(n+1)]; Arrays.fill(prime, true); List<Long> l = new ArrayList<>(); for (long p = 2; p*p<=n; p++) { if (prime[(int)(p)] == true) { for(long i = p*p; i<=n; i += p) { prime[(int)(i)] = false; } } } for (long p = 2; p<=n; p++) { if (prime[(int)(p)] == true) { l.add(p); } } return l; } public static int countDivisors(int x) { int c = 0; for(int i = 1;i*i<=x;i++) { if(x%i == 0) { if(x/i != i) { c+=2; } else { c++; } } } return c; } public static long log2(long n) { long ans = (long)(log(n)/log(2)); return ans; } public static boolean isPow2(long n) { return (n != 0 && ((n & (n-1))) == 0); } public static boolean isSq(int x) { long s = (long)Math.round(Math.sqrt(x)); return s*s==x; } /* * * >= <= 0 1 2 3 4 5 6 7 5 5 5 6 6 6 7 7 lower_bound for 6 at index 3 (>=) upper_bound for 6 at index 6(To get six reduce by one) (<=) */ public 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; } public 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; } public static void Sort(long[] a) { List<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); // Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void ssort(char[] a) { List<Character> l = new ArrayList<>(); for (char i : a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void main(String[] args) throws Exception { Reader sc = new Reader(); PrintWriter fout = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-- > 0) { int x = sc.nextInt(), y = sc.nextInt(); int par = x * x + y * y; long dist = (int)(Math.round(Math.sqrt(par))); if(x == 0 && y == 0) { fout.println(0); } else { fout.println((dist * dist == par) ? 1 : 2); } } fout.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
7a206f31a540b534e4156b2836c1d69a
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class Chip { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for (int i = 0; i < n; i++) { int x = in.nextInt(); int y = in.nextInt(); int b = (x*x)+(y*y); if (x ==0 && y ==0) { System.out.println("0"); continue; } if (Math.sqrt(b) % 1 == 0) { System.out.println("1"); } else { System.out.println("2"); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
7f9e63b4c9f73bd114000600f8531e2f
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; 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 x = sc.nextInt(),y=sc.nextInt(); int a = x*x + y*y; double ans = Math.sqrt(a); if(x==0 && y==0) System.out.println(0); else if(ans == (int)ans) System.out.println(1); else System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
169fc5be9139d5ea5c1c6031632583b3
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static FastReader in=new FastReader(); static final Random random=new Random(); static long mod=1000000007L; static HashMap<String,Integer>map=new HashMap<>(); public static void main(String[] args) { int t=in.nextInt(); StringBuilder res=new StringBuilder(); loop: while(t-->0){ int x=in.nextInt(); int y=in.nextInt(); if(x==y&&y==0){ res.append("0\n"); continue loop; } int sum=x*x+y*y; boolean test =false; int num=1; while (num*num<=sum){ if(num*num==sum){ test=true; } num++; } if(test) res.append(1+"\n"); else res.append(2+"\n"); } System.out.println(res); } static long calculateSum(long n) { if(n<0) { return 0; } return n*(n+1)/2; } static class Node implements Comparable<Node>{ int val; char ch; Node(int x,char y) { val=x; ch=y; } @Override public int compareTo(Node o) { if(val>o.val) { return 1; } if(val==o.val) { return 0; } return -1; } } static int max(int a, int b) { if(a<b) return b; return a; } static void ruffleSort(int[] a) { int n=a.length; 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 < E > void print(E res) { System.out.println(res); } static int gcd(int a,int b) { if(b==0) { return a; } return gcd(b,a%b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int abs(int a) { if(a<0) return -1*a; return a; } 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 [] readintarray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++)res[i] = nextInt(); return res; } long [] readlongarray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
2842238359135a16cd914d2c33a26e20
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); while(num > 0){ int x = scanner.nextInt(); int y = scanner.nextInt(); System.out.println(getMinStep(x,y)); num --; } } private static int getMinStep(int x, int y){ // 在两个点之间移动,要求走的必须是整数步 if(x == 0 && y == 0){ return 0; }else if(x == 0 || y == 0){ return 1; }else { int sq = (int) Math.sqrt(x*x + y*y); if((sq*sq) == (x*x + y*y)){ return 1; }else{ return 2; } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
943dfbed8e61bed064e9a2dee53909b3
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.sqrt; import static java.lang.Math.floor; public class Solution { public static void main(String args[])throws IOException { BufferedReader ob = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t = Integer.parseInt(ob.readLine()); while(t --> 0){ StringTokenizer st = new StringTokenizer(ob.readLine()); int x= Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); long a = (long)Math.pow(x,2) + (long)Math.pow(y,2); long element = (long)Math.sqrt(a); long f = a; long ans = f; if(x == 0 && y == 0) { System.out.println(0); }else if(element*element == a) { System.out.println(1); }else { System.out.println(2); } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
1577cb95eda652e8993090f385e88e84
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=1;i<=t;i++) { int x = sc.nextInt(); int y = sc.nextInt(); int temp = (int)Math.sqrt(x * x + y * y); if(x == 0 && y == 0) { System.out.println(0); } else if(temp * temp == x * x + y * y) { System.out.println(1); } else{ System.out.println(2); } } sc.close(); } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
1456498ba52f2f8c02cc185e69bcb476
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.*; import java.util.*; public class Demo{ // public static long gcd(long a, long b) { // if (b==0) // return a; // return gcd(b, a%b); // } // public static void pA(int n, int[] arr) { // for (int i=0; i<n; i++) { // System.out.print(arr[i]+" "); // } // System.out.println(); // } static BufferedReader br; public static void main(String args[]) throws IOException{ br = new BufferedReader(new InputStreamReader(System.in)); // Scanner s = new Scanner(System.in); int t = Integer.parseInt(br.readLine()); // int t = s.nextInt(); while (t-->0){ // int n = Integer.parseInt(br.readLine()); long[] arr = readLongArr(); long aa = arr[0]*arr[0] + arr[1]*arr[1]; long x = (long)Math.sqrt(aa); // System.out.println("x"+x); boolean sss = x*x==aa; if (arr[0]==0 && arr[1]==0){ System.out.println(0); // }else if ((double)(Math.sqrt(arr[0]*arr[0]+arr[1]*arr[1])*Math.sqrt(arr[0]*arr[0]+arr[1]*arr[1])) == (double)(arr[0]*arr[0]+arr[1]*arr[1])){ // System.out.println(Math.sqrt(arr[0]*arr[0]+arr[1]*arr[1])); // System.out.println(78.0064==78); }else if (sss){ System.out.println(1); }else{ System.out.println(2); } } // s.close(); } public static long[] readLongArr() throws IOException{ String[] integersInString = br.readLine().split(" "); long a[] = new long[integersInString.length]; // List<Integer> al = new ArrayList<>(integersInString.length); for (int i = 0; i < integersInString.length; i++) { a[i]=(Long.parseLong(integersInString[i])); } return a; } public static int[] readIntArr() throws IOException{ String[] integersInString = br.readLine().split(" "); int a[] = new int[integersInString.length]; // List<Integer> al = new ArrayList<>(integersInString.length); for (int i = 0; i < integersInString.length; i++) { a[i]=(Integer.parseInt(integersInString[i])); } return a; } // public static String sortString(String inputString) { // // convert input string to char array // char tempArray[] = inputString.toCharArray(); // // sort tempArray // Arrays.sort(tempArray); // // return new sorted string // return new String(tempArray); // } // public static String getString(int n) { // char[] buf = new char[(int) Math.floor(Math.log(25 * (n + 1)) / Math.log(26))]; // for (int i = buf.length - 1; i >= 0; i--) { // n--; // buf[i] = (char) ('a' + n % 26); // n /= 26; // } // return new String(buf); // } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
c5f22b5d912bca37d686713a383c0562
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.*; public class Main { static FastReader sc; static StringBuilder sb = new StringBuilder(); static final long MOD = 998244353; //sb.append("Case #"+(t+1)+": IMPOSSIBLE\n"); static boolean isPerfect(int n){ for(int i=1;i<n;i++){ if(n%i==0){ if(i*i==n) return true; } } return false; } public static void main(String args[]) throws InterruptedException { sc = new FastReader(); int tc=sc.nextInt(); for(int t=0;t<tc;t++){ int x=sc.nextInt(); int y=sc.nextInt(); if(x==0&&y==0){ sb.append("0\n"); }else{ int z=x*x+y*y; if(x==0||y==0||isPerfect(z)){ sb.append("1\n"); }else{ sb.append("2\n"); } } } out.println(sb.toString()); } public static void reverse(int[] b) { int n=b.length; int i=0,j=n-1; while(i<j){ int k=b[i]; b[i]=b[j]; b[j]=k; i++; j--; } return; } public static boolean nextPermutation(int[]a){ int n=a.length; if(n==0||n==1)return false; int pos=-1; for(int i=n-2;i>=0;i--){ if(a[i]<a[i+1]){ pos=i; int rep=-1; for(int j=i+1;j<n;j++){ if(a[j]>a[pos]){ rep=j; } } int k=a[pos]; a[pos]=a[rep]; a[rep]=k; break; } } int i=pos+1,j=n-1; while(i<j){ int k=a[i]; a[i]=a[j]; a[j]=k; i++; j--; } return (pos==-1)?false:true; } public static long powerMOD(long x, long y) { long res = 1L; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0){ x %= MOD; res %= MOD; res = (res * x)%MOD; } // y must be even now y = y >> 1; // y = y/2 x%= MOD; x = (x * x)%MOD; // Change x to x^2 } return res%MOD; } public static long power(long x, long y) { long res = 1L; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0){ res = (res * x); } // y must be even now y = y >> 1; // y = y/ x = (x * x); } return res; } public static void printArray(int[] a){ int n=a.length; for(int i=0;i<n;i++){ System.out.print(a[i]+" "); } System.out.println(); } public static int gcd(int a, int b){ if(b == 0) return a; return gcd(b , a%b); } static int cntBits(long n){ int cnt=0; while(n>0){ if(n%2==1) cnt++; n/=2; } return cnt; } static double p_dist(long x1,long y1,long x2,long y2){ double dist=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); dist=Math.sqrt(dist); return dist; } static void swap(int[]a,int i,int j){ int k=a[i]; a[i]=a[j]; a[j]=k; } static void printArray(char[]a){ int n=a.length; for(int i=0;i<n;i++){ System.out.print(a[i]+" "); } System.out.println(); } public 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 void sort(char[] a) { ArrayList<Character> l=new ArrayList<>(); for (char i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } public 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 log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static boolean isVowel(char c) { return (c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' || c=='u' || c=='U'); } static int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) sc.nextInt(); } return res; } static long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = sc.nextLong(); } return res; } public static long gcd(long a, long b){ if(b == 0) return a; return gcd(b , a%b); } public static class Pair implements Comparable<Pair>{ public long a; public long b; Pair(long a , long b){ this.a = a; this.b = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return (a == pair.a && b == pair.b); } @Override public int hashCode() { return Objects.hash(a,b); } @Override public String toString(){ return "("+a + "," + b+")"; } @Override public int compareTo(Pair pair) { if((a == pair.a && b == pair.b)) return 0; return 1; } } 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()); } char nextChar(){ return next().charAt(0); } 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
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
8b2a3e9868838212ab29030b456326c1
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-->0){ double x=sc.nextDouble(); double y=sc.nextDouble(); if ((int) x==0&&(int) y==0){ System.out.println(0); continue; } double sqrt = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); if (sqrt==(int)sqrt) System.out.println(1); else System.out.println(2); } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
09bec8bc9d0fbb4e407bf051fe9dc3b7
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.StringTokenizer; public class Integer_Moves { 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') { if (cnt != 0) { break; } else { continue; } } 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(); } } public static void main(String Args[]) throws java.lang.Exception { try { Scanner obj = new Scanner (System.in); int t = obj.nextInt(); while (t > 0) { t--; int x = obj.nextInt(); int y = obj.nextInt(); if (x == 0 && y == 0) { System.out.println ("0"); continue; } double d = Math.sqrt (x * x + y * y); if (d % 1 == 0) { System.out.println ("1"); } else { System.out.println ("2"); } } }catch(Exception e){ return; } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output
PASSED
b5d25f3a2f42b77f31a2a2731e1ebeee
train_110.jsonl
1647960300
There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
256 megabytes
import java.util.*; import java.io.*; public class codeforces1657A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); while (numCases-->0) { StringTokenizer st = new StringTokenizer(br.readLine()); int x = Integer.parseInt(st.nextToken()); int y = Integer.parseInt(st.nextToken()); if (x==0 && y == 0) { System.out.println(0); } else { if (x*x + y*y == (int)Math.sqrt(x*x+y*y)* (int)Math.sqrt(x*x+y*y)) { System.out.println(1); } else { System.out.println(2); } } } } }
Java
["3\n8 6\n0 0\n9 15"]
2 seconds
["1\n0\n2"]
NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.
Java 8
standard input
[ "brute force", "math" ]
fce6d690c2790951f7e04c622c3c2d44
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.
800
For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.
standard output