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
listlengths
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
b7ba918ed8a433f2d44451cc22252cff
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class two { public static void main(String[] args) { // TODO Auto-generated method stub Scanner key=new Scanner(System.in); int t=key.nextInt(); key.nextLine(); for(int i=0;i<t;i++) { String str=key.nextLine(); int temp=str.charAt(0)-96; int temp2=str.charAt(1)-96; if(temp==1) { System.out.println(temp2-1); }else if(temp<temp2) { System.out.println((temp-1)*25+temp2-1); }else { System.out.println((temp-1)*25+temp2); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6fb41f985e13798c0461cbfff4909062
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Dictionary_3 { public static void main(String args[]) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0) { String str1 = s.next(); int n = str1.charAt(0); int t1 = n-96; int t2 = str1.charAt(1); if(t2>n) { t2= t2-1; } int position = 25*t1-24+(t2-97); System.out.println(position); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
4126f5333236395124207f0d39fe9a67
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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. */ public final class Solution { public static void main (String[] args) throws java.lang.Exception { Scanner n1; try { n1 = new Scanner(new FileReader("./input.txt")); } catch(Exception e) { n1 = new Scanner(System.in); } PrintWriter output = new PrintWriter(System.out); int xt = n1.nextInt(); while(xt-->0) { String x = n1.next(); solve(x, output); } output.flush(); } static void solve(String x, PrintWriter output) throws Exception { char c1 = x.charAt(0); char c2 = x.charAt(1); int x1 = c1-'a'; int x2 = c2-'a'>x1? c2-'a'-x1: c2-'a'-x1+1; int ans = x1*26 + x2; output.println(ans); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3469c4af1b282f8b4775908bc73f61bb
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Answer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); HashMap<String, Integer> hm = new HashMap<>(); int c = 1; for(int i = 1; i <= 26; i++) { for(int j = 1; j <= 26; j++) { if(i != j) hm.put((char)('a'+i-1) + "" + (char)('a'+j-1), c++);//pw.println((char)('a'+i-1) + "" + (char)('a'+j-1)); } } while(t-->0) { String s = sc.next(); pw.println(hm.get(s)); } sc.close(); pw.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
c9e029cbfd8e93e0e1fc06d5aa70703a
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class CF1209{ public static void main(String args[]){ Scanner scan = new Scanner(System.in); int testCases = scan.nextInt(); while(testCases>0){ String string = scan.next(); int index = (string.charAt(0)-'a')*25+1; if(string.charAt(1)<string.charAt(0)){ index += string.charAt(1)-'a'; }else{ index += string.charAt(1)-'a'-1; } System.out.println(index); testCases--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
c9f2c5fcc1ddefdd68b316e14afd9305
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Dict { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++){ String s = sc.next(); int a = s.charAt(0) - 'a' + 1; int b = s.charAt(1) - 'a' + 1; if(b > a){ System.out.println((a-1) * 25 + b-1); }else{ System.out.println((a-1) * 25 + b); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
566b55d059745085e3df316954fe0252
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args){ Scanner sc=new Scanner(System.in); // System.out.println(sc.nextByte()); // foodanimal(sc); dic(sc); } private static void dic(Scanner scanner){ int testcase=scanner.nextInt(); for(int i=0;i<testcase;i++){ String s=scanner.next(); char f=s.charAt(0); char second=s.charAt(1); int place=0; place+=25*(f-97); // System.out.println((int)f); if((int)second>(int)f){ place+=second-97; }else{ // System.out.println('D'); place+=second-96; } System.out.println(place); } }}
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
7e7de0f2f24a0c3f5e638d0d1ae71fba
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; //import java.util.Arrays; //import java.util.Collections; //import java.util.ArrayList; public class CodeForces { public static void main(String args[])throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.valueOf(br.readLine()); while(t-->0) { String s=br.readLine(); int fl=(int)s.charAt(0); fl-=96; int sl=(int)s.charAt(1); sl-=96; if(sl>fl) sl--; int finalval=((fl-1)*25) + sl; //System.out.println(fl); //System.out.println(sl); System.out.println(finalval); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
1edc52470b3f5bed85cd4ecf588f1faa
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class practice { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new PrintWriter(System.out))); StringBuilder sb = new StringBuilder(); int t = Integer.parseInt(br.readLine()); while (t --> 0) { char arr[] = br.readLine().toCharArray(); int a = Character.codePointAt(arr, 0); int b = Character.codePointAt(arr, 1); int tot = (a - 97) * 25 + (b - 96); if (a < b) tot--; sb.append(tot).append("\n"); } pw.println(sb.toString().trim()); pw.close(); br.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
0889930b108bed057c000a4b08c4805f
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Solution{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } static int[] string_to_array(String[] arr){ int[] ans=new int[arr.length]; for(int i=0;i<arr.length;i++){ ans[i]=Integer.parseInt(arr[i]); } return ans; } static int binarySearch(int arr[], int num){ int l = 0, r = arr.length-1; int mid = 0; while(l <= r){ mid = l + (r-l)/2; if(arr[mid] == num){ return mid; } //Item presents in the left SubArray if(num < arr[mid]){ r = mid - 1; } //Item presents in the right SubArray if(num > arr[mid]){ l = mid + 1; } } return l; } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); // List<String>answer=new ArrayList<>(); Map<String,Integer> map=new HashMap<>(); int count=1; for(char i='a';i<='z';i++) { for(char j='a';j<='z';j++) { if(i!=j){ map.put(""+i+j,count++); } } } while(testCases-- > 0) { String s=in.nextLine(); // int n=Integer.parseInt(in.nextLine()); //int[] arr=string_to_array(in.nextLine().split(" ")); out.println(map.get(s)); } // for(String s:answer){ // out.println(s); // } out.close(); } catch (Exception e) { return; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
af7a47de0816f41c71780ff80c356543
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class dictionary { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int testcases = sc.nextInt(); for (int i = 0; i < testcases; i++) { String s = sc.next(); if(s.charAt(1)- 'a' > s.charAt(0) -'a'){ System.out.println(25*(s.charAt(0) - 'a') + s.charAt(1)-'a'); }else{ System.out.println(25*(s.charAt(0) - 'a') + s.charAt(1)-'a' + 1); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
5f1c693dbad62ee610eedefa2e3eb53a
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); for(int h=0;h<test;h++) { String s = sc.next(); int one = (s.charAt(0)-'a')*25; int two; if(s.charAt(1)<s.charAt(0)) two = s.charAt(1)-'a'; else two = s.charAt(1)-'a'-1; System.out.println(one+two+1); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
9a81c0abd04a392d7030cc3fc0468315
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class cf { public static void main(String[] args) { HashMap<String,Integer> hm = new HashMap<String ,Integer>(); int count = 1; for(char i='a';i<='z';i++) { for(char j = 'a' ; j<= 'z';j++) { if(i!=j) { String str = ""; str += i; str += j; hm.put(str , count); count++; } } } Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { String str = sc.next(); System.out.println(hm.get(str)); t--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d20b8cea64e4803157dd07665b46f07b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Test{ //Global Declarations final static Random random = new Random(); final static FastReader in = new FastReader(); final static PrintWriter out = new PrintWriter(System.out); public static int solve() { //Long range is -10^18 to 10^18 and is 64 bit (8 bytes) //Integer range is ~~ -2 * 10^9(-2^31) to 2 * 10^9(2^31 - 1) and is 32 bit (4 bytes) //Java executes 5 * 10^7 operations per second return 0; } public static void reverseLong(long a[]) { int i,n=a.length,j=n-1; long temp; for(i=0;i<n/2;++i){ temp = a[i]; a[i] = a[j]; a[j] = temp; --j; } } public static void reverseInt(int a[]) { int i,n=a.length,j=n-1,temp; for(i=0;i<n/2;++i){ temp = a[i]; a[i] = a[j]; a[j] = temp; --j; } } public static void ruffleLong(long a[]) { //shuffle, then sort int i,j,n=a.length; long temp; for (i=0; i<n; i++) { j = random.nextInt(n); temp = a[i]; a[i] = a[j]; a[j] = temp; } Arrays.sort(a); } public static void ruffleInt(int a[]) { //shuffle, then sort int i,j,n=a.length,temp; for (i=0; i<n; i++) { j = random.nextInt(n); temp = a[i]; a[i] = a[j]; a[j] = temp; } Arrays.sort(a); } public static void main(String ... args) throws IOException { // << --> multiply // >> --> divide //variable_name <<= 1 --> (variable)multiply by 2 //variable_name >>= 1 --> (variable)divide by 2 //2<<3 --> (multiply)2 * 2^3 --> 16; //6>>1 --> (divide)6 / 2^1 --> 3; //out.println(Integer.valueOf(1).compareTo(Integer.valueOf(3))); //it returns the remaining length of the string //out.println("h".compareTo("ham")); /* HashMap<Integer,Integer> mp = new HashMap<>(); mp.merge(1,2,Integer::sum); mp.merge(1,3,Integer::sum); mp.merge(2,3,Integer::sum); mp.merge(2,3,Integer::sum); mp.merge(2,3,Integer::sum); out.println(mp.toString());*/ //out.println(solve()); int tt = in.nextInt(); while(tt-->0){ String s = in.next(); int temp = ((int)s.charAt(0) - (int)'a') * 25; if(s.charAt(0) < s.charAt(1)) temp = temp + ((int)s.charAt(1) - (int)'a'); else temp = temp + ((int)s.charAt(1) - (int)'a') + 1; out.println(temp); } out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6ee6c0b359d0250d88ffa8f7a89a87cc
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
/* package whatever; // 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. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner( System.in ); int t = in.nextInt(); for(int i = 0;i<t;i++){ String s = in.next(); int p = 25*(s.charAt(0)-97)+s.charAt(1)-97; if(s.charAt(0)>s.charAt(1)){ p++; } System.out.println(p); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
5c75c945e83476fe5f313824e38cabff
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class Main { static FastScanner sc; static PrintWriter pw; public static void main(String[] args) throws Exception{ sc = new FastScanner(); pw = new PrintWriter(System.out); try{ int T = sc.ni(); Map<String,Integer> mp = new HashMap<>(); int cnt = 0; for(int i=0; i<26; i++){ for(int j=0; j<26; j++){ if(i!=j){ char c1 = (char)('a'+i); char c2 = (char)('a'+j); String temp = ""+c1+c2; cnt++; mp.put(temp, cnt); } } } while(T-->0){ String s = sc.nextLine(); pw.println(mp.get(s)); } }catch(Exception e){ return; } pw.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); st = null; } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N) { int[] ret = new int[N]; for (int i = 0; i < N; i++) ret[i] = ni(); return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N) { long[] ret = new long[N]; for (int i = 0; i < N; i++) ret[i] = nl(); return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
3d8a332f62cf73b75b15cdc81f0a4ecb
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; public class One { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { 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> { long x,y; Pair(long x, long y) { this.x = (int) x; this.y = (int) y; } public int compareTo(Pair o) { return (int) (o.x-this.x); } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a,long b) { return ((a*b)/gcd(a,b)); } static final int mod=1_000_000_007; 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; } private static int[] rarr(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=sc.nextInt(); return a; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse(int []arr,int i,int j) { while(i<j){ int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; i++; j--; } } public static void sort1(long[] arr) { ArrayList<Long> ls = new ArrayList<>(); for (long x : arr) { ls.add(x); } Collections.sort(ls); for (int i = 0; i < arr.length; i++) { arr[i] = ls.get(i); } } 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 FastScanner sc=new FastScanner(); public static void main(String[] args){ int t=sc.nextInt(); while(t-->0) { String str=sc.nextLine(); char ch=str.charAt(0); char ch1=str.charAt(1); long val; val=(25*(ch-'a')+(ch1-'a')); if(ch1<ch) { val++; } System.out.println(val); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2d7bcbe2b5a596480acba9994932844c
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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){ String s=sc.next(); int a=s.charAt(0); a =a-96; int b=s.charAt(1); b=b-96; if(b<a) System.out.println(25*(a-1)+b); else System.out.println(25*(a-1)+b-1); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
c1efbf87dd59fb1efa7c38aa220362e0
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.StringTokenizer; public class B implements Runnable { public static void main(String[] args) { new Thread(null, new B(), "whatever", 1 << 26).start(); } FastScanner s = new FastScanner(System.in); StringBuilder sb = new StringBuilder(); public void run() { int t = s.nextInt(); for (int test = 0; test < t; test++) { test(); } System.out.print(sb); } { String str = "ab"; for (int i = 0; i < 100; i++) { System.err.println(str); str = next(str); } } void test() { // Read input String str = s.next(); // Process String cur = "ab"; int index = 1; while (!cur.equals(str)) { cur = next(cur); index++; } // Add output to string builder sb (with newline if needed). sb.append(index + ""); sb.append("\n"); } String next(String cur) { char a = cur.charAt(0); char b = cur.charAt(1); b++; if (b > 'z') { b = 'a'; a++; } if (a != b) { return a + "" + b; } else { return next(a + "" + b); } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(Reader in) { br = new BufferedReader(in); } public FastScanner(InputStream in) { this(new InputStreamReader(in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
beb73993687a4c9c0c17a9bcfe420e23
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; 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 B_Dictionary{ public static void main (String[] args) throws java.lang.Exception { FastReader sc = new FastReader() ; HashMap <String,Integer> hm = new HashMap<> (); int p=1; for(char i='a';i<='z';i++) { for(char j='a';j<='z';j++) { if(i!=j) { String x= (char)i+""+(char)j; hm.put(x, p); p++; } } } int check = sc.nextInt(); for(int tp=0;tp<check;tp++) { String s=sc.next(); if(hm.containsKey(s)) { System.out.println(hm.get(s)); } else { System.out.println(-1); } // // long arr[]=new long [n]; //HASHMAP MAP NO REPETITION //HashMap <Long,Long> hm = new HashMap<Long,Long> (); //h1.put(1,4); //h1.forEach((k,v)->System.out.println(v+" and "+k)); //System.out.println(h1.getOrDefault(100,1)); //ARRAYLIST ARRAY ALTERNATIVE //ArrayList<Long> al = new ArrayList<Long> (); // ArrayList<ArrayList<Long>> al = new ArrayList<> (); // for(int i=0;i<3;i++) // { // al.add(new ArrayList<>()); // } //al.add(sc.nextLong()); //al.forEach((x) -> System.out.println(x*x)); //al.removeIf(x->(x%2==0)); //ORDERED IN ASCENDING //TreeMap <Long,Long> tm = new TreeMap <Long,Long>(); //tm.put(10,8); //System.out.println(tm.subMap(2,5)); // Start here //long a = sc.nextLong(); } } static final class Utils { private static class Shuffler { private static void shuffle(int[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void shuffle(long[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void swap(int[] x, int i, int j) { final int t = x[i]; x[i] = x[j]; x[j] = t; } private static void swap(long[] x, int i, int j) { final long t = x[i]; x[i] = x[j]; x[j] = t; } } public static void shuffleSort(int[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } public static void shuffleSort(long[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } private Utils() {} } static class FastReader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; FastReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } FastReader(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 { 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 { byte c = read(); while ('+' != c && '-' != c) { c = read(); } return '+' == c ? 0 : 1; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() throws IOException { int b; //noinspection StatementWithEmptyBody 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 int[] nextIntArray(int n) throws IOException { final int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } 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 long[] nextLongArray(int n) throws IOException { final long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextLong(); } return res; } 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
86639367a85ac429968e099e0c5a1c54
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); char[] chars = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; Map<String, Integer> mp = new HashMap<>(); int k = 0; for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { if (chars[i] == chars[j]) continue; String x = ""; x += chars[i]; x += chars[j]; mp.put(x, k); k++; } } int t = scanner.nextInt(); while (t > 0) { t--; String x = scanner.next(); System.out.println(mp.get(x)+1); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
28c4b75de46eb364f1755ea992402695
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.util.Map.Entry; import java.io.*; import java.lang.*; /** * B_Dictionary */ public class B_Dictionary { private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static int mod = 998244353; private static FastReader sc = new FastReader(); public static void main(String[] args) { int t = sc.nextInt(); while(t-->0) { solve(); } } private static void solve() { String s = sc.next(); int z = 25*(s.charAt(0)-'a')+s.charAt(1)-'a'+1; if(s.charAt(0)<=s.charAt(1)){ z--; } System.out.println(z); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6e06e4eaac8fc31a59c6f5f00f89efec
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class dictionary { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int cases = scanner.nextInt(); for (int i = 0; i < cases; i++) { String word = scanner.next(); char[] letters = new char[2]; for (int j = 0; j < 2; j++) { letters[j] = word.charAt(j); } int counter1 = 0; for (char c = 'a'; c < 'z'; c++) { if (letters[0] == c) { break; } counter1++; } int counter2 = 0; for (char c = 'a'; c < 'z'; c++) { counter2++; if (letters[1] == c) { if (letters[1] > letters[0]) { counter2 -= 1; } break; } } int number = counter1*25 + counter2; System.out.println(number); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
fc1d6e5f62df728056d14c02e62f0b12
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class roughCodeforces { public static boolean isok(long x, long h, long k){ long sum = 0; if(h > k){ long t1 = h - k; long t = t1 * k; sum += (k * (k + 1)) / 2; sum += t - (t1 * (t1 + 1) / 2); }else{ sum += (h * (h + 1)) / 2; } if(sum < x){ return true; } return false; } public static boolean binary_search(long[] a, long k){ long low = 0; long high = a.length - 1; long mid = 0; while(low <= high){ mid = low + (high - low) / 2; if(a[(int)mid] == k){ return true; }else if(a[(int)mid] < k){ low = mid + 1; }else{ high = mid - 1; } } return false; } public static long lowerbound(long a[], long ddp){ long low = 0; long high = a.length; long mid = 0; while(low < high){ mid = low + (high - low)/2; if(a[(int)mid] == ddp){ return mid; } if(a[(int)mid] < ddp){ low = mid + 1; }else{ high = mid; } } // if(low + 1 < a.length && a[(int)low + 1] <= ddp){ // low++; // } if(low == a.length && low != 0){ low--; return low; } if(a[(int)low] > ddp && low != 0){ low--; } return low; } public static long upperbound(long a[], long ddp){ long low = 0; long high = a.length; long mid = 0; while(low < high){ mid = low + (high - low) / 2; if(a[(int)mid] < ddp){ low = mid + 1;; }else{ high = mid; } } if(low == a.length){ return a.length - 1; } return low; } public static class pair{ long w; long h; public pair(long w, long h){ this.w = w; this.h = h; } } public static class trinary{ long a; long b; long c; public trinary(long a, long b, long c){ this.a = a; this.b = b; this.c = c; } } public static long lowerboundforpairs(pair a[], long pr){ long low = 0; long high = a.length; long mid = 0; while(low < high){ mid = low + (high - low)/2; if(a[(int)mid].w <= pr){ low = mid + 1; }else{ high = mid; } } // if(low + 1 < a.length && a[(int)low + 1] <= ddp){ // low++; // } // if(low == a.length && low != 0){ // low--; // return low; // } // if(a[(int)low].w > pr && low != 0){ // low--; // } return low; } public static pair[] sortpair(pair[] a){ Arrays.sort(a, new Comparator<pair>() { public int compare(pair p1, pair p2){ return (int)p1.w - (int)p2.w; } }); return a; } public static boolean ispalindrome(String s){ long i = 0; long j = s.length() - 1; boolean is = false; while(i < j){ if(s.charAt((int)i) == s.charAt((int)j)){ is = true; i++; j--; }else{ is = false; return is; } } return is; } public static void sort(long[] arr) { ArrayList<Long> a = new ArrayList<>(); for (long i : arr) { a.add(i); } Collections.sort(a); for (int i = 0; i < a.size(); i++) { arr[i] = a.get(i); } } public static void sortForObjecttypes(Long[] arr) { ArrayList<Long> a = new ArrayList<>(); for (Long i : arr) { a.add(i); } Collections.sort(a); for (int i = 0; i < a.size(); i++) { arr[i] = a.get(i); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } void readArr(int[] ar, int n) { for (int i = 0; i < n; i++) { ar[i] = nextInt(); } } } public static void solve(FastReader sc, PrintWriter w) throws Exception { String s = sc.nextLine(); long ans = ((s.charAt(0) - 'a') * 25) + (s.charAt(1) - 'a'); if(s.charAt(0) - 'a' != 0 ){ if(s.charAt(0) - 'a' > s.charAt(1) - 'a'){ ans++; } } System.out.println(ans); } public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter w = new PrintWriter(System.out); long o = sc.nextLong(); while (o-- > 0) { solve(sc, w); } w.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
7d3e6f46385222bde8d934fcaa4a821c
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 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.util.HashMap; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Manav */ 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); BDictionary solver = new BDictionary(); solver.solve(1, in, out); out.close(); } static class BDictionary { public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.nextInt(); HashMap<String, Integer> map = new HashMap<>(); int x = 1; for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { if (i != j) { map.put((char) ('a' + i) + "" + (char) ('a' + j), x++); } } } // out.println(map); for (int i = 0; i < t; i++) { out.println(map.get(in.next())); } } } 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 nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return nextString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } 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 println(int i) { writer.println(i); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2eaed95b3f7c03ce90c25a896f92a73d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; // you can compare with output.txt and expected out public class Round786B { MyPrintWriter out; MyScanner in; final static String IMPOSSIBLE = "IMPOSSIBLE"; final static String POSSIBLE = "POSSIBLE"; final static String YES = "YES"; final static String NO = "NO"; private void preferFileIO(boolean isFileIO) { if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) { try{ in = new MyScanner(new FileInputStream("input.txt")); out = new MyPrintWriter(new FileOutputStream("output.txt")); } catch(FileNotFoundException e){ e.printStackTrace(); } } else{ in = new MyScanner(System.in); out = new MyPrintWriter(new BufferedOutputStream(System.out)); } } public static void main(String[] args){ // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); Round786B sol = new Round786B(); sol.run(); } private void run() { boolean isDebug = false; boolean isFileIO = true; preferFileIO(isFileIO); int t = in.nextInt(); for (int i = 1; i <= t; ++i) { String s = in.next(); if(isDebug){ out.printf("Test %d\n", i); } int ans = solve(s); out.println(ans); if(isDebug) out.flush(); } in.close(); out.close(); } private int solve(String s) { int first = s.charAt(0)-'a'; int second = s.charAt(1)-'a'; int index = first*25+second+1; if(second > first) index--; return index; } public static class MyScanner { BufferedReader br; StringTokenizer st; // 32768? public MyScanner(InputStream is, int bufferSize) { br = new BufferedReader(new InputStreamReader(is), bufferSize); } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); // br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[][] nextGraphEdges(){ return nextGraphEdges(0); } int[][] nextGraphEdges(int offset) { int m = nextInt(); int[][] e = new int[m][2]; for(int i=0; i<m; i++){ e[i][0] = nextInt()+offset; e[i][1] = nextInt()+offset; } return e; } int[] nextIntArray(int len) { return nextIntArray(len, 0); } int[] nextIntArray(int len, int offset){ int[] a = new int[len]; for(int j=0; j<len; j++) a[j] = nextInt()+offset; return a; } long[] nextLongArray(int len) { return nextLongArray(len, 0); } long[] nextLongArray(int len, int offset){ long[] a = new long[len]; for(int j=0; j<len; j++) a[j] = nextLong()+offset; return a; } } public static class MyPrintWriter extends PrintWriter{ public MyPrintWriter(OutputStream os) { super(os); } public void print(long[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void println(long[] arr){ print(arr); println(); } public void print(int[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void println(int[] arr){ print(arr); println(); } public <T> void print(ArrayList<T> arr){ if(arr != null && arr.size() > 0){ print(arr.get(0)); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)); } } } public <T> void println(ArrayList<T> arr){ print(arr); println(); } public void println(int[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public <T> void println(ArrayList<T> arr, int split){ if(arr != null && !arr.isEmpty()){ for(int i=0; i<arr.size(); i+=split){ print(arr.get(i)); for(int j=i+1; j<i+split; j++){ print(" "); print(arr.get(j)); } println(); } } } } static private int[][] constructChildren(int n, int[] parent, int parentRoot){ int[][] childrens = new int[n][]; int[] numChildren = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) numChildren[parent[i]]++; } for(int i=0; i<n; i++) { childrens[i] = new int[numChildren[i]]; } int[] idx = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) childrens[parent[i]][idx[parent[i]]++] = i; } return childrens; } static private int[][] constructNeighborhood(int n, int[][] e) { int[] degree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; degree[u]++; degree[v]++; } int[][] neighbors = new int[n][]; for(int i=0; i<n; i++) neighbors[i] = new int[degree[i]]; int[] idx = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; neighbors[u][idx[u]++] = v; neighbors[v][idx[v]++] = u; } return neighbors; } static private void makeDotUndirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict graph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "--" + e[i][1] + ";"); } out2.println("}"); out2.close(); } static private void makeDotDirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict digraph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "->" + e[i][1] + ";"); } out2.println("}"); out2.close(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
304c95591156ba4f1b903d989a7f82ce
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { static Scanner sc = new Scanner (System.in); public static void main(String[] args) { int test = sc.nextInt(); for ( int life=0; life<test; life++){ String str = sc.next(); char c1 = str.charAt(0); char c2 = str.charAt(1); int ans = ((int)c2-97)+ ((int)c1-97)*25; if ( (int)c1>=(int)c2) System.out.println(ans+1); else System.out.println(ans); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
a114c8be43b519ef7966cf19add6675b
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0){ String s = sc.nextLine(); int ans = 0; ans = (s.charAt(0) - 97)*25; if(s.charAt(0) > s.charAt(1)) ans += s.charAt(1) - 97 + 1; else ans += s.charAt(1) - 97; System.out.println(ans); } } } 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
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
b1a7fbc153d644b520c8129c6fdf7feb
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Scanner; public class Dictionary_800 { public static void main(String[] args) { Scanner input = new Scanner (System.in); int cases = Integer.parseInt(input.nextLine()); for (int j = 0; j < cases; j ++) { String word = input.nextLine(); String[] split1 = word.split(""); String letter1 = split1[0]; char c1 = letter1.charAt(0); int num1 = ((int)c1 - 96); String letter2 = split1[1]; char c2 = letter2.charAt(0); int num2 = ((int)c2 - 96); int place; if (num2 < num1) { place = ((25*(num1 - 1)) + (num2)); } else place = ((25*(num1 - 1)) + (num2 - 1)); System.out.println(place); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d454e2e64ebfc00aab77f688be0a1747
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Main { static StringBuilder sb; static dsu dsu; static long fact[]; static int mod = (int) (1e9 + 7); static void solve() { String s=s(); int ch1=s.charAt(0)-'a'; int ch2=s.charAt(1)-'a'; int ans=0; ans=ch1*25; if(ch2<ch1){ ans+=ch2; } else{ ans+=(ch2-1); } ans++; sb.append(ans+"\n"); } public static void main(String[] args) { sb = new StringBuilder(); int test = i(); while (test-- > 0) { solve(); } System.out.println(sb); } /* * fact=new long[(int)1e6+10]; fact[0]=fact[1]=1; for(int i=2;i<fact.length;i++) * { fact[i]=((long)(i%mod)1L(long)(fact[i-1]%mod))%mod; } */ //**************NCR%P****************** static long ncr(int n, int r) { if (r > n) return (long) 0; long res = fact[n] % mod; // System.out.println(res); res = ((long) (res % mod) * (long) (p(fact[r], mod - 2) % mod)) % mod; res = ((long) (res % mod) * (long) (p(fact[n - r], mod - 2) % mod)) % mod; // System.out.println(res); return res; } /////////////////////////////////////////// static class Pair { long x; long y; long gcd; public Pair(long x, long y, long gcd) { this.x = x; this.y = y; this.gcd = gcd; } } static Pair euclids(long a, long b) { if (b == 0) { return new Pair(1, 0, a); } Pair dash = euclids(b, a % b); return new Pair(dash.y, dash.x - ((a / b) * dash.y), dash.gcd); } /////////////////////////////////// static int euler(int n) { int count = n; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) { n = n / i; } count = count - count / i; } } if (n > 1) { count = count - count / n; } return count; } ////////////////////////////////// static long[][] ncrcoll(int n, int k, int p) { long[][] arr = new long[n + 1][k + 1]; for (int i = 1; i < arr.length; i++) { arr[i][0] = 1; } for (int i = 1; i < arr.length; i++) { for (int j = 1; j <= i && j < arr[0].length; j++) { if (i == 1 && j == 1) { arr[i][j] = 1; } else { arr[i][j] = (arr[i - 1][j] + arr[i - 1][j - 1]) % (p); } } } return arr; } ////////////////////////////////// static void sieve() { int MAXN=spf.length; spf[1] = 1; for (int i = 2; i < MAXN; i++) { spf[i] = i; } for (int i = 2; i * i < MAXN; i++) { if (spf[i] == i) { for (int j = i * i; j < MAXN; j += i) { if (spf[j] == j) { spf[j] = i; } } } } } static int[] spf=new int[1000000]; static ArrayList<Integer> getFactorization(int x) { ArrayList<Integer> ret = new ArrayList<>(); while (x != 1) { ret.add(spf[x]); x = x / spf[x]; } return ret; } ////////////////////////////////// static long p(long x, long y)// POWER FXN // { if (y == 0) return 1; long res = 1; while (y > 0) { if (y % 2 == 1) { res = (res * x) % mod; y--; } x = (x * x) % mod; y = y / 2; } return res; } //**************END****************** // *************Disjoint set // union*********// static class dsu { int parent[]; dsu(int n) { parent = new int[n]; for (int i = 0; i < n; i++) parent[i] = -1; } int find(int a) { if (parent[a] < 0) return a; else { int x = find(parent[a]); parent[a] = x; return x; } } void merge(int a, int b) { a = find(a); b = find(b); if (a == b) return; parent[b] = a; } } //**************PRIME FACTORIZE **********************************// static TreeMap<Integer, Integer> prime(long n) { TreeMap<Integer, Integer> h = new TreeMap<>(); long num = n; for (int i = 2; i <= Math.sqrt(num); i++) { if (n % i == 0) { int nt = 0; while (n % i == 0) { n = n / i; nt++; } h.put(i, nt); } } if (n != 1) h.put((int) n, 1); return h; } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private 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 Int() { 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 String String() { 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 boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return String(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } 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 printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static InputReader in = new InputReader(System.in); static OutputWriter out = new OutputWriter(System.out); public static long[] sort(long[] a2) { int n = a2.length; ArrayList<Long> l = new ArrayList<>(); for (long i : a2) l.add(i); Collections.sort(l); for (int i = 0; i < l.size(); i++) a2[i] = l.get(i); return a2; } public static char[] sort(char[] a2) { int n = a2.length; ArrayList<Character> l = new ArrayList<>(); for (char i : a2) l.add(i); Collections.sort(l); for (int i = 0; i < l.size(); i++) a2[i] = l.get(i); return a2; } public static long pow(long x, long y) { long res = 1; while (y > 0) { if (y % 2 != 0) { res = (res * x);// % modulus; y--; } x = (x * x);// % modulus; y = y / 2; } return res; } //GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public static long gcd(long x, long y) { if (x == 0) return y; else return gcd(y % x, x); } // ******LOWEST COMMON MULTIPLE // ********************************************* public static long lcm(long x, long y) { return (x * (y / gcd(x, y))); } //INPUT PATTERN******************************************************** public static int i() { return in.Int(); } public static long l() { String s = in.String(); return Long.parseLong(s); } public static String s() { return in.String(); } public static int[] readArrayi(int n) { int A[] = new int[n]; for (int i = 0; i < n; i++) { A[i] = i(); } return A; } public static long[] readArray(long n) { long A[] = new long[(int) n]; for (int i = 0; i < n; i++) { A[i] = l(); } return A; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
90e8c6f2ef6d6a9ddc9c54ec9ae19276
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class Main{ public static void main(String[] args) throws IOException { // write your code here r.init(System.in); int t = r.nextInt(); String s, s1 = ""; char ch1, ch2; int index = -1; int[] ans = new int[t]; for (int i = 1; i <= t; i++) { s = r.next(); ch1 = s.charAt(0); ch2 = s.charAt(1); if ((int)(ch1) < (int)(ch2)) index = ((int)(ch1) - 97)*25 + ((int)(ch2) - 97); else index = ((int)(ch1) - 97)*25 + ((int)(ch2) - 97) + 1; ans[i-1] = index; } for (Integer i: ans) System.out.println(i); // int sum1, sum2; // for (int i = 1; i <= t; i++){ // s = r.next(); // sum1 = sum2 = 0; // for (int j = 0; j < s.length(); j++){ // ch = s.charAt(j); // s1 += ch; // if (j < 3) sum1 += Integer.valueOf(s1); // else sum2 += Integer.valueOf(s1); // s1 = ""; // } // // if (sum1 == sum2) System.out.println("YES"); // else System.out.println("NO"); // } } } class r { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
b952879a4dc36724449510060207c82d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.util.Arrays; import java.util.HashMap; import java.util.InputMismatchException; import java.util.Map; /* By : SSD */ public class B { long mod = (long) (1e9 + 7); static class InputReader1 { private final InputStream st; private final byte[] buf = new byte[8192]; private int cc, sc; private SpaceCharFilter f; public InputReader1(InputStream st) { this.st = st; } public int t() { if (sc == -1) throw new InputMismatchException(); if (cc >= sc) { cc = 0; try { sc = st.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (sc <= 0) return -1; } return buf[cc++]; } public int nextInt() { int c = t(); while (isSpaceChar(c)) { c = t(); } int sgn = 1; if (c == '-') { sgn = -1; c = t(); } int res = 0; do { res *= 10; res += c - '0'; c = t(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = t(); while (isSpaceChar(c)) { c = t(); } int sgn = 1; if (c == '-') { sgn = -1; c = t(); } long res = 0; do { res *= 10; res += c - '0'; c = t(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = t(); while (isSpaceChar(c)) { c = t(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = t(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = t(); while (isSpaceChar(c)) c = t(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = t(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (f != null) return f.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } 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(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } InputReader1 sc; OutputWriter out; public static void main(String[] ssd) throws Exception { new B().run(); } void run() throws Exception { sc = new InputReader1(System.in); out = new OutputWriter(System.out); long s = System.currentTimeMillis(); solve(); tr(System.currentTimeMillis() - s + "ms"); out.close(); } Map< String ,Integer> map; private void solve() { map = new HashMap<>(); int idx=1; for(int i=0; i<26; i++) { for(int j=0; j<26; j++) { if(i==j) continue; char p = (char) (i+'a'); char q = (char) (j+'a'); map.put( ""+p+q, idx++); } } // System.out.println(map); int tt = sc.nextInt(); while (tt-- > 0) { String s = sc.nextLine(); int a =map.getOrDefault(s, 1); System.out.println(a); } } void dbg(Object... o) { out.println(Arrays.deepToString(o)); } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
2bb69895b28b6fe930d9e42fc49641db
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); Map<String, Integer> dictionary = new HashMap<>(); int count = 0; for (int i = 0; i < 26; i++) { for (int k = 0; k < 26; k++) { if (k == i) continue; String key = String.valueOf((char) ((int) 'a' + i)) + String.valueOf((char) ((int) 'a' + k)); dictionary.put(key, ++count); } } while (t != 0) { String question = cin.next(); System.out.println(dictionary.get(question)); t--; } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
800c9adcde84ed3cb3fc588082a6ea18
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
// 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. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner op= new Scanner(System.in); int n = op.nextInt(); while(n-->0){ String str = op.next(); int k= (int)str.charAt(0); int l = (int)str.charAt(1); int a = k-97; int b =l-97; // System.out.println(a); if(b>a){ System.out.println(25*a+b); } else{ System.out.println(25*a+b+1); } } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6b7b8dc8efbf7cb1b8825c2f5edb8978
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main{ static int N = 1010; static int[][] c = new int[N][N]; public static void main(String[] args){ Scanner scan = new Scanner(System.in); int T = scan.nextInt(); int cnt = 0; for (char i = 'a' ; i <= 'z' ; i ++ ) for (char j = 'a' ; j <= 'z' ; j ++){ if (i != j){ c[i][j] = ++cnt; } } while (T -- > 0){ String s = scan.next(); int a = s.charAt(0); int b = s.charAt(1); System.out.println(c[a][b]); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
4accbd2e66ecb0c0d4494849e682cf07
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class Watermelon4A { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); HashMap<String, Integer> map = new HashMap<>(); int count = 1; for (char ch = 'a'; ch <= 'z'; ch++) { for (char ch1 = 'a'; ch1 <= 'z'; ch1++) { if (ch == ch1) { continue; } else { String temp = ""; temp += ch; temp += ch1; map.put(temp, count); count++; } } } for (int i = 0; i < t; i++) { String word = scan.next(); System.out.println(map.get(word)); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
b4b5ce4d62e7d38c409bb1e6b819f0eb
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int count = Integer.parseInt(scanner.nextLine()); Map<String, Integer> map = new HashMap<>(); int cur = 1; for(int i = 0; i < 26; i++) { for(int j = 0; j < 26; j++) { char first = (char)('a' + i); char second = (char)('a' + j); if(first != second) { map.put((String.valueOf(first) + String.valueOf(second)), cur++); } } } while(count-- > 0) { System.out.println(map.get(scanner.nextLine())); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
7e9ac06399217534f7be0b052e259022
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc=new Scanner(System.in); char i,j; HashMap<String,Integer> map=new HashMap<>(); int c=0; for(i='a';i<='z';i++) { for(j='a';j<='z';j++) { if(i!=j) { ++c; String str=String.valueOf(i)+String.valueOf(j); map.put(str,c); } } } int tc=sc.nextInt(); while(tc>0) { String str=sc.next(); System.out.println(map.get(str)); --tc; }}}
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
02fc21e0cfc67b7ee8b331073b95ae18
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.*; import java.util.*; /** * @author atulanand */ public class Solution { private static int solve(char[] arr) { int f = (int) arr[0] - 97; int s = (int) arr[1] - 97; return (f) * 25 + s + (s < f ? 1 : 0); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = inputInt(br); StringBuilder sb = new StringBuilder(); while (t-- > 0) { char[] spec = inputString(br).toCharArray(); sb.append(solve(spec)).append("\n"); } System.out.println(sb); } public static String inputString(BufferedReader br) throws IOException { return br.readLine().trim(); } public static int inputInt(BufferedReader br) throws IOException { return Integer.parseInt(inputString(br)); } public static int[] inputIntArray(BufferedReader br) throws IOException { String[] spec = inputString(br).split(" "); int[] arr = new int[spec.length]; for (int i = 0; i < spec.length; i++) arr[i] = Integer.parseInt(spec[i]); return arr; } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
cd964ea377538aebdfd6459770da98ad
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int kol =sc.nextInt(); for(int a =0;a<kol;a++){ String s =sc.next(); char ch = s.charAt(0); char ch2 =s.charAt(1); int pos = ch - 'a' + 1; int pos2 = ch>ch2 ? ch2 - 'a' + 1 : ch2 - 'a'; int al = (pos-1)*25 + pos2; System.out.println(al); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
d78ecfcb93d3726ec76a213c41d739f0
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; public class Lol { //Hi my name is Vijay, My age is 27, My birthday is 17th Oct 1995. public static void main(String[] args) { Scanner sc = new Scanner(System.in); //System.out.println('c'-'a'); int t = sc.nextInt(); while (t-- > 0) { String s=sc.next(); int a=s.charAt(0)-'a'; if(s.charAt(0)<s.charAt(1))System.out.println(25*a+(s.charAt(1)-'a')); else System.out.println(25*a+(s.charAt(1)-'a')+1); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
46315ac10bef9200a2c5a4015e0f42d1
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.util.stream.*; public class Sequence { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); scan.nextLine(); StringBuilder result = new StringBuilder(); for(int i = 0; i < t; i++) { String s = scan.nextLine(); char l1 = s.charAt(0); char l2 = s.charAt(1); int t1 = l1 - 'a'; int t2 = (l2 > l1) ? l2 - 'a' : l2 - 'a' + 1; int res = (25*t1) + t2; result.append(res + "\n"); } System.out.println(result); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
e51bffc9c94968df341415da75b1f364
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
// package All_in_all; import java.io.*; import java.util.*; /** * Created by nikitos on 23.08.17. */ public class A { public StreamTokenizer t; public int nextInt() throws IOException { t.nextToken(); return (int) t.nval; } public long nextLong() throws IOException { t.nextToken(); return (long) t.nval; } public String nextString() throws IOException { t.nextToken(); return t.sval; } public void start() throws IOException { t = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int t = nextInt(); Map<String, Integer> m = new HashMap<>(); int o = 1; for (int i = 0; i < 26; i++) { for (int j = 0; j < 26; j++) { if (i == j) { continue; } char f = (char)('a' + i); char s = (char)('a' + j); String r = String.valueOf(f) + String.valueOf(s); m.put(r, o++); } } for (int i = 0; i < t; i++) { String a = nextString(); System.out.println(m.get(a)); } } public static void main(String[] args) throws IOException { new A().start(); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
eee7140fde8e532960f0d012be097fc4
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; public class k { 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(); } } //---------------------MATHS-------------------- public static ArrayList<Long> divisor(long n) { ArrayList<Long> arr=new ArrayList<Long>(); long x=(long) Math.sqrt(n); for (long i=1; i<=x; i++) { if (n%i == 0) { if (n/i == i) arr.add(i); else arr.add( i); arr.add( (n/i)); } } return arr; } public static ArrayList<Long> Factors(long n) { ArrayList<Long> arr=new ArrayList<Long>(); while (n%2l==0) { n /=2; arr.add(2l); } long p=(long) Math.sqrt(n); for (long i = 3; i <=p; i+= 2) { if(n==1)break; while (n%i == 0) { arr.add(i); n /= i; } } if (n > 2) { arr.add(n); } return arr; } static long hcf(long a,long b) { while (b > 0) { long temp = b; b = a % b; a = temp; } return a; } public static long gcd(long x, long p) { if (x == 0) return p; return gcd(p%x, x); } public static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static int biggestFactor(int num) { int result = 1; for(int i=2; i*i <=num; i++){ if(num%i==0){ result = num/i; break; } } return result; } static int sieve = 1000000 ; static boolean[] prime = new boolean[sieve + 1] ; static ArrayList<Integer> pr=new ArrayList<Integer>(); public static void sieveOfEratosthenes() { // FALSE == prime and 1 // TRUE == COMPOSITE // time complexity = 0(NlogLogN)== o(N) // gives prime nos bw 1 to N // size - 1e7(at max) for(int i = 4; i<= sieve ; i++) { prime[i] = true ; i++ ; } for(int p = 3; p*p <= sieve; p++) { if(prime[p] == false) { pr.add(p); for(int i = p*p; i <= sieve; i += p) prime[i] = true; } p++ ; } } static long isPrime(long x) { if (x >= 0) { long sr = (long)Math.sqrt(x); long k=sr*sr; if(k == x)return sr; } return -1; } public static long pwmd(long a, long n,long mod) { if (n == 0) return 1; long pt = pwmd(a, n / 2,mod); pt *= pt; pt %= mod; if ((n & 1) > 0) { pt *= a; pt %= mod; } return pt; } static long nCr(long n, long r) { return (long)fact(n) / (long)(fact(r) * fact(n - r)); } // Returns factorial of n static long fact(long n) { long res = 1; for (int i = 2; i <= n; i++) res = res * (long)(i); return res; } //-------------------------BINARY SEARCHES-------------------------------------- //if present - return the first occurrence of the no //not present- return the index of next greater value //if greater than all the values return N(taking high=N-1) //if smaller than all the values return 0(taking low =0) static int lower_bound(long arr[], int low,int high, long X) { if (low > high) { return low; } int mid = low + (high - low) / 2; if (arr[mid] >= X) { return lower_bound(arr, low, mid - 1, X); } return lower_bound(arr, mid + 1, high, X); } //if present - return the index of next greater value //not present- return the index of next greater value //if greater than all the values return N(taking high=N-1) //if smaller than all the values return 0(taking low =0)\ static int upper_bound(long arr[], int low, int high, long X) { if (low > high) return low; int mid = low + (high - low) / 2; if (arr[mid] <= X) { return upper_bound(arr, mid + 1,high, X); } return upper_bound(arr, low,mid - 1, X); } public static class Pair {// comparator with class long x; long y; public Pair(long x, long y) { this.x = x; this.y = y; } } //---------------UTIL--------------------- public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } public static void printArr(int[] arr) { for(int i=0;i<arr.length;i++) { System.out.print(arr[i]+" "); } System.out.println(); } public static int[] decSort(int[] arr) { int[] arr1 = Arrays.stream(arr).boxed().sorted(Collections.reverseOrder()).mapToInt(Integer::intValue).toArray(); return arr1; } public static void sortbyColumn(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else if (entry1[col] < entry2[col]) return -1; else return 0; } }); } public static void print2D(long[][] dp) { for (int i = 0; i < dp.length; i++) { { for (int j = 0; j < dp[i].length; j++) System.out.print(dp[i][j] + " "); } System.out.println(); } } public static int knapsack(int[] weights,int[] price, int totW) { int[] dp1=new int[totW+1]; int[] dp2=new int[totW+1]; int N=totW; int ans=0; for(int i=0;i<price.length;i++) { for(int j=0;j<=N;j++) { if(weights[i]>j) { if(i%2==0) { dp1[j]=dp2[j]; } else { dp2[j]=dp1[j]; } } else { if(i%2==0) { dp1[j]=Math.max(dp2[j],dp2[j-weights[i]]+price[i]); } else { dp2[j]=Math.max(dp1[j], dp1[j-weights[i]]+price[i]); } } } if(i%2==0)ans=dp1[N]; else ans=dp2[N]; } return ans; } public static class p { long no; long h; public p(long no, long h) { this.no=no; this.h= h; } } static class com implements Comparator<p>{ public int compare(p s1, p s2) { if (s1.h > s2.h) return -1; else if (s1.h < s2.h) return 1; else if(s1.h==s2.h) { if(s1.no>s2.no)return -1; else return 1; } return 0; } } static <K,V extends Comparable<? super V>> SortedSet<Map.Entry<K,V>> entriesSortedByValues(Map<K,V> map) { SortedSet<Map.Entry<K,V>> sortedEntries = new TreeSet<Map.Entry<K,V>>( new Comparator<Map.Entry<K,V>>() { @Override public int compare(Map.Entry<K,V> e1, Map.Entry<K,V> e2) { int res = e1.getValue().compareTo(e2.getValue()); return res != 0 ? res : 1; // Special fix to preserve items with equal values } } ); sortedEntries.addAll(map.entrySet()); return sortedEntries; } public static void floodFill1(int[][] image, int sr, int sc) { image[sr][sc]=2; if((sr-1>=0) && image[sr-1][sc]==1) { floodFill1(image,sr-1,sc); } if((sr+1<image.length) && image[sr+1][sc]==1) { floodFill1(image,sr+1,sc); } if((sc-1>=0) && image[sr][sc-1]==1 ) { floodFill1(image,sr,sc-1); } if((sc+1<image[0].length) && image[sr][sc+1]==1) { floodFill1(image,sr,sc+1); } } // ---------------SEGMENT TREE---------- public static void buildTree(long[] arr,long[][] tree,int st, int en,int ind) { // int x = (int) (Math.ceil(Math.log(arr.length) / Math.log(2))); // int size = 2 * (int) Math.pow(2, x) - 1; // int[] tree=new int[size]; if(st==en) {tree[ind][0]=arr[st];tree[ind][1]=1;return;} int mid=(st+en)/2; buildTree(arr,tree,st,mid,2*ind); buildTree(arr,tree,mid+1,en,(2*ind)+1); if(tree[2*ind][0]<tree[(2*ind)+1][0]) { tree[ind][0]=tree[2*ind][0]; tree[ind][1]=tree[2*ind][1]; } if(tree[2*ind][0]>tree[(2*ind)+1][0]) { tree[ind][0]=tree[2*ind+1][0]; tree[ind][1]=tree[2*ind+1][1]; } if(tree[2*ind][0]==tree[(2*ind)+1][0]) { tree[ind][0]=tree[2*ind][0]; tree[ind][1]=tree[2*ind][1]+tree[2*ind+1][1]; } return; } public static int k=0; public static long query(long[][] tree,int st, int en, int qs, int qe, int ind) { if(st>=qs && en<=qe) { return tree[ind][0]; } if(st>qe || en<qs)return Integer.MAX_VALUE; int mid=(st+en)/2; long l=query(tree,st,mid,qs,qe,2*ind); long r=query(tree,mid+1,en,qs,qe,2*ind+1); return Math.min(l, r); } public static p query1(long[][] tree,int st, int en, int qs, int qe, int ind) { if(st>qe || en<qs) { p k=new p(1000000007,-1); return k; } if(st>=qs && en<=qe) { return new p(tree[ind][0],tree[ind][1]); } int mid=(st+en)/2; p l=query1(tree,st,mid,qs,qe,2*ind); p r=query1(tree,mid+1,en,qs,qe,2*ind+1); p fin; if(l.no<r.no) { return l; } if(l.no>r.no) { return r; } return new p(l.no,l.h+r.h); } public static void update(long[][] tree,int st, int en, int qs, int qe, int ind,long inc) { if(st>qe || en<qs)return ; if(st==en) { tree[ind][0]=inc; return; } int mid=(st+en)/2; update(tree,st,mid,qs,qe,2*ind,inc); update(tree,mid+1,en,qs,qe,2*ind+1,inc); if(tree[2*ind][0]<tree[(2*ind)+1][0]) { tree[ind][0]=tree[2*ind][0]; tree[ind][1]=tree[2*ind][1]; } if(tree[2*ind][0]>tree[(2*ind)+1][0]) { tree[ind][0]=tree[2*ind+1][0]; tree[ind][1]=tree[2*ind+1][1]; } if(tree[2*ind][0]==tree[(2*ind)+1][0]) { tree[ind][0]=tree[2*ind][0]; tree[ind][1]=tree[2*ind][1]+tree[2*ind+1][1]; } return ; } //-------------------------------------------------------------- static void rec(String p, int ind, long ans, ArrayList<Long> arr) { if(ind>=p.length()) {arr.add(ans);return;} if(p.charAt(ind)=='1') { rec(p,ind+1,ans+(long)Math.pow(2, p.length()-ind-1),arr); } if(p.charAt(ind)=='0') { rec(p,ind+1,ans,arr); } if(p.charAt(ind)=='?') { rec(p,ind+1,ans,arr); rec(p,ind+1,ans+(long)Math.pow(2, p.length()-ind-1),arr); } } static int reverseDigits(int num) { int rev_num = 0; while (num > 0) { rev_num = rev_num * 10 + num % 10; num = num / 10; } return rev_num; } /* Function to check if n is Palindrome*/ static int isPalindrome(int n) { // get the reverse of n int rev_n = reverseDigits(n); // Check if rev_n and n are same or not. if (rev_n == n) return 1; else return 0; } public static void main(String args[]) throws NumberFormatException, IOException ,java.lang.Exception { Reader reader = new Reader(); long mod= 1000000007; // long mod= 998244353; // long[] pow2 =new long[64]; // pow2[0]=1l; // for(int i=1;i<64;i++) // { //// pow2[i]=(int) Math.pow(2, i); // pow2[i]=((long)(2)*pow2[i-1]); //// System.out.println(pow2[i]); // } // sieveOfEratosthenes(); //Scanner reader=new Scanner(System.in); // ArrayList<ArrayList<Pair>> g=new ArrayList<ArrayList<Pair>>(); // PrintWriter out = new PrintWriter(System.out); // ArrayList<String> even=new ArrayList<String>(); ArrayList<Integer> odd=new ArrayList<Integer>(); // System.out.println(set); HashMap<String,Integer > map=new HashMap<String,Integer>(); int x=1; for(char i='a' ;i<='z';i++) { for(char j='a';j<='z';j++) { if(i!=j) { map.put(""+i+j,x); x++; } } } // System.out.println(map.size()); // System.out.println(map); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int cases=Integer.parseInt(br.readLine()); // int cases=1; // int cases=reader.nextInt(); while (cases-->0){ // // long N=reader.nextLong(); // long B=reader.nextLong(); // long X=reader.nextLong(); // long Y=reader.nextLong(); // long D2=reader.nextLong(); // // long C=reader.nextLong(); // long W=reader.nextLong(); // long A=reader.nextLong(); // long N=reader.nextLong(); // long K=reader.nextLong(); // long M=reader.nextLong(); // int M=reader.nextInt(); // long X=reader.nextLong(); // int D=reader.nextInt(); // int K2=reader.nextInt(); // int K=reader.nextInt(); // long M=reader.nextLong(); // // long X=reader.nextLong(); System.out.println(map.get(br.readLine())); ////// // String[] first=br.readLine().split(" "); // int N=Integer.parseInt(first[0]); // int M=Integer.parseInt(first[1]); // int X=Integer.parseInt(first[2]); // int Y=Integer.parseInt(first[3]); // String[] first2=br.readLine().split(" "); // String[] first3=br.readLine().split(" "); // int M=Integer.parseInt(first1[1]); // long K=Long.parseLong(first1[0]); // long X=Long.parseLong(first1[1]); // String s3=br.readLine();String s4=br.readLine(); // char[] s11=s2.toCharArray(); // char[] s12=new char[s11.length]; // long max=Long.MIN_VALUE; // long max=10000000000001l; // int min=Integer.MAX_VALUE; // long min=Inteeg.MAX_VALUE; // int min1=Integer.MAX_VALUE; // int min2=Integer.MAX_VALUE; // HashMap<Integer, Integer> map=new HashMap<Integer,Integer>(); // PriorityQueue<Integer> q = new PriorityQueue<Integer>(); // PriorityQueue<Long> q = new PriorityQueue<Long>(Collections.reverseOrder()); // HashMap<Integer,TreeSet<Integer>> map=new HashMap<Integer,TreeSet<Integer>>(); // HashMap<Long,Long> map=new HashMap<Long,Long>(); // HashMap<String,String> map1=new HashMap<String,String>(); // TreeMap<Long,Integer> map1=new TreeMap<Long,Integer>(); // List<TreeMap<Integer,Integer>> map = new ArrayList<TreeMap<Integer,Integer>>(); // HashSet<Character> set =new HashSet<Character>(); // HashSet<String> set1 =new HashSet<String>(); // HashSet<Integer> map =new HashSet<Integer>(); // HashSet<Long> map =new HashSet<Long>(); // TreeSet<Integer> a =new TreeSet<Integer>(); // TreeSet<Long> b =new TreeSet<Long>(); // TreeSet<Integer> map=new TreeSet<Integer>(); // int[] arr=new int[(int)M]; // Integer[] arr=new Integer[N]; // Integer[] arr2=new Integer[N]; // int[] arr2=new int[64]; // int[] ev=new int[N]; // int[] od=new int[N]; // // boolean[] s=new boolean[K+1]; // int[] arr=new int[32];// i00nt[] odd=new int[100001]; // Integer[] arr=new Integer[N]; // long[] b=new long[N+1]; // long[] suf=new long[N+1]; // Integer[] arr=new Integer[N]; // Long[] arr=new Long[N]; // long[][] dp=new long[N][M+1]; // ArrayList<String> l=new ArrayList<String>(); }} } // output.flush(); // output.flush(); // output.flush();
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
98cdfdfc459b327e387cf052dacab418
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.util.*; import java.io.*; public class Main { static int n, m, x, y, test, N = 200001; static String io[], s; public static void main(String[] args) throws Exception { test = Integer.parseInt(in.readLine()); while (test-- > 0){ s = in.readLine(); x = s.charAt(0)-'a'; y = s.charAt(1)-'a'; if (y > x) y--; out.println(x*25+y+1); } out.flush(); } static int ni() throws IOException { input.nextToken(); return (int) input.nval; } static long nl() throws IOException { input.nextToken(); return (long) input.nval; } static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); static StreamTokenizer input = new StreamTokenizer(in); static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); } class E{ int to, ne, wt; E(int t, int n) {to = t;ne = n;} }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
46e399044b8d8a73afc3b82ff4393c0d
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.security.cert.X509CRL; import java.util.*; import java.lang.*; import java.util.stream.Collector; import java.util.stream.Collectors; @SuppressWarnings("unused") public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; static String OUTPUT = ""; //global //private final static long BASE = 998244353L; private final static int ALPHABET = (int)('z') - (int)('a') + 1; private final static int BASE = 1000000007; private final static int INF_I = (1<<31)-1; private final static long INF_L = (1l<<63)-1; private final static int MAXN = 100100; private final static int MAXK = 31; static void solve() { int ntest = readInt(); //out.println(shift('f',2)); Map<String, Integer> dict = new HashMap<>(); int sz=0; for (char ch1='a'; ch1<='z'; ch1++) for (char ch2='a'; ch2<='z'; ch2++) { if (ch1==ch2) continue; StringBuilder sb = new StringBuilder(); sb.append(ch1); sb.append(ch2); dict.put(sb.toString(), ++sz); } for (int test=0;test<ntest;test++) { String s = readString(); out.println(dict.get(s)); } } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); if (INPUT=="") { is = System.in; } else { File file = new File(INPUT); is = new FileInputStream(file); } if (OUTPUT == "") out = new PrintWriter(System.out); else out = new PrintWriter(OUTPUT); solve(); out.flush(); long G = System.currentTimeMillis(); } private static class Point<T extends Number & Comparable<T>> implements Comparable<Point<T>> { private T x; private T y; public Point(T x, T y) { this.x = x; this.y = y; } public T getX() {return x;} public T getY() {return y;} @Override public int compareTo(Point<T> o) { int cmp = x.compareTo(o.getX()); if (cmp==0) return y.compareTo(o.getY()); return cmp; } } private static class ClassComparator<T extends Comparable<T>> implements Comparator<T> { public ClassComparator() {} @Override public int compare(T a, T b) { return a.compareTo(b); } } private static class ListComparator<T extends Comparable<T>> implements Comparator<List<T>> { public ListComparator() {} @Override public int compare(List<T> o1, List<T> o2) { for (int i = 0; i < Math.min(o1.size(), o2.size()); i++) { int c = o1.get(i).compareTo(o2.get(i)); if (c != 0) { return c; } } return Integer.compare(o1.size(), o2.size()); } } private static boolean eof() { if(lenbuf == -1)return true; int lptr = ptrbuf; while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false; try { is.mark(1000); while(true){ int b = is.read(); if(b == -1){ is.reset(); return true; }else if(!isSpaceChar(b)){ is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } // private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static double readDouble() { return Double.parseDouble(readString()); } private static char readChar() { return (char)skip(); } private static String readString() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] readChar(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] readTable(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = readChar(m); return map; } private static int[] readIntArray(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = readInt(); return a; } private static long[] readLongArray(int n) { long[] a = new long[n]; for (int i=0;i<n;i++) a[i] = readLong(); return a; } private static int readInt() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static long readLong() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
5ba689c7830b708c43073176702109f8
train_107.jsonl
1651502100
The Berland language consists of words having exactly two letters. Moreover, the first letter of a word is different from the second letter. Any combination of two different Berland letters (which, by the way, are the same as the lowercase letters of Latin alphabet) is a correct word in Berland language.The Berland dictionary contains all words of this language. The words are listed in a way they are usually ordered in dictionaries. Formally, word $$$a$$$ comes earlier than word $$$b$$$ in the dictionary if one of the following conditions hold: the first letter of $$$a$$$ is less than the first letter of $$$b$$$; the first letters of $$$a$$$ and $$$b$$$ are the same, and the second letter of $$$a$$$ is less than the second letter of $$$b$$$. So, the dictionary looks like that: Word $$$1$$$: ab Word $$$2$$$: ac ... Word $$$25$$$: az Word $$$26$$$: ba Word $$$27$$$: bc ... Word $$$649$$$: zx Word $$$650$$$: zy You are given a word $$$s$$$ from the Berland language. Your task is to find its index in the dictionary.
512 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class cf1674B { // https://codeforces.com/contest/1674/problem/B public static void main(String[] args) { Kattio io = new Kattio(); int t = io.nextInt(), ans; char[] arr; for (int i = 0; i < t; i++) { arr = io.next().toCharArray(); ans = 25 * (arr[0] - 97); if (arr[1] < arr[0]) { ans += arr[1] - 96; } else { ans += arr[1] - 97; } io.println(ans); } io.close(); } // Kattio static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in,System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName+".out"); r = new BufferedReader(new FileReader(problemName+".in")); } // returns null if no more input public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) {} return null; } public String nextLine() { try { st = null; return r.readLine(); } catch (Exception e) {} return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["7\n\nab\n\nac\n\naz\n\nba\n\nbc\n\nzx\n\nzy"]
2 seconds
["1\n2\n25\n26\n27\n649\n650"]
null
Java 11
standard input
[ "combinatorics", "math" ]
2e3006d663a3c7ad3781aba1e37be3ca
The first line contains one integer $$$t$$$ ($$$1 \le t \le 650$$$) — the number of test cases. Each test case consists of one line containing $$$s$$$ — a string consisting of exactly two different lowercase Latin letters (i. e. a correct word of the Berland language).
800
For each test case, print one integer — the index of the word $$$s$$$ in the dictionary.
standard output
PASSED
6ab3e55aa1631ae9189d658caab18351
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.io.*; import java.util.*; public class Main { private static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { int a = in.nextInt(); int b = in.nextInt(); if (b < a || b % a != 0) { out.println("0 0"); } else { b /= a; if (b == 1) { out.println("1 1"); } else { for (int i = 2; i <= b; i++) { int count = 0, j = 1; for (; j < b; j *= i) { count++; } if (j == b) { out.println(count + " " + i); return; } } } } } } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); // solver.solve(1, in, out); int testNumber = in.nextInt(); for (int i = 1; i <= testNumber; i++) { solver.solve(i, in, out); } out.close(); } private static class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; private InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } private String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private String nextLine() { String str; try { str = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } private boolean hasNext() { while (tokenizer != null && !tokenizer.hasMoreTokens()) { String nextLine = null; try { nextLine = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } if (nextLine == null) { return false; } tokenizer = new StringTokenizer(nextLine); } return true; } private int nextInt() { return Integer.parseInt(next()); } private long nextLong() { return Long.parseLong(next()); } private double nextDouble() { return Double.parseDouble(next()); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
fdce2c5844b51d632a539c3cd2e6cbeb
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
//package com.company; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-- > 0){ int x = in.nextInt(); int y = in.nextInt(); if(y%x == 0){ System.out.println(1 + " " + y/x); }else{ System.out.println(0 + " " + 0); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
7c7691186cff72f5829afcc7194cf6b1
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
/*import java.util.*; import java.io.*; public class forces2 { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { // int n= sc.nextInt(); String s; s = sc.next(); int i = Integer.parseInt(s); int choice=0; int y=0,z=0; int num = 10; while(choice!=3) { z = i%num + z; i = i/num; choice++; } int a=0; int num2=10; while(a!=3) { y = i%num2+y; i = i/num2; a++; } if(z==y) { System.out.println("Yes"); } else { System.out.println("No"); } } } } */ import java.util.*; class forces2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { // int n=sc.nextInt(); /* int index=0; int n=sc.nextInt(); int []a=new int[n]; int sum=0; int max=a[0]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); if (max < a[i]) { max = a[i]; index = i; } } System.out.println(index+1); */ /* int res=0; res=sum-a[0]-a[n-1]; int res2=0; res2=a[0]+a[n-1]; int z; z=res-res2; System.out.println(Math.abs(z));}*/ Long x =sc.nextLong(); Long y=sc.nextLong(); // Long z = x/y; Long r =y/x; /* if(x%y!=0 || y%x!=0) { System.out.println("0" + " " + "0"); }*/ if(y>=x && y%x==0) { System.out.println("1" + " " + r); } else{ System.out.println("0" + " " + "0"); } /* int n =sc.nextInt(); int []a=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } Arrays.sort(a); int x = a[n-1]-a[0]; System.out.println(x); */ /* String s = sc.next(); char c='a'; char d='b'; int result=0; int result2=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)==c) result++; if(s.charAt(i)==d) result2++; } if(result>=3 && result2>=2) { System.out.println("Yes"); } else if(result>=2 && result2>=3) { System.out.println("Yes"); } else if(result>=2 && result2==0) { System.out.println("Yes"); } else if(result==0 && result2>=2) { System.out.println("Yes"); } else { System.out.println("No"); } */ /* int n = sc.nextInt(); int a[] = new int[n]; int sum=0; int choice=0; int choice2=0; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ if(a[i]%2==0) { choice++; } if(a[i]%2!=0) { choice2++; } } System.out.println(Math.min(choice,choice2)); */ /* Long m = sc.nextLong(); Long y; y=m; int choice=0; while(m!=0) { m=m/10; choice++; } //System.out.println(choice); choice--; double x; x=Math.pow(10, choice); int val = (int) x; Long res; res=y-val; System.out.println(res); */ /*int m=sc.nextInt(); int z=0; int []a=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); z=z+a[i]; } if(m>z) { System.out.println("0"); } else { int x=z-m; System.out.println(x); }*/ /* int x = sc.nextInt(); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if(x==3) { System.out.println("Yes"); } else if(x==1 && (a==0 || a==1)) { System.out.println("No"); } else if(x==2 && (a==0 || a==1)) { System.out.println("No"); } else { System.out.println("Yes"); } */ } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
ad1b279c6222da2583c94c25296c6cab
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class MyClass { public static int hcf(int n1, int n2){ if(n2 != 0){ return hcf(n2, n1%n2); }else{ return n1; } } public static void main(String args[]) { Scanner sc= new Scanner(System.in); int tc = sc.nextInt(); while(tc>0){ tc--; int a = sc.nextInt(); int b = sc.nextInt(); if(b % a == 0) System.out.println(1 + " " + b/a); else System.out.println(0 + " "+ 0); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
144b53035a4aa0ad011a1ceb087206bf
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner myobj=new Scanner(System.in); int t; t=myobj.nextInt(); int i,j,k; int c[][]=new int[2][t]; for(i=0;i<t;i++) { int x,y; x=myobj.nextInt(); y=myobj.nextInt(); k=y/x; int a,b; int[] r=new int[2]; if(k>0 && y%x==0){ c[0][i]=1; c[1][i]=k; } else { c[0][i]=0; c[1][i]=0; } } for(i=0;i<t;i++) { System.out.println(c[0][i]+" "+c[1][i]); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
7508f647bcc2c531d4dcd62cca0901d1
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class Testing { public static void main(String[] args) { Scanner s = new Scanner (System.in); int t=s.nextInt(); for(int i=0;i<t;i++){ int x=s.nextInt(),y=s.nextInt(); if (x>y||((double)y/x-(y/x)!=0)) System.out.println("0 0"); else if (x==y) System.out.println("1 1"); else System.out.println(1+" "+y/x); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
94ef8aeabf3a769f0bc2587e79d49968
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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,y; x=sc.nextInt(); y=sc.nextInt(); if(y%x==0) { System.out.println("1 "+y/x); } else System.out.println("0 0"); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
df1ffcb7d26e425c6cb497432d54c2f8
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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(); if (y % x != 0) out.println(0 + " " + 0); else out.println(1 + " " + y / x); } 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\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
44c8ca68b89a6884f5aadd1159758b80
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Scanner; public class problem2 { 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(y%x == 0){ System.out.println("1 "+y/x); } else{ System.out.println("0 0"); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
f98bc7290e2a44ea930c39daa4c68a2b
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class Solution{ public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); s.nextLine(); while(n!=0) { --n; int x=s.nextInt(); int y=s.nextInt(); if(y%x==0) { System.out.println("1"+" "+y/x); } else { System.out.println("0"+" "+"0"); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
0a3e2bb70c54455917181d293bdce17f
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class Solution{ public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); s.nextLine(); while(n!=0) { --n; int x=s.nextInt(); int y=s.nextInt(); if(y%x==0) { System.out.println("1"+" "+y/x); } else { System.out.println("0"+" "+"0"); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
8a9ff7d8622604faa048f4d8fa5bf471
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.nio.charset.StandardCharsets; import java.util.Scanner; public class CF1674A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int x = scanner.nextInt(); int y = scanner.nextInt(); System.out.println(solve(x, y)); } } private static String solve(int x, int y) { // y = x * b^a for (int a = 1; a <= 100; a++) { for (int b = 1; b <= 100; b++) { int pow = (int) (x * Math.pow(b, a)); if (pow == y) { return a + " " + b; } else if (pow > y) { break; } } } return "0 0"; } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
b9084e8c73da9240e53ef7b2a841a265
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Scanner; public class Codeforces { public static void main(String[] args) { Scanner lta = new Scanner(System.in); int t = lta.nextInt(); while (t -->0){ int x = lta.nextInt(); int y = lta.nextInt(); int count = 0; if (x <= y){ if (y % x == 0){ System.out.println(1 + " " + y/x); } else { System.out.println(0 + " " + 0); } } else { System.out.println(0 + " " + 0); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
76a43116d0dbb32ab44905d8240f798f
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class A_Number_Transformation { 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(); if (y % x != 0) { System.out.println(0 + " " + 0); } else { System.out.println(1 + " " + (y / x)); } } sc.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
679b2b05a3f499249b66ec8e9c22622a
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Solution { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static PrintWriter pw = new PrintWriter(System.out); static void getRes() throws Exception{ int[] inp = inputIntArray(2); if (inp[1] % inp[0] == 0) pw.println("1 " + inp[1]/inp[0]); else pw.println("0 0"); } public static void main(String[] args) throws Exception { int tests = Integer.parseInt(br.readLine()); while (tests-- > 0) { getRes(); } pw.flush(); pw.close(); } static int[] inputIntArray(int n) throws Exception{ int[] arr = new int[n]; String[] inp = br.readLine().split(" "); for (int x = 0; x < n; x++) arr[x] = Integer.parseInt(inp[x]); return arr; } static long[] inputLongArray(int n) throws Exception{ long[] arr = new long[n]; String[] inp = br.readLine().split(" "); for (int x = 0; x < n; x++) arr[x] = Integer.parseInt(inp[x]); return arr; } static void printArray(int[] arr) { for (int x = 0; x < arr.length; x++) pw.print(arr[x] + " "); pw.println(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 17
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
8b56847e1685666320c6e3dd12b06602
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class numberTransformation{ 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>y || y%x!=0){ System.out.println("0 0"); }else{ System.out.println("1 " + y/x); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
a2aedf0508a22832e3b440c5c4644a03
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int t = Integer.valueOf(br.readLine()); while(t-- > 0) { String[] input = br.readLine().split("\\s"); int x = Integer.valueOf(input[0]); int y = Integer.valueOf(input[1]); if(y % x != 0) { out.write("0 0\n"); } else { int a = 1; int b = y/x; out.write(a+" "+b+"\n"); } } out.flush(); br.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
b8025d099c08ddf1d0215e3ea5c684bf
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class Main{ public static int gcd(int a,int b){ return b != 0 ? gcd(b, a % b) : a; } 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(); if (x > y || y % x != 0) System.out.println(0 + " " + 0); else System.out.println(1 + " " + y / x); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
bef73ce498a4867fdd3dd3f9f1796575
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.awt.datatransfer.StringSelection; import java.util.*; import javax.management.Query; import java.io.*; public class practice { static String s; static int n,k; static int[] a; static long[][] memo; static HashMap<Long,Integer>hm; public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=sc.nextInt(); boolean f=true; if(n<=k&&k%n==0){ pw.println(1+" "+(k/n)); }else pw.println("0 0"); // pw.println(k%n); } pw.close(); } private static double customLog(double base, double logNumber) { return Math.log(logNumber) / Math.log(base); } public static int next(long[] arr, int target,int days) { // pw.println("days="+days); int start = 0, end = arr.length-1; // Minimum size of the array should be 1 // If target lies beyond the max element, than the index of strictly smaller // value than target should be (end - 1) if (target >= 0l+arr[end]+1l*(end+1)*days) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; // Move to the left side if the target is smaller if (0l+arr[mid]+1l*(mid+1)*days > target) { end = mid - 1; } // Move right side else { ans = mid; start = mid + 1; } } return ans; } public static long factorial(int n){ int y=1; for (int i = 2; i <=n ; i++) { y*=i; } return y; } public static void sort(int[] in) { shuffle(in); Arrays.sort(in); } public static void shuffle(int[] in) { for (int i = 0; i < in.length; i++) { int idx = (int) (Math.random() * in.length); int tmp = in[i]; in[i] = in[idx]; in[idx] = tmp; } } static LinkedList getfact(int n){ LinkedList<Integer>ll=new LinkedList<>(); LinkedList<Integer>ll2=new LinkedList<>(); for (int i = 1; i <= Math.sqrt(n); i++) { if(n%i==0) { ll.add(i); if(i!=n/i) ll2.addLast(n/i); } } while (!ll2.isEmpty()){ ll.add(ll2.removeLast()); } return ll; } static void rev(int n){ String s1=s.substring(0,n); s=s.substring(n); for (int i = 0; i <n ; i++) { s=s1.charAt(i)+s; } } static class SegmentTree { // 1-based DS, OOP int N; //the number of elements in the array as a power of 2 (i.e. after padding) long[] array, sTree; Long[]lazy; SegmentTree(long[] in) { array = in; N = in.length - 1; sTree = new long[N<<1]; //no. of nodes = 2*N - 1, we add one to cross out index zero lazy = new Long[N<<1]; build(1,1,N); } void build(int node, int b, int e) // O(n) { if(b == e) sTree[node] = array[b]; else { int mid = b + e >> 1; build(node<<1,b,mid); build(node<<1|1,mid+1,e); sTree[node] = sTree[node<<1]+sTree[node<<1|1]; } } void update_point(int index, int val) // O(log n) { index += N - 1; sTree[index] += val; while(index>1) { index >>= 1; sTree[index] = sTree[index<<1] + sTree[index<<1|1]; } } void update_range(int i, int j, int val) // O(log n) { update_range(1,1,N,i,j,val); } void update_range(int node, int b, int e, int i, int j, int val) { if(i > e || j < b) return; if(b >= i && e <= j) { sTree[node] = (e-b+1)*val; lazy[node] = val*1l; } else { int mid = b + e >> 1; propagate(node, b, mid, e); update_range(node<<1,b,mid,i,j,val); update_range(node<<1|1,mid+1,e,i,j,val); sTree[node] = sTree[node<<1] + sTree[node<<1|1]; } } void propagate(int node, int b, int mid, int e) { if(lazy[node]!=null) { lazy[node << 1] = lazy[node]; lazy[node << 1 | 1] = lazy[node]; sTree[node << 1] = (mid - b + 1) * lazy[node]; sTree[node << 1 | 1] = (e - mid) * lazy[node]; } lazy[node] = null; } long query(int i, int j) { return query(1,1,N,i,j); } long query(int node, int b, int e, int i, int j) // O(log n) { if(i>e || j <b) return 0; if(b>= i && e <= j) return sTree[node]; int mid = b + e >> 1; propagate(node, b, mid, e); long q1 = query(node<<1,b,mid,i,j); long q2 = query(node<<1|1,mid+1,e,i,j); return q1 + q2; } } // public static long dp(int idx) { // if (idx >= n) // return Long.MAX_VALUE/2; // return Math.min(dp(idx+1),memo[idx]+dp(idx+k)); // } // if(num==k) // return dp(0,idx+1); // if(memo[num][idx]!=-1) // return memo[num][idx]; // long ret=0; // if(num==0) { // if(s.charAt(idx)=='a') // ret= dp(1,idx+1); // else if(s.charAt(idx)=='?') { // ret=Math.max(1+dp(1,idx+1),dp(0,idx+1) ); // } // } // else { // if(num%2==0) { // if(s.charAt(idx)=='a') // ret=dp(num+1,idx+1); // else if(s.charAt(idx)=='?') // ret=Math.max(1+dp(num+1,idx+1),dp(0,idx+1)); // } // else { // if(s.charAt(idx)=='b') // ret=dp(num+1,idx+1); // else if(s.charAt(idx)=='?') // ret=Math.max(1+dp(num+1,idx+1),dp(0,idx+1)); // } // } // } static void putorrem(long x){ if(hm.getOrDefault(x,0)==1){ hm.remove(x); } else hm.put(x,hm.getOrDefault(x,0)-1); } public static int max4(int a,int b, int c,int d) { int [] s= {a,b,c,d}; Arrays.sort(s); return s[3]; } public static double logbase2(int k) { return( (Math.log(k)+0.0)/Math.log(2)); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } 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 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(); } } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } public tuble add(tuble t){ return new tuble(this.x+t.x,this.y+t.y,this.z+t.z); } } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
90d3b110afc49e5e4e84376c3bc782f9
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; /** * NumberTransformation_1674A */ public class NumberTransformation_1674A { private static int m; private static int n; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); while (t-- > 0) { String[] s = br.readLine().split(" "); int x = Integer.parseInt(s[0]); int y = Integer.parseInt(s[1]); double z = y / Double.parseDouble(x+""); if(z==0.0 || (z%1!=0) ){ System.out.println(0 +" "+0); }else{ System.out.println(1+" "+(int)z); } } // System.out.println(sb); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
2f5a7cf0f6ec07fe6936a7f0adc7b703
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.io.*; import java.util.*; public class ary{ static Scanner sc = new Scanner(System.in); public static void main(String[] args){ int tt = sc.nextInt(); for(int i = 0;i < tt; i++){ callme(); } } public static void callme(){ int x = sc.nextInt(); int y = sc.nextInt(); if(x == y){ System.out.println(1+" "+1); return; } int a = 0,b= 0; for(int i = 2; i <= y; i++){ int t = x; // System.out.println("this if for"); while(t < y){ t *= i; a++; // System.out.println("this if while"); } if(t == y){ b = i; System.out.println(a+" "+b); return ; } a = 0; } // a = (b > 0)? 1:0; System.out.println(0+" "+0); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
98dfceba476f05e6aa564d80f501691f
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.security.spec.RSAOtherPrimeInfo; import java.util.*; import java.lang.*; public class solve { static Scanner sc; public static void main (String[] args) { sc = new Scanner(System.in); // testCases int testCases = sc.nextInt(); // scan first-word while (testCases > 0) { justDoIt(); testCases--; } } // ==== SOLVE ============== static void justDoIt () { int x = sc.nextInt(), y = sc.nextInt(); if (y % x != 0) { System.out.println("0 0"); return; } System.out.println("1 " + (y/x)); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
e886a8da593bcc90b4f0c289a7c56bb8
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.security.spec.RSAOtherPrimeInfo; import java.util.*; import java.lang.*; public class solve { static Scanner sc; public static void main (String[] args) { sc = new Scanner(System.in); // testCases int testCases = sc.nextInt(); // scan first-word while (testCases > 0) { justDoIt(); testCases--; } } // ==== SOLVE ============== static void justDoIt () { int x = sc.nextInt(), y = sc.nextInt(); if (y % x != 0) { System.out.println("0 0"); return; } if (y == x) { System.out.println("1 1"); return; } // get count of factors Map<Integer, Integer> map = new HashMap<>(); // get factors // check for 2 as factor int num = (y/x); while (num % 2 == 0) { map.put(2, map.getOrDefault(2, 0) + 1); num /= 2; } for (int i=3; i <= Math.sqrt(num); i += 2) { while (num % i == 0) { map.put(i, map.getOrDefault(i, 0) + 1); num /= i; } } // check for the case of 25 if (num > 1) map.put(num, 1); // System.out.println("map = " + map); // check if ans exist int count = -1, ans = 1; for (Map.Entry<Integer, Integer> entry : map.entrySet()) { if (count != -1 && count != entry.getValue()) { // only possible ans is the num itself count = 1; ans = y/x; break; } if (count == -1) count = entry.getValue(); ans *= entry.getKey(); } System.out.println(count + " " + ans); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
8915b12649aac106a379fe6883649e9a
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; import java.lang.*; public class solve { static Scanner sc; public static void main (String[] args) { sc = new Scanner(System.in); // testCases int testCases = sc.nextInt(); // scan first-word while (testCases > 0) { justDoIt(); testCases--; } } // ==== SOLVE ============== static void justDoIt () { int x = sc.nextInt(), y = sc.nextInt(); if (y % x != 0) { System.out.println("0 0"); return; } // make factors Map<Integer, Integer> numCounts = makeFactors(y / x); // check if ans exist // count if all values of all nums(keys) are equal int ans = 1, count = -1; for (Map.Entry<Integer, Integer> entry : numCounts.entrySet()) { if (count == -1) count = entry.getValue(); if (entry.getValue() == count) { ans *= entry.getKey(); } else { System.out.println(1 + " " + (y/x)); return; } } System.out.println(count + " " + ans); } private static Map<Integer, Integer> makeFactors(int num) { Map<Integer, Integer> map = new HashMap<>(); int divider = 2; while (num % divider == 0) { map.put(divider, map.getOrDefault(divider, 0) + 1); num /= divider; } int sqrt = (int)Math.sqrt(num); for (divider = 3; divider <= sqrt; divider += 2) { while (num % divider == 0) { map.put(divider, map.getOrDefault(divider, 0) + 1); num /= divider; } } if (num > 2) map.put(num, 1); if (map.size() == 0) map.put(num, 1); // System.out.println("map = " + map); return map; } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
7bcc5581c8f284e8cc88dcca64f01e51
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { 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(y%x!=0){ System.out.println("0 0"); } else{ System.out.println("1 "+y/x); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
fa2b339612df1ed064cf1f2bc94fb8bd
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ /** * Main , Solution , Remove Public */ public class A { public static void process() throws IOException { long n = sc.nextLong(),m = sc.nextLong(); if(m%n == 0) { System.out.println("1 "+(m/n)); return; } System.out.println("0 0"); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; private static void google(int tt) { System.out.print("Case #" + (tt) + ": "); } static FastScanner sc; static FastWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new FastWriter(System.out); } else { sc = new FastScanner("input.txt"); out = new FastWriter("output.txt"); } long s = System.currentTimeMillis(); int t = 1; t = sc.nextInt(); int TTT = 1; while (t-- > 0) { // google(TTT++); process(); } out.flush(); // tr(System.currentTimeMillis()-s+"ms"); } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } //custom multiset (replace with HashMap if needed) public static void push(TreeMap<Integer, Integer> map, int k, int v) { //map[k] += v; if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { //assumes map[k] >= v //map[k] -= v int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } // compress Big value to Time Limit public static int[] compress(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int boof = 1; //min value for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } // Fast Writer public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } // Fast Inputs static class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readArrayDouble(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
a18feaa479a473e36425309103ac6c6b
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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(); if(x>y || y%x!=0) { System.out.println("0 0"); } else { int p=(int)(y/x); int temp=p; int b=2; int a=0; while(p!=1) { if(p%b!=0) { a=0; p=temp; b++; } else { p=p/b; a++; } } if(p==1) { if(a==0) { b=1; a=1; } System.out.println(a+" "+b); } else { System.out.println("0 0"); } } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
ed20ffba0d27a6c6610a170c01e5cf42
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Scanner; public class A_786 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); A_786 ob=new A_786(); int t=sc.nextInt(); StringBuilder ans=new StringBuilder(); while(t-->0) { int x=sc.nextInt(); int y=sc.nextInt(); ans.append(ob.solve(x,y)); } System.out.print(ans); } public StringBuilder solve(int x,int y) { StringBuilder sb=new StringBuilder(); if(y%x!=0) sb.append("0").append(" 0"+'\n'); else if(x==1) sb.append(1).append(" "+y+'\n'); else{ sb.append(1).append(" "+y/x+'\n'); } return sb; } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
c952c5ccff9a8e778d7f811e3394fa62
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class MyClass{ public static void main(String[] args){ Scanner scr= new Scanner(System.in); int t=scr.nextInt(); scr.nextLine(); while(t-->0){ int x=scr.nextInt(); int y=scr.nextInt(); if(y%x!=0){ System.out.println(0+" "+0); }else{ int b=y/x; int a=1; System.out.println(a+" "+b); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
7a142756d090a7b120d67b936850f1d2
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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(); if(x>y) { System.out.println("0 0"); continue; } double fact=(double)y/(double)x; if(Math.ceil(fact)==Math.floor(fact)) System.out.println("1 "+(int)fact); else System.out.println("0 0"); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
4ac42fc987d81f0f8ba7290cace96200
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Contest786A{ public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while(t-- > 0){ int[] a = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); if(a[1] % a[0] != 0){ pw.println(0 + " " + 0); } else{ pw.println(1 + " " + a[1] / a[0]); } } pw.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
3a0414159316daafc8d1a14fe15ea79f
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class A { //public static int list[] ={0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; //public static int b[] = {0, 1, 0, 0, 2 , 0, 0, 0, 2 , 3 , 0, 0, 0, 0, 0, 0, 4 , 0, 0, 0, 0, 0, 0, 0, 0, 5 , 0, 3 , 0, 0, 0, 0, 2 , 0, 0, 0, 6 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10}; //public static int a[] = {0, 1, 0, 0, 2 , 0, 0, 0, 3 , 2 , 0, 0, 0, 0, 0, 0, 2 , 0, 0, 0, 0, 0, 0, 0, 0, 2 , 0, 3 , 0, 0, 0, 0, 5 , 0, 0, 0, 2 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int out1[] = new int[t]; int out2[] = new int[t]; for(int i = 0; i<t; i++) { int x = sc.nextInt(); int y = sc.nextInt(); if(y%x!=0) { out1[i]=out2[i]=0; } else { out2[i] = y/x; out1[i] = 1; } } for(int i = 0; i<t; i++) { System.out.println(out1[i] + " " + out2[i]); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
b3f99d9487b8f472ba7fe030b832105c
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class Number { public static void main(String[] args) { Scanner input = new Scanner(System.in); long t = input.nextLong(); long a = 1; long b = 0; for (long i = 1; i <= t; ++i) { long x = input.nextLong(); long y = input.nextLong(); if (y % x == 0) { b = y / x; System.out.println(a + " " + b); } else { System.out.println("0 0"); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
bf154731162f3c12f44729e262b096aa
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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){ int a = sc.nextInt(); int b = sc.nextInt(); if(b%a==0){ System.out.println(1 +" "+b/a); } else System.out.println("0"+" "+"0"); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
8efb7c3841a84f7053880742afa65b49
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
//javac CF786_1.java; java CF786_1 import java.util.*; public final class CF786_1 { public static void main (String[] args) { Scanner in = new Scanner(System.in); int tnr = in.nextInt(); for (int t = 0; t < tnr; t++) { long x = in.nextLong(); long y = in.nextLong(); if(x == 1 && y == 1) { System.out.println("1 1"); } else { if (y == 1 || x > y || y%x != 0){ System.out.println("0 0"); } else { System.out.println(1 + " " + y/x); } } } in.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
54f8864c66a69dcadc00217b706244dd
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
//package codeForces; import java.io.*; import java.util.StringTokenizer; public class A_1674 { static void solve(FastReader sc) { int a = sc.nextInt(); int b = sc.nextInt(); if (a > b) { System.out.println("0 0"); } else { if (b % a != 0) { System.out.println("0 0"); } else { System.out.println(1 + " " + b / a); } } } public static void main(String[] args) { FastReader sc = new FastReader(); // int t = 1; int t = sc.nextInt(); for (int s = 0; s < t; s++) { solve(sc); } } static class FastReader { private final BufferedReader br; private StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } 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\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
787ba209e4386f33b7fdd93c5535903e
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int x = sc.nextInt(); int y = sc.nextInt(); if(y % x == 0) { System.out.println(1 + " " + y/x); } else { System.out.println(0 + " " + 0); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
fd21f21d0be87eceba22b1f57cf441ac
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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. */ public class Codechef { public static void solution(int x,int y) { int a=0; int b=0; if(x>y) { System.out.println("0"+" "+"0"); } else if(x==y) { System.out.println("1"+" "+"1"); } else if(y%x!=0) { System.out.println("0"+" "+"0"); } else{ a=y/x; b=1; System.out.println(b+" "+a); } } public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int test=sc.nextInt(); while(test-->0) { int x=sc.nextInt(); int y=sc.nextInt(); solution(x,y); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
001a13b3d9aa73e8e0669aeb496d0131
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { try(Scanner scanner = new Scanner(System.in)) { int t = Integer.parseInt(scanner.nextLine()); for (; t > 0; t--) { String[] line = scanner.nextLine().split(" "); int x = Integer.parseInt(line[0]); int y = Integer.parseInt(line[1]); if (y < x || y % x != 0) { System.out.println("0 0"); } else { y /= x; if (y == 1) { System.out.println("1 1"); } else { boolean correct = false; for (int i = 2; i <= y * x; i++) { int c = i; int times = 1; while (c < y) { c *= i; times++; } if (c == y) { System.out.println(times + " " + i); correct = true; break; } } if (!correct) { System.out.println("0 0"); } } } } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
3272172d8476c17eff25cf7eba4cd3bf
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Scanner; public class Ques1 { 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(); if(x!=0 && y%x==0) System.out.println(1+" "+(y/x)); else System.out.println("0 0"); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
2b03635060371a8e4b4bbc284122648e
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; import java.io.*; public class A { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); static StringTokenizer st = new StringTokenizer(""); static String next() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } static int nexti() throws IOException { return Integer.parseInt(next()); } public static void solve() throws IOException { int x = nexti(), y = nexti(); if (x > y || y % x != 0) {out.println("0 0"); return;} if (x == y) {out.println("1 1"); return;} if (y % x == 0) {out.println("1 " + (y / x)); return;} int t = y / x; int temp = t; boolean b = false; for (int i = 2; i * i <= t && !b; i++) { temp = t; int cnt = 0; while(temp % i == 0) { ++cnt; temp /= i; } if (temp == 1) { out.println(cnt + " " + i); b = true; return; } } if (!b) out.println("0 0"); } public static void main(String[] args) throws IOException { // int T = 1; int T = nexti(); while(T-->0) solve(); br.close(); out.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
9c3a9973e131cce22df3834504c98247
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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 a=sc.nextInt(); int b=sc.nextInt(); if(b%a!=0) { System.out.println("0 0"); continue; } int t=b/a; boolean flag=false; for(int i=1;i<=t && !flag;i++) { for(int j=1;j<=5;j++) { if(t==Math.pow(i,j)) { flag=true; System.out.println(j+" "+i); break; } } } if(!flag) System.out.println("0 0"); } sc.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
f7f0da7fc29761938e5fef5b9096aeae
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; import java.io.*; public class 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; } } public static void swap(long[] a, int i, int j) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void main(String[] args) { // TODO Auto-generated method stub FastReader t = new FastReader(); PrintWriter o = new PrintWriter(System.out); int test = t.nextInt(); while (test-- > 0) { long x = t.nextLong(); long y = t.nextLong(); long max = Integer.MIN_VALUE, min = Integer.MAX_VALUE; // int n = t.nextInt(); // long[] a = new long[n]; // for (int i = 0; i < n; ++i) { // a[i] = t.nextLong(); // } long a =0 ,b =0; if (y%x == 0 && y>=x) { long r = y/x; if (x == y) { a = 1; b = 1; } else { a = 1; b = r; } } o.println(a+" "+b); } o.flush(); o.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
a89a11b3890563b1e3129179fb5e713b
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Arrays; import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); for (int itc=0; itc<tc; itc++) { int x = sc.nextInt(); int y = sc.nextInt(); if (y % x != 0) { System.out.println("0 0"); } else { System.out.printf("%d %d%n", 1, y/x); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
eec89e66f37985f236e857003e74cdbf
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Arrays; import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); for (int itc=0; itc<tc; itc++) { boolean flag = true; int x = sc.nextInt(); int y = sc.nextInt(); double a = 1.0; double b = 1.0; while (flag == true) { if (y % x != 0) { flag = false; break; } b = (int)Math.pow(((double)y/(double)x), (1.0/(double)a)); if (Math.pow(b, a)*x == y) { break; } //System.out.println(b); if (Math.pow(b, a)>2) { flag = false; break; } //System.out.println(a); a++; } if (flag == false) { System.out.println("0 0"); } else { System.out.printf("%d %d%n", (int)a, (int)b); } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
d8bc71d431aa036758082ff404377be3
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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 a = 0; int b = 0; int x = sc.nextInt(); int y = sc.nextInt(); if (y%x !=0 ){ a = 0; b = 0; } else{ a = y / x ; b = 1; } String res = Integer.toString(b) + " "+ Integer.toString(a); System.out.println(res); t--; } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
5a9604fe85204a2e57e990b440fba046
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class ACM { private static int[][][] table = new int[101][101][2]; public static void main(String args[]) { computeTable(); Scanner in = new Scanner(System.in); for (int t = in.nextInt(); t > 0; t--) { int x = in.nextInt(); int y = in.nextInt(); int[] res = table[x][y]; System.out.print(res[0]); System.out.print(" "); System.out.println(res[1]); } } private static void computeTable() { for (int i = 100; i > 0; i--) table[i][i] = new int[]{1, 1}; for (int x = 50; x > 0; x--) { for (int b = 100 / x; b > 1; b--) { for (int a = 1; x * (int)Math.pow(b, a) <= 100; a++) { int y = x * (int)Math.pow(b, a); table[x][y] = new int[]{a, b}; } } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
26c69cd8cf5f3b26b15ebd5981669f2d
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.*; public class numberTransformation { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); sc.nextLine(); for (int i = 0; i < num; i++) { int x = sc.nextInt(); int y = sc.nextInt(); if (y < x || y%x!=0) { System.out.println(0 + " " + 0); } else { // System.out.println("here"); int prod = 0; int a = 0; int b = 0; for (int i1 = 1; i1 <= y; i1++) { a = i1; // System.out.println("here1"); for (int j = 1; j <= y; j++) { b = j; prod = x * (int)Math.pow(b, a); // System.out.println(prod); if (prod == y) { System.out.println(a + " " + b); break; } } if(prod == y) break; } } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
3ddceaa22f1495e6d2a9380931610ecd
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main{ static int mod = (int)1e9+7; static PrintWriter out; static int[] memo; static int n; static String line; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); Scanner sc=new Scanner(System.in); int t = sc.nextInt(); while(t--!=0) { int x = sc.nextInt(); int y = sc.nextInt(); int tmp = y/x; int tmp2 = y%x; //System.out.println(tmp+" "+tmp2); if(tmp==0||tmp2!=0) out.println("0 0"); else { out.println("1 "+tmp); } } out.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } 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 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(); } } static class pair implements Comparable<pair> { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
187301f9854aade0ceda0fab812a5dd3
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.util.Scanner; public class Main { public static Scanner cin; public static int[] sieve = new int[101]; public static void main(String[] args) { cin = new Scanner(System.in); int t = 1; t = cin.nextInt(); while (t-- > 0) { solve(); } } public static void solve() { int a = cin.nextInt(), b = cin.nextInt(); if (b % a == 0) { System.out.printf("%d %d\n", 1, b / a); } else { System.out.println("0 0 "); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
e08e7b2b473365297c416236e4d25599
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 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 tt=1;tt<=t;tt++) { int a=sc.nextInt(), b=sc.nextInt(); if(b%a!=0) System.out.println("0 0"); else System.out.println("1 "+b/a); } sc.close(); } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
747f51da3f2634d34f892c3d2b8a4664
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
/** * @Jai_Bajrang_Bali * @Har_Har_Mahadev */ //@Author : Sanat04 import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class practice2 { 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(y%x!=0) System.out.println(0+" "+0); else System.out.println(1+" "+y/x); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output
PASSED
eaf8cb14776d757ead980df8a76bbf5d
train_107.jsonl
1651502100
You are given two integers $$$x$$$ and $$$y$$$. You want to choose two strictly positive (greater than zero) integers $$$a$$$ and $$$b$$$, and then apply the following operation to $$$x$$$ exactly $$$a$$$ times: replace $$$x$$$ with $$$b \cdot x$$$.You want to find two positive integers $$$a$$$ and $$$b$$$ such that $$$x$$$ becomes equal to $$$y$$$ after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.For example: if $$$x = 3$$$ and $$$y = 75$$$, you may choose $$$a = 2$$$ and $$$b = 5$$$, so that $$$x$$$ becomes equal to $$$3 \cdot 5 \cdot 5 = 75$$$; if $$$x = 100$$$ and $$$y = 100$$$, you may choose $$$a = 3$$$ and $$$b = 1$$$, so that $$$x$$$ becomes equal to $$$100 \cdot 1 \cdot 1 \cdot 1 = 100$$$; if $$$x = 42$$$ and $$$y = 13$$$, there is no answer since you cannot decrease $$$x$$$ with the given operations.
512 megabytes
import java.io.*; import java.util.*; public class Main { static long d; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { int x = sc.nextInt(); int y = sc.nextInt(); boolean f = false; for (int i = 1; i <=y; i++) { int z = solve(i,x,y); if(z>0) { f = true; pw.println(z+" "+i); break; } } if(!f) pw.println("0 0"); } pw.flush(); } public static int solve(int b,int x,int y) { if(b==1) { if(x==y) { return 1; } return -1; } int c = 0; while(x<y) { x = b*x; c++; } if(x==y) return c; return -1; } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["3\n\n3 75\n\n100 100\n\n42 13"]
2 seconds
["2 5\n3 1\n0 0"]
null
Java 8
standard input
[ "constructive algorithms", "math" ]
f7defb09175c842de490aa13a4f5a0c9
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of one line containing two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le 100$$$).
800
If it is possible to choose a pair of positive integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$ after the aforementioned process, print these two integers. The integers you print should be not less than $$$1$$$ and not greater than $$$10^9$$$ (it can be shown that if the answer exists, there is a pair of integers $$$a$$$ and $$$b$$$ meeting these constraints). If there are multiple such pairs, print any of them. If it is impossible to choose a pair of integers $$$a$$$ and $$$b$$$ so that $$$x$$$ becomes $$$y$$$, print the integer $$$0$$$ twice.
standard output