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 | 9ce1e785a897b365dc20c85d0c11fa3b | 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();
for(int i=0;i<t;i++){
int a=sc.nextInt();
int b=sc.nextInt();
int out=0;
if(b/a==0||(b/a+b%a)!=b/a){
System.out.println("0 0");
continue;
}
else{
int temp=b/a;
if(temp==1){
System.out.println("1 1");
continue;
}
else{
for(int j=100;j>1;j--){
int check=1;
int counter=0;
while(temp%j==0&&check<temp){
check*=j;
counter++;
}
if(check==temp){
System.out.println(counter+" "+j);
out=1;
break;
}
}
}
}
if(out==0){
System.out.println("0 0");
}
}
// your code goes here
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 9120a5a58ede50e76d1b03e934e39206 | 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.lang.*;import java.util.*;
//* --> number of prime numbers less then or equal to x are --> x/ln(x)
//* --> String concatenation using the + operator within a loop should be avoided. Since the String object is immutable, each call for concatenation will
// result in a new String object being created.
// THE SIEVE USED HERE WILL RETURN A LIST CONTAINING ALL THE PRIME NUMBERS TILL N
public class codechef {static FastScanner sc;static PrintWriter pw;static class FastScanner {InputStreamReader is;BufferedReader br;StringTokenizer st;
public FastScanner() {is = new InputStreamReader(System.in);br = new BufferedReader(is);}
String next() throws Exception {while (st == null || !st.hasMoreElements())st = new StringTokenizer(br.readLine());
return st.nextToken();}int nextInt() throws Exception {return Integer.parseInt(next());}long nextLong() throws Exception {
return Long.parseLong(next());}int[] readArray(int num) throws Exception {int arr[]=new int[num];
for(int i=0;i<num;i++)arr[i]=nextInt();return arr;}String nextLine() throws Exception {return br.readLine();
}} public static boolean power_of_two(int a){if((a&(a-1))==0){ return true;}return false;}
static boolean PS(double x){if (x >= 0) {double i= Math.sqrt(x);if(i%1!=0){
return false;}return ((i * i) == x);}return false;}public static int[] ia(int n){int ar[]=new int[n];
return ar;}public static long[] la(int n){long ar[]=new long[n];return ar;}
public static void print(int ans,int t){System.out.println("Case"+" "+"#"+t+":"+" "+ans);}
static long mod=1000000007;static int max=Integer.MIN_VALUE;static int min=Integer.MAX_VALUE;
public static void sort(long[] arr){//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Long> ls = new ArrayList<Long>();for(long x: arr)ls.add(x);Collections.sort(ls);
for(int i=0; i < arr.length; i++)arr[i] = ls.get(i);}public static long fciel(long a, long b) {if (a == 0) return 0;return (a - 1) / b + 1;}
static boolean[] is_prime = new boolean[1000001];static ArrayList<Integer> list = new ArrayList<>();
static long n = 1000000;public static void sieve() {Arrays.fill(is_prime, true);
is_prime[0] = is_prime[1] = false;for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {for (int j = i * i; j <= n; j += i)is_prime[j] = false;}}for (int i = 2; i <= n; i++) {
if (is_prime[i]) {list.add(i);}}}
// ---------- NCR ---------- \
static int NC=100005;
static long inv[]=new long[NC];
static long fac_inv[]=new long[NC];
static long fac[]=new long[NC];public static void initialize()
{
long MOD=mod;
int i;
inv[1]=1;
for(i=2;i<=NC-2;i++)
inv[i]=(MOD-MOD/i)*inv[(int)MOD%i]%MOD;
fac[0]=fac[1]=1;
for(i=2;i<=NC-2;i++)
fac[i]=i*fac[i-1]%MOD;
fac_inv[0]=fac_inv[1]=1;
for(i=2;i<=NC-2;i++)
fac_inv[i]=inv[i]*fac_inv[i-1]%MOD;
}
public static long ncr(int n,int r)
{
long MOD=mod;
if(n<r) return 0;
return (fac[n]*fac_inv[r]%MOD)*fac_inv[n-r]%MOD;
}
// ---------- NCR ---------- \
// ---------- FACTORS -------- \
static int div[][] = new int[1000001][];
public static void factors()
{
int divCnt[] = new int[1000001];
for(int i = 1000000; i >= 1; --i) {
for(int j = i; j <= 1000000; j += i)
divCnt[j]++;
}
for(int i = 1; i <= 1000000; ++i)
div[i] = new int[divCnt[i]];
int ptr[] = new int[1000001];
for(int i = 1000000; i >= 1; --i) {
for(int j = i; j <= 1000000; j += i)
div[j][ptr[j]++] = i;
}
}
// ---------- FACTORS -------- \
// ------------- DSU ---------------\
static int par[]=new int[1000001];static int size[]=new int[1000001];
public static void make(int v){par[v]=v;size[v]++;}
public static void union(int a,int b){a=find(a);b=find(b);
if(a!=b){if(size[a]<size[b]){int temp=a;a=b;b=temp;}par[b]=a;
size[a]++;}}public static int find(int v)
{if(v==par[v]){return v;}return par[v]=find(par[v]);}
// ------------- DSU ---------------\
public static void main(String args[]) throws java.lang.Exception {
sc = new FastScanner();pw = new PrintWriter(System.out);StringBuilder s = new StringBuilder();
int t=sc.nextInt();
while(t-->0)
{
int x=sc.nextInt();
int y=sc.nextInt();
if(y%x!=0)
{
s.append(0+" "+0);
}
else{
s.append(1+" "+(y/x));
}
if(t>0)
{
s.append("\n");
}}
pw.print(s);pw.close();}}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | f19e9f6f0a4c0cd890cb6aaa83e7a7b8 | 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 String getAandB(int x, int y) {
if(x > y) return "0 0";
if(y%x == 0) return "1 " + (int)(y/x);
return "0 0";
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
try {
int t = s.nextInt();
for(int i=0;i<t;i++) {
int x = s.nextInt();
int y = s.nextInt();
System.out.println(getAandB(x, y));
}
} catch(Exception e) {
System.out.println("Exception: " + e);
e.printStackTrace();
} finally {
s.close();
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 69b37014066c55eab534ce8826930703 | 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 int mod = (int)1e9+7;
static boolean[] prime = new boolean[10];
static int[][] dir1 = new int[][] {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
static int[][] dir2 = new int[][] {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
static {
for (int i = 2; i < prime.length; i++)
prime[i] = true;
for (int i = 2; i < prime.length; i++) {
if (prime[i]) {
for (int k = 2; i * k < prime.length; k++) {
prime[i * k] = false;
}
}
}
}
static class JoinSet {
int[] fa;
JoinSet(int n) {
fa = new int[n];
for (int i = 0; i < n; i++)
fa[i] = i;
}
int find(int t) {
if (t != fa[t])
fa[t] = find(fa[t]);
return fa[t];
}
void join(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
}
}
static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
static int get() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Integer.parseInt(ss);
}
static long getx() throws Exception {
String ss = bf.readLine();
if (ss.contains(" "))
ss = ss.substring(0, ss.indexOf(" "));
return Long.parseLong(ss);
}
static int[] getint() throws Exception {
String[] s = bf.readLine().split(" ");
int[] a = new int[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(s[i]);
}
return a;
}
static long[] getlong() throws Exception {
String[] s = bf.readLine().split(" ");
long[] a = new long[s.length];
for (int i = 0; i < a.length; i++) {
a[i] = Long.parseLong(s[i]);
}
return a;
}
static String getstr() throws Exception {
return bf.readLine();
}
static void println() throws Exception {
bw.write("\n");
}
static void print(int a) throws Exception {
bw.write(a + "\n");
}
static void print(long a) throws Exception {
bw.write(a + "\n");
}
static void print(String a) throws Exception {
bw.write(a + "\n");
}
static void print(int[] a) throws Exception {
for (int i : a) {
bw.write(i + " ");
}
println();
}
static void print(long[] a) throws Exception {
for (long i : a) {
bw.write(i + " ");
}
println();
}
static void print(int[][] a) throws Exception {
for (int i[] : a)
print(i);
}
static void print(long[][] a) throws Exception {
for (long[] i : a)
print(i);
}
static void print(char[] a) throws Exception {
for (char i : a) {
bw.write(i + "");
}
println();
}
static long pow(long a, long b) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans *= a;
}
a *= a;
b >>= 1;
}
return ans;
}
static int powmod(long a, long b, int mod) {
long ans = 1;
while (b > 0) {
if ((b & 1) == 1) {
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return (int)ans;
}
static void sort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void sort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[i];
}
static void resort(int[] a) {
int n = a.length;
Integer[] b = new Integer[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static void resort(long[] a) {
int n = a.length;
Long[] b = new Long[n];
for (int i = 0; i < n; i++)
b[i] = a[i];
Arrays.sort(b);
for (int i = 0; i < n; i++)
a[i] = b[n - 1 - i];
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(long a, long b) {
return Math.max(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int max(int[] a) {
int max = a[0];
for (int i : a)
max = max(max, i);
return max;
}
static int min(int[] a) {
int min = a[0];
for (int i : a)
min = min(min, i);
return min;
}
static long max(long[] a) {
long max = a[0];
for (long i : a)
max = max(max, i);
return max;
}
static long min(long[] a) {
long min = a[0];
for (long i : a)
min = min(min, i);
return min;
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void yes() throws Exception {
print("Yes");
}
static void no() throws Exception {
print("No");
}
static int[] getarr(List<Integer> list) {
int n = list.size();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = list.get(i);
return a;
}
public static void main(String[] args) throws Exception {
int t = get();
while (t-- > 0){
int p[] = getint();
int x = p[0], y = p[1];
if(x > y || y%x!=0){
print(0+ " " + 0);
}else{
int k = y/x;
if(k == 1){
print(1+" "+1);
}else {
boolean ok = false;
int c = 1, r = 0;
for (int i = 2; i <= 100; i++) {
int l = i; c = 1;
while(l < k){
l*=i;
c++;
}
if(l == k){
ok = true;
r = i;
break;
}
}
if(ok) print(c+" "+r);
else print(0+" "+0);
}
}
}
bw.flush();
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 2745e547bafb389016183e656113e9a2 | 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.Objects;
import java.util.StringTokenizer;
public class Transform {
void solveCase(FScanner scanner) throws IOException {
int x = scanner.nextInt();
int y = scanner.nextInt();
boolean found = false;
int a=0, b=0;
if( x == y ) {
a = 1; b = 1;
found = true;
} else if(y%x==0) {
y /= x;
for (b = 2; b < 100; b++) {
int cnt = 0;
int tmp = y;
while (tmp % b == 0) {
tmp /= b;
cnt++;
}
if(tmp==1) {
found = true;
a = cnt;
break;
}
}
}
if (!found) {
a = 0; b=0;
}
out.println(a + " " + b);
out.flush();
}
private int findDiv(int n) {
int result = 1;
for (int i = 2; i <= (int) Math.sqrt(n); i++) {
if (n % i == 0) {
result = i;
}
}
return result;
}
//-----------------------------------------
InputStream sin;
PrintWriter out;
Transform() {
this(System.in, System.out);
}
Transform(InputStream sin, OutputStream sout) {
this.sin = sin;
out = new PrintWriter(new BufferedOutputStream(sout));
}
public FScanner createScanner() {
return new FScanner(sin);
}
void solve(FScanner scanner) throws IOException {
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
solveCase(scanner);
}
}
public static void main(String[] args) {
Transform task = new Transform();
FScanner scanner = task.createScanner();
try {
task.solve(scanner);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
static class FScanner {
private final BufferedReader bufferedReader;
StringTokenizer tokenizer;
public FScanner(InputStream inputStream) {
this.bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
}
public int nextInt() {
return Integer.parseInt(Objects.requireNonNull(next()));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
String line;
try {
line = bufferedReader.readLine();
} catch (IOException e) {
throw new RuntimeException("Input error", e);
}
if (line == null) return null;
tokenizer = new StringTokenizer(line);
}
return tokenizer.nextToken();
}
public int[] nextIntArr(int n) {
int[] result = new int[n];
for (int i = 0; i < n; i++) {
result[i] = Integer.parseInt(Objects.requireNonNull(next()));
}
return result;
}
public long[] nextLongArr(int n) {
long[] result = new long[n];
for (int i = 0; i < n; i++) {
result[i] = Long.parseLong(Objects.requireNonNull(next()));
}
return result;
}
public double[] nextDoubleArr(int n) {
double[] result = new double[n];
for (int i = 0; i < n; i++) {
result[i] = Double.parseDouble(Objects.requireNonNull(next()));
}
return result;
}
public String[] nextStringArr(int n) {
String[] result = new String[n];
for (int i = 0; i < n; i++) {
result[i] = Objects.requireNonNull(next());
}
return result;
}
}
// --------------
long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long gcdAll(long[] arr, int start) {
long g = arr[start];
if (arr.length > 2) {
for (int j = start + 2; j < arr.length; j += 2) {
g = gcd(arr[j], g);
}
}
return g;
}
void reverse(int[] arr) {
int n = arr.length;
for (int i = 0; i < n / 2; i++) {
int tmp = arr[i];
arr[i] = arr[n - 1 - i];
arr[n - 1 - i] = tmp;
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 9bc2cfa53086606b44429fae2f04ceba | 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 NumberTransformation {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++) {
int x=sc.nextInt();
int y=sc.nextInt();
if(y%x==0) {
int p=y/x;
System.out.println(1 +" "+p);
}
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 11 | 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 | 940a79636bfcd8325b9b320bbabe9205 | 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.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class A {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc=new Scanner(br);
int T=Integer.parseInt(sc.nextLine().trim());
for (int t=0; t<T; t++) {
int x= sc.nextInt(), y=sc.nextInt();
//Find prime divisors of y/x
sc.nextLine();
if (y%x == 0) System.out.printf("1 %d\n", y/x);
else 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 11 | 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 | f89d4f94249078074235102c7031e6f4 | 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 s = new Scanner(System.in);
int t = s.nextInt();
for(int i = 0; i<t; i++) {
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 11 | 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 | 6bd25319cb972c238bb584523890b503 | 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 s = new Scanner(System.in);
int t = s.nextInt();
for(int i = 0; i<t; i++) {
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 11 | 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 | c69734a71395ab3f36007420384f3a3c | 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.Scanner;
import java.util.*;
import java.lang.*;
import java.io.IOException;
import java.math.BigInteger;
public class Main
{
public static void main(String[] args) throws IOException
{
try
{
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
}
catch (Exception e)
{
System.err.println("Error");
}
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t--!=0)
{
int x = sc.nextInt();
int y = sc.nextInt();
// int find = y/x;
if(y<x || y%x!=0)
{
System.out.println("0 0");
}
else
{
int find = y/x;
System.out.println(1 + " " + find);
}
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 9b5b80a6eab2fd2631620dfd5703e012 | 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 A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0; i < t; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
if(((double)y/x) - (int)(y/x) != 0) System.out.println("0 0");
else {
int b = y/x;
int a = 1;
/*if(a != b) {
while( Math.sqrt(b) - (int) Math.sqrt(b) == 0) {
b = (int)Math.sqrt(b);
a++;
}
}*/
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 11 | 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 | 7957732d4e1a2cc2e3facf7a2c2e019c | 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 j=0;j<t;j++){
int x=sc.nextInt();
int y=sc.nextInt();
int c=0,s=0;
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 11 | 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 | afe079caa676b1c2e6ee69b4e94eda86 | 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 Sol1{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int ts = Integer.parseInt(scn.nextLine());
for(int t =0;t<ts;t++){
Double x = scn.nextDouble();
Double y = scn.nextDouble();
scn.nextLine();
int a=0,b=0;
Double equal = Math.log(y/x);
int i = 1;
int j = 1;
for(j=1;j<100;j++){
for(i=1;i<8;i++){
if(i*Math.log(j)==equal){
a=i;
b=j;
break;
}
}
}
System.out.println(a+" "+b);
// if(i*Math.log(j)==equal)System.out.println(1+" "+1);
// else{
// for(int m =1;m<30;m++){
// double num1 = Math.pow(Math.E, equal/m);
// double num2 = Math.ceil(Math.pow(Math.E, equal/m));
// if(Math.abs(num1-num2)<0.00000000001){
// a=m;
// b=(int)Math.ceil(Math.pow(Math.E, equal/m));
// break;
// }
// }
// System.out.println(a+" "+b);
// }
}
}
}
/*
3
3 75
100 100
42 13
*/ | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 6499d8afc1ed05fe7c3fb784c60b7270 | 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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Collections;
public class firstCF {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i =0;i<t;i++){
int x = sc.nextInt();
int y = sc.nextInt();
if(y%x != 0) System.out.print("0 0\n");
else System.out.print(1+" "+ (y/x)+"\n");
// int arr[] = new int[p];
// int carr[] = new int[p];
// for(int j =0;j<p;j++){
// arr[j] = sc.nextInt();
// }
// Arrays.sort(arr);
// for(int g =0;g<p;g++){
// carr[g] = arr[g];
// }
// int f =0;
// int x =0;
// int e =0;
// while(x<p){
// for(int b = e;b<p;b++){
// f = carr[x];
// arr[b] = arr[b] - f;
// }
// e = e+1;
// x = x+1;
// }
// if(arr[p-1]>=2) System.out.print("NO\n");
// else System.out.print("YES\n");
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | bb8781ba8ea5584ffdc9e983b5e4ae70 | 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) {
int a, b, c;
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
a = scanner.nextInt();
b = scanner.nextInt();
if ((b % a) != 0 || b < a) {
System.out.println(0 + " " + 0);
}else {
System.out.println(1 + " " + (b/a));
}
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | a7710f798d97403f12cb864158cc4508 | 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 P11 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
for(int h=0;h<t;h++){
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 11 | 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 | c89555afe3feb9cb51b5cb68d4974972 | 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{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args){
int t=sc.nextInt();
while(t-->0){
solve();
}
}
public static void solve(){
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 11 | 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 | 0026f9ca7a5c9e19132064199e646ed3 | 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 i = 0; i < t; i++) {
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 11 | 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 | 9939314fc85cd8ed8eff24a0111fd4de | 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 code {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
while(n-->0) {
int x=sc.nextInt();
int y=sc.nextInt();
if(x>y || y%x!=0)System.out.println(0+" "+0);
else {
int req = y/x;
System.out.println(1+" "+req);
}
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 7f19d12d47a3ff658d915d82caa72b3d | 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.Arrays;
public class Pair {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int numberSets = Integer.parseInt(br.readLine());
for (int nos = 0; nos<numberSets; nos++) {
int [] data = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int x = data[0];
int y = data[1];
boolean res = true;
if (x>y) {
System.out.println("0 0");
continue;
}
if (x==y) {
System.out.println("1 1");
continue;
}
if (y%x == 0) {
System.out.println("1 " + y/x);
continue;
}
loop1: for (int i = 1; i<=y/x; i++) {
for (int j = 1; j <= y/x; j++) {
if (y == x * Math.pow(i, j)) {
System.out.println(j + " " + i);
res = false;
break loop1;
}
}
}
if (res) {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 11 | 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 | 5d1c5c965098fdbe83a2b45cfca71313 | 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 NewClass{
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(0+" "+0);
else
{
int res=y/x;
x*=res;
System.out.println(1+" "+res);
}
t--;
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 6a8d954e1dd21d38a5a11c37d26bc7aa | 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 CardTrick{
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);
t--;
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 3fc7f78d939f381efa7275a41ae098c9 | 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 CardTrick{
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)
System.out.println(1+" "+1);
else if(y<x||y<2*x)
System.out.println(0+" "+0);
else{
int a=0,b=0;
for(int i=1;i<=10;i++){
for(int j=2;j<=100;j++){
if(x*(int)Math.pow(j,i)==y){
a=i;
b=j;
break;
}
}
}
System.out.println(a+ " " +b);
}
t--;
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 325faf1215e447b675ccc8e0bf5050af | 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 cf {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
// System.out.println(t);
while(test>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");
}
test--;
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 3ca5a0a81c50d038d9047512c9e96a7d | 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 Solution{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int iter=input.nextInt();
int x, y;
for(int i = 1; i<=iter; i++){
x = input.nextInt();
y = input.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 11 | 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 | 4c00c54647530c7776fb873cef725c88 | 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 queue {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
for (int i = 0; i < x; i++) {
int y = scan.nextInt();
int q = scan.nextInt();
if(y>q){
System.out.println("0 0");
}
else if(y==q){
System.out.println("1 1");
}
// 2 24
else if(q%y==0){
System.out.println(1+" " + q/y);
}
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 11 | 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 | 0b02214f9f3564c2e149f695f09ba570 | 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; // don't place package name! */
// algo_messiah23 , NIT RKL ...
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import static java.lang.System.*;
import java.util.stream.IntStream;
/* Name of the class has to be "Main" only if the class is public. */
public class CodeForces
{
static PrintWriter out=new PrintWriter((System.out));
static FastReader in = new FastReader();
static int INF = Integer.MAX_VALUE;
static int NINF = Integer.MIN_VALUE;
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int t=i();
while(t-->0)
{
solve();
}
out.close();
}
public static void solve()
{
int x=i();
int y=i();
if(x>y || y%x!=0)
out.println(0+" "+0);
else
{
int k=y/x;
out.println(1+" "+k);
}
}
static int[] input(int N){
int[] A=new int[N];
for(int i=0; i<N; i++)
A[i]=in.nextInt();
return A;
}
public static void print(int[] arr){
int n = arr.length;
for(int i = 0;i < n;i++){
out.print(arr[i] + " ");
}
out.println();
}
public static void sort(int[] arr){
ArrayList<Integer> ls = new ArrayList<>();
for(int x : arr){
ls.add(x);
}
Collections.sort(ls);
for(int i = 0;i < arr.length;i++){
arr[i] = ls.get(i);
}
}
public static void reverse(int[] arr){
int n = arr.length;
for(int i = 0;i < n/2;i++){
int temp = arr[i];
arr[i] = arr[n-1-i];
arr[n-1-i] = temp;
}
}
public static void reverse(long[] arr){
int n = arr.length;
for(int i = 0;i < n/2;i++){
long temp = arr[i];
arr[i] = arr[n-1-i];
arr[n-1-i] = temp;
}
}
public static void print(ArrayList<Integer> arr){
int n = arr.size();
for(int i = 0;i < n;i++){
out.print(arr.get(i) + " ");
}
out.println();
}
static int i()
{
return in.nextInt();
}
static long l()
{
return in.nextLong();
}
static char ich()
{
return in.next().charAt(0);
}
static String is()
{
return in.next();
}
static String isl()
{
return in.nextLine();
}
public static int max(int[] arr){
int max = -1;
int n = arr.length;
for(int i = 0;i < n;i++)
max = Math.max(max,arr[i]);
return max;
}
public static int min(int[] arr){
int min=INF;
int n=arr.length;
for(int i = 0;i< n;i++)
min=Math.min(min,arr[i]);
return min;
}
public static int gcd(int x, int y)
{
if (y==0){
return x;
}
return gcd(y,x%y);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | e7df155b4ec33619010e61fd026ab2d6 | 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 scanner = new Scanner(System.in);
int count = Integer.parseInt(scanner.nextLine());
while(count-- > 0) {
String[] strings = scanner.nextLine().split(" ");
int x = Integer.parseInt(strings[0]);
int y = Integer.parseInt(strings[1]);
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 11 | 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 | 5c9d020c61205dbe64fa9d7292d408c1 | 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.lang.*;
import java.util.*;
import java.io.*;
import java.awt.Point;
public class Main {
void solve() {
int t = ri();
while(t-- > 0) {
int x = ri(), y = ri();
if(y % x != 0) {
out.println("0 0");
} else {
out.printf("1 %d\n", y / x);
}
}
}
public static void main(String[] args) {
new Main().run();
}
void run() {
try {
solve();
out.close();
} catch(Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
String readLine() {
try {
return in.readLine();
} catch(Exception e) {
throw new RuntimeException(e);
}
}
String rs() {
while(!tok.hasMoreTokens()) {
tok = new StringTokenizer(readLine());
}
return tok.nextToken();
}
int ri() {
return Integer.parseInt(rs());
}
long rl() {
return Long.parseLong(rs());
}
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer tok = new StringTokenizer("");
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | d653e46bd2b8f57dcc115199d1af678c | 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 i=0;i<t;i++){
int x=sc.nextInt();
int y=sc.nextInt();
int a=1;
int b=y/x;
if(y%x!=0){
System.out.print(0);
System.out.print(" ");
System.out.print(0);
System.out.println();
}
else{
System.out.print(a);
System.out.print(" ");
System.out.print(b);
System.out.println();
}
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | f2a4729f83d6afe60e391dcc1b4f53c2 | 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 codeforce;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.io.*;
public class A {
static class Node {
int id1;
int id2;
Node(int v1, int w1){
this.id1= v1;
this.id2=w1;
}
Node(){}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
static boolean[] seiveofEratoSthenes(int n) {
boolean[] isPrime= new boolean[n+1];
Arrays.fill(isPrime, true);
isPrime[0]=false;
isPrime[1]= false;
for(int i=2;i*i<n;i++) {
for(int j=2*i; j<=n;j++) {
isPrime[j]= false;
}
}
return isPrime;
}
static int in = 2;
// Function check whether a number
// is prime or not
public static boolean isPrime(int n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static class SortingComparator implements Comparator<Node>{
@Override
public int compare(Node p1, Node p2) {
int n = p1.id1-p2.id1;
if(n!=0)return n;
return p2.id2-p1.id2;
}
}
static int pp =1;
static long[] dp = new long[500001];
public static void main(String[] args) {
FastReader sc=new FastReader();
PrintWriter out=new PrintWriter(System.out);
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);
}
}
out.close();
}
public static void rec(int l, int e, int[] arr) {
if(l>e || e>=arr.length || l<=0)return;
int mid = (e-l+1)%2==0?(e+l-1)/2:(e+l)/2;
if(arr[mid]==0 ) {
arr[mid]=pp;
pp++;
// if(pp>1)return;
}
if(e-mid-1<=mid-l-1) {rec(l, mid-1, arr);
rec(mid+1, e, arr);
}
else {
rec(mid+1, e, arr);
rec(l, mid-1, arr);
}
}
static double fact(double n)
{
int i=1;
double fact=1;
while(i<=n)
{
fact=fact*i;
i++;
}
return fact;
}
static double combination(int n,int r)
{
double com=fact(n)/(fact(n-r)*fact(r));
return com;
}
static boolean digit(long n) {
long ans = n;
while(n>0) {
long rem = n%10;
if(rem!=0 && ans%rem!=0)return false;
n=n/10;
}
return true;
}
static int nCr(int n, int r)
{
return fact(n) / (fact(r) *
fact(n - r));
}
// Returns factorial of n
static int fact(int n)
{
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l, Collections.reverseOrder());
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPalindrome(char[] arr, int i, int j) {
while(i<j) {
if(arr[i]!=arr[j])return false;
i++;
j--;
}
return true;
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static int max =0;
static void dfs(int i, boolean[] vis , ArrayList<ArrayList<Integer>> adj) {
max = Math.max(max, i);
vis[i]= true;
for(int e: adj.get(i)) {
if(vis[e]==false) {
dfs(e, vis, adj);
}
}
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static double pow(int a, int b) {
long res= 1;
while(b>0) {
if((b&1)!=0) {
res= (res*a);
}
a= (a*a);
b= b>>1;
}
return res;
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | d51d9742f66fe7132d102830fca598ff | 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 NumberTransformation {
public static void main(String[] args) {
Scanner input=new Scanner (System.in);
int t=input.nextInt();
int a,b;
for (int i=0;i<t;i++)
{
int x=input.nextInt();
int y=input.nextInt();
if (x>y)
{ a=b=0;
System.out.println(a+" "+b);}
else
{
if (y%x!=0)
{
a=b=0;
System.out.println(a+" "+b);
}
else
{
a=1;
b=y/x;
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 11 | 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 | 61213499d700f0e07c24c5e1d00e844e | 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.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class NumberTransformation {
public static void main(String[] args) {
FastScanner input=new FastScanner ();
int t=input.nextInt();
int a,b;
for (int i=0;i<t;i++)
{
int x=input.nextInt();
int y=input.nextInt();
if (x>y)
{ a=b=0;
System.out.println(a+" "+b);}
else
{
if (y%x!=0)
{
a=b=0;
System.out.println(a+" "+b);
}
else
{
a=1;
b=y/x;
System.out.println(a+" "+b);
}
}
}
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 6d8920cb2d3251460a55ac7e5ff45b44 | 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{
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;
}
public static void main(String[] args) {
try {
FastReader in=new FastReader();
FastWriter out = new FastWriter();
int testCases=in.nextInt();
List<String>answer=new ArrayList<>();
while(testCases-- > 0){
int[] arr=string_to_array(in.nextLine().split(" "));
if(arr[1]%arr[0]==0){
//for(int i=1;i<=rem;i++){
// for(int j=1;j<=rem;j++){
////out.println(Math.pow(i,j)+" "+rem);
// if(Math.pow(i,j)==rem){
// out.println(j+" "+i);
// ans=true;
// break;
// }
// }
// if(ans){
// break;
// }
//}
//if(!ans){
//out.println("0 0");
//}
out.println("1 "+(arr[1]/arr[0]));
}
else{
out.println("0 0");
}
}
for(String s:answer){
out.println(s);
}
out.close();
} catch (Exception e) {
return;
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 7251670d4fa2c4735ec5a5a1b1659bce | 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 | // 1:无需package
// 2: 类名必须Main, 不可修改
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
for (int i = 0; i < num; i++) {
int x = scan.nextInt();
int y = scan.nextInt();
int b;
int a;
boolean flag=false;
if (x > y || y % x != 0) {
System.out.println("0 0");
} if(x==1){
System.out.println("1 "+y);
} else if(y%x==0){
y = y / x;
for (b = 1; b <=100; b++) {
for (a=1;a<=100;a++) {
if ((int) Math.pow(b, a) == y) {
System.out.println(a + " " + b);
flag=true;
break;
}
}
if(flag){
break;
}if(b==100&&flag==false){
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 11 | 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 | bf2397b7f2e6b4bd9513bbb7f97eaa9c | 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.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class _1674A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
List<Map.Entry<Integer, Integer>> answers = new ArrayList<>(t);
for (int i = 0; i < t; ++i) {
int x = sc.nextInt();
int y = sc.nextInt();
if (y % x == 0) {
answers.add(Map.entry(1, y / x));
} else {
answers.add(Map.entry(0, 0));
}
}
System.out.println(
answers.stream()
.map(e -> String.format("%1$d %2$d", e.getKey(), e.getValue()))
.collect(Collectors.joining("\n"))
);
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 9fd8537ccaea676af88ccadc86df270f | 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.InputMismatchException;
public class A {
public static void main(String[] args) throws IOException {
ReadInput in = new ReadInput(System.in);
PrintWriter writer = new PrintWriter(System.out);
int t = in.nextInt();
for (int ti = 0; ti < t; ti++) {
int x = in.nextInt(), y = in.nextInt();
int a = 0;
int b = 0;
if (y >= x && y % x == 0) {
int k = y / x;
for (int i = 1; i <= 100; i++) {
int p = i;
for (int j = 1; j <= 6 && p <= 100; j++) {
if (k == p) {
a = j;
break;
}
p *= i;
}
if (a != 0) {
b = i;
break;
}
}
}
writer.println(a + " " + b);
}
in.close();
writer.flush();
writer.close();
}
public static class ReadInput {
private final BufferedReader source;
private String next;
public ReadInput(InputStream source) {
this.source = new BufferedReader(new InputStreamReader(source));
}
public ReadInput(String source) {
this.source = new BufferedReader(new StringReader(source));
}
public ReadInput(File source) throws IOException {
this.source = new BufferedReader(new FileReader(source));
}
public String next() throws IOException {
if (next == null) {
if (!hasNext()) {
throw new InputMismatchException("Nothing to read");
}
}
String res = next;
next = null;
return res;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public Double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean hasNext() throws IOException {
if (next != null) {
return true;
}
StringBuilder sb = new StringBuilder();
int read = skipSpaces();
while (read != -1 && !testSpaces(read)) {
sb.append((char) read);
read = source.read();
}
if (sb.length() > 0) {
next = sb.toString();
return true;
} else {
return false;
}
}
private int skipSpaces() throws IOException {
int read;
do {
read = source.read();
} while (testSpaces(read));
return read;
}
private boolean testSpaces(int c) {
return c == ' ' || c == '\r' || c == '\t' || c == '\n';
}
public void close() throws IOException {
next = null;
source.close();
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 19898cd254a016133d0842868fbbf211 | 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.InputMismatchException;
public class A {
public static void main(String[] args) throws IOException {
ReadInput in = new ReadInput(System.in);
PrintWriter writer = new PrintWriter(System.out);
int t = in.nextInt();
for (int ti = 0; ti < t; ti++) {
int x = in.nextInt(), y = in.nextInt();
int a = 0;
int b = 0;
if (y >= x && y % x == 0) {
int k = y / x;
for (int i = 1; i <= 100; i++) {
int p = i;
for (int j = 1; j <= 6; j++) {
if (k == p) {
a = j;
break;
}
p *= i;
}
if (a != 0) {
b = i;
break;
}
}
}
writer.println(a + " " + b);
}
in.close();
writer.flush();
writer.close();
}
public static class ReadInput {
private final BufferedReader source;
private String next;
public ReadInput(InputStream source) {
this.source = new BufferedReader(new InputStreamReader(source));
}
public ReadInput(String source) {
this.source = new BufferedReader(new StringReader(source));
}
public ReadInput(File source) throws IOException {
this.source = new BufferedReader(new FileReader(source));
}
public String next() throws IOException {
if (next == null) {
if (!hasNext()) {
throw new InputMismatchException("Nothing to read");
}
}
String res = next;
next = null;
return res;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public Double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean hasNext() throws IOException {
if (next != null) {
return true;
}
StringBuilder sb = new StringBuilder();
int read = skipSpaces();
while (read != -1 && !testSpaces(read)) {
sb.append((char) read);
read = source.read();
}
if (sb.length() > 0) {
next = sb.toString();
return true;
} else {
return false;
}
}
private int skipSpaces() throws IOException {
int read;
do {
read = source.read();
} while (testSpaces(read));
return read;
}
private boolean testSpaces(int c) {
return c == ' ' || c == '\r' || c == '\t' || c == '\n';
}
public void close() throws IOException {
next = null;
source.close();
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 1633209a101030090c09c7381c8dd105 | 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.InputMismatchException;
public class A {
public static void main(String[] args) throws IOException {
ReadInput in = new ReadInput(System.in);
PrintWriter writer = new PrintWriter(System.out);
int t = in.nextInt();
for (int ti = 0; ti < t; ti++) {
int x = in.nextInt(), y = in.nextInt();
int a = 0;
int b = 0;
if (y >= x && y % x == 0) {
int k = y / x;
for (int i = 1; i <= 100; i++) {
if (k == i) {
a = 1;
} else if (k == i * i) {
a = 2;
} else if (k == i * i * i) {
a = 3;
} else if (k == i * i * i * i) {
a = 4;
} else if (k == i * i * i * i * i) {
a = 5;
} else if (k == i * i * i * i * i * i) {
a = 6;
}
if (a != 0) {
b = i;
break;
}
}
}
System.out.println(a + " " + b);
}
in.close();
writer.flush();
writer.close();
}
public static class ReadInput {
private final BufferedReader source;
private String next;
public ReadInput(InputStream source) {
this.source = new BufferedReader(new InputStreamReader(source));
}
public ReadInput(String source) {
this.source = new BufferedReader(new StringReader(source));
}
public ReadInput(File source) throws IOException {
this.source = new BufferedReader(new FileReader(source));
}
public String next() throws IOException {
if (next == null) {
if (!hasNext()) {
throw new InputMismatchException("Nothing to read");
}
}
String res = next;
next = null;
return res;
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public Long nextLong() throws IOException {
return Long.parseLong(next());
}
public Double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean hasNext() throws IOException {
if (next != null) {
return true;
}
StringBuilder sb = new StringBuilder();
int read = skipSpaces();
while (read != -1 && !testSpaces(read)) {
sb.append((char) read);
read = source.read();
}
if (sb.length() > 0) {
next = sb.toString();
return true;
} else {
return false;
}
}
private int skipSpaces() throws IOException {
int read;
do {
read = source.read();
} while (testSpaces(read));
return read;
}
private boolean testSpaces(int c) {
return c == ' ' || c == '\r' || c == '\t' || c == '\n';
}
public void close() throws IOException {
next = null;
source.close();
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 86323f7186d901dc1cf3224bf22cd4b3 | 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.*;
public class test
{
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 11 | 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 | 2b1e6861733a82e8605e303572d61fd8 | 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.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.*;
public class Solution{
static int mod=(int)1e9+7;
static int mod1=998244353;
static FastScanner sc = new FastScanner();
public static void solve(){
int x=sc.nextInt(),y=sc.nextInt();
if(y%x==0){
System.out.println(1+" "+y/x);
}else
System.out.println(0+" "+0);
}
public static void main(String[] args) {
int t = sc.nextInt();
outer: for (int tt = 0; tt < t; tt++) {
solve();
}
}
static boolean isSubSequence(String str1, String str2,
int m, int n)
{
int j = 0;
for (int i = 0; i < n && j < m; i++)
if (str1.charAt(j) == str2.charAt(i))
j++;
return (j == m);
}
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 boolean 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 true;
else
return false;
}
static boolean isPrime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static int[] LPS(String s){
int[] lps=new int[s.length()];
int i=0,j=1;
while (j<s.length()) {
if(s.charAt(i)==s.charAt(j)){
lps[j]=i+1;
i++;
j++;
continue;
}else{
if (i==0) {
j++;
continue;
}
i=lps[i-1];
while(s.charAt(i)!=s.charAt(j) && i!=0) {
i=lps[i-1];
}
if(s.charAt(i)==s.charAt(j)){
lps[j]=i+1;
i++;
}
j++;
}
}
return lps;
}
static long getPairsCount(int n, double sum,int[] arr)
{
HashMap<Double, Integer> hm = new HashMap<>();
for (int i = 0; i < n; i++) {
if (!hm.containsKey((double)arr[i]))
hm.put((double)arr[i], 0);
hm.put((double)arr[i], hm.get((double)arr[i]) + 1);
}
long twice_count = 0;
for (int i = 0; i < n; i++) {
if (hm.get(sum - arr[i]) != null)
twice_count += hm.get(sum - arr[i]);
if (sum - (double)arr[i] == (double)arr[i])
twice_count--;
}
return twice_count / 2l;
}
static boolean[] sieveOfEratosthenes(int n)
{
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
prime[1]=false;
return prime;
}
static long power(long x, long y, long p)
{
long res = 1l;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if ((y & 1) != 0)
res = (res * x) % p;
y>>=1;
x = (x * x) % p;
}
return res;
}
public static int log2(int N)
{
int result = (int)(Math.log(N) / Math.log(2));
return result;
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////DO NOT READ AFTER THIS LINE //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
static long modFact(int n,
int p)
{
if (n >= p)
return 0;
long result = 1l;
for (int i = 2; i <= n; i++)
result = (result * i) % p;
return result;
}
static boolean isPalindrom(char[] arr, int i, int j) {
boolean ok = true;
while (i <= j) {
if (arr[i] != arr[j]) {
ok = false;
break;
}
i++;
j--;
}
return ok;
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(long a, long b) {
return Math.max(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void swap(long arr[], int i, int j) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static void swap(int arr[], int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int maxArr(int arr[]) {
int maxi = Integer.MIN_VALUE;
for (int x : arr)
maxi = max(maxi, x);
return maxi;
}
static int minArr(int arr[]) {
int mini = Integer.MAX_VALUE;
for (int x : arr)
mini = min(mini, x);
return mini;
}
static long maxArr(long arr[]) {
long maxi = Long.MIN_VALUE;
for (long x : arr)
maxi = max(maxi, x);
return maxi;
}
static long minArr(long arr[]) {
long mini = Long.MAX_VALUE;
for (long x : arr)
mini = min(mini, x);
return mini;
}
static int lcm(int a,int b){
return (int)(((long)a*b)/(long)gcd(a,b));
}
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static void ruffleSort(int[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
int temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
public static int binarySearch(int a[], int target) {
int left = 0;
int right = a.length - 1;
int mid = (left + right) / 2;
int i = 0;
while (left <= right) {
if (a[mid] <= target) {
i = mid + 1;
left = mid + 1;
} else {
right = mid - 1;
}
mid = (left + right) / 2;
}
return i-1;
}
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[] readLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
int[][] read2dArray(int n, int m) {
int arr[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = nextInt();
}
}
return arr;
}
ArrayList<Integer> readArrayList(int n) {
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int a = nextInt();
arr.add(a);
}
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Pair {
int val;
long coins;
Pair(int val,long coins) {
this.val=val;
this.coins=coins;
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 27380b7f9f4d72193fd76337988414bf | 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 numbertransform
{
public static void main (String[] args) throws IOException
{
PrintWriter pw = new PrintWriter(System.out);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for (int i = 0; i < t; i ++)
{
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
if (((double) y / (double) x) % 1 == 0)
{
pw.println("1"+ " " + y/x);
}
else
{
pw.println("0 0");
}
}
pw.close();
}
public static boolean isPrime(int i)
{
if (i == 1)
{
return false;
}
for (int j = 2; j < i; j++)
{
if (i % j == 0)
{
return true;
}
}
return false;
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 40767d45ef11502e413e004c99c54e72 | 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 Problem1674A {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws IOException {
int tc = scanner.nextInt();
while (tc-->0){
int x = scanner.nextInt();
int y = scanner.nextInt();
if (y%x==0){
System.out.println(1 + " " + y/x);
}else System.out.println(0 + " " + 0);
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader s) throws FileNotFoundException {
br = new BufferedReader(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 {
return Double.parseDouble(next());
}
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 11 | 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 | 80ed6b675c42ae97a4efe070095232c3 | 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 may2_A {
public static void main(String[] sss){
Scanner sc = new Scanner(System.in);
int test = sc.nextInt();
while(test-->0){
int x = sc.nextInt();
int y = sc.nextInt();
if(x>y || y%x!=0){
System.out.println("0 0");
}else {
y = y/x;
System.out.println("1 "+y);
}
}
sc.close();
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 1c24f9e368c7f2ea858dc639730452be | 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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class CF_786_A {
public static void main(String[] args) throws IOException{
try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out)){
int tCases = Integer.parseInt(br.readLine());
StringTokenizer st;
while (tCases-- > 0) {
st = new StringTokenizer(br.readLine());
long x = Long.parseLong(st.nextToken());
Long y = Long.parseLong(st.nextToken());
if (x > y || y % x != 0)
pw.println("0 0");
else {
Long b = y / x;
int a = 0;
if (x == 1) {
a = 1;
b = y;
}else {
while(b < y) {
b *= x;
++a;
}
}
if(b == y) pw.println(a + " " + b/x);
else pw.println("0 0");
}
}
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | ade9dd158e7b4e8993186f1b0aa7fb84 | 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 x = sc.nextInt();
int y = sc.nextInt();
if(x>y || y%x!=0)
{
System.out.println("0 0");
}
else{
int z = y/x;
int a = 0, b =0;
for(int i = 1 ; i <= z;i++)
{
for(int j = 1; j < 10 ; j++)
{
if(Math.pow(i,j) == z)
{
a = i;
b = j;
}
}
}
System.out.println(b+" "+a);
}
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 4064247c7cc15c993c62f3740d0837cd | 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.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
public class Binary_Tree_Creation {
static FastReader scn = new FastReader();
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class Node{
int data;
Node left;
Node right;
public Node(int data){
this.data = data;
}
}
static class BST{
Node root;
public BST(){
root = null;
}
public void insert(int data){
root = insertin(root, data);
}
private Node insertin(Node root, int data){
if(root == null){
Node n = new Node(data);
root = n;
return root;
}
if(root.data < data){
root.right = insertin(root.right, data);
}
else root.left = insertin(root.left, data);
return root;
}
public void print(){
InIt(root);
}
private void InIt(Node root){
if(root == null) return;
Stack<Node> st = new Stack<>();
while (true){
if (root != null){
st.add(root);
root = root.left;
}
else {
if (st.isEmpty()) break;
root = st.pop();
System.out.println(root.data);
root = root.right;
}
}
}
private void PreIt(Node root){
if(root == null) return;
Stack<Node> st = new Stack<>();
st.add(root);
while (!st.isEmpty()){
Node cur = st.pop();
System.out.println(cur.data);
if (cur.right != null)st.add(cur.right);
if(cur.left != null) st.add(cur.left);
}
}
private void inOrder(Node root){
if (root != null){
System.out.println(root.data);
inOrder(root.left);
inOrder(root.right);
}
}
private void Level(Node root){
if(root == null) return;
Queue<Node> q = new LinkedList<>();
q.add(root);
while (!q.isEmpty()){
Node cur = q.poll();
if(cur.left!= null) q.add(cur.left);
if(cur.right!= null) q.add(cur.right);
System.out.println(cur.data);
}
}
}
public static void main(String[] args) throws Exception {
int t = scn.nextInt();
while(t-->0){
int x = scn.nextInt();
int y = scn.nextInt();
if(x>y || y%x != 0){
System.out.println("0 " + "0");
}
else{
int rem = y/x;
System.out.println("1 " + rem);
}
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | cc9e46303ab6af00c8ad5c0f0fc6789a | 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 Shree Ram⛳⛳⛳
// Jai Bajrang Bali
// Jai Saraswati maa
// Thanks Kalash Shah :)
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class B {
static FastScanner sn = new FastScanner();
public static void main(String[] args) {
int T = sn.nextInt();
while (T-- > 0)
solve();
}
public static void solve() {
int x = sn.nextInt();
int y = sn.nextInt();
int a = 0, b = 0;
if (y % x != 0 || y < x) {
System.out.println(a + " " + b);
return;
}
int temp = y / x;
a = 1;
b = temp;
System.out.println(a + " " + b);
}
//----------------------------------------------------------------------------------//
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());
}
char nextChar() {
return next().charAt(0);
}
long[] readArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Debug {
public static void debug(long a) {
System.out.println("--> " + a);
}
public static void debug(long a, long b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(char a, char b) {
System.out.println("--> " + a + " + " + b);
}
public static void debug(int[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(char[] array) {
System.out.print("Array--> ");
System.out.println(Arrays.toString(array));
}
public static void debug(HashMap<Integer, Integer> map) {
System.out.print("Map--> " + map.toString());
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 69ece1f2c4754a8457a6cd81dcde43a6 | 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 Arbuz {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a =input.nextInt();
int[] numbers = new int[a*2];
for (int i = 0; i < numbers.length; i++)
{
numbers[i] = input.nextInt();
}
for (int i = 0; i < numbers.length ; i=i+2) {
if (numbers[i] >numbers[i+1] || numbers[i+1]%numbers[i]!=0 ) {
System.out.println(0);
System.out.println(0);
}
else{
System.out.println(1);
System.out.println(numbers[i+1]/numbers[i]);
}
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 3c8c0a69402e88ebb056b212ab2b557a | 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 Solution
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
long t=sc.nextLong();
while(t-->0){
long n=sc.nextLong();
long y=sc.nextLong();
if(y%n==0)
{
long ans=(long)y/n;
System.out.println("1 "+ans);
}
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 11 | 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 | 43ce131180cfe68acb68544cff695913 | 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 d3
{
//static boolean[] visited;
//static long min;
public static void main (String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
while(t-->0){
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
if(x > y || (y%x != 0)){
bw.write("0 0\n");
}
else if(x == y){
bw.write("1 1\n");
}
else{
y /= x;
bw.write("1 "+y+"\n");
}
}
bw.flush();
}
public static boolean palin1(String s){
int n = s.length()-1;
int mid = (n+1)/2;
for(int i = 0;i<mid;i++){
if(s.charAt(i) != s.charAt(n-i)){
return false;
}
}
return true;
}
public static long recur(int n,long[] ans){
return ans[n-1] + ans[n/2] +ans[n/3];
}
static class pair{
int a;
int b;
pair(int a,int b){
this.a = a;
this.b = b;
}
}
public static boolean check1(ArrayList<ArrayList<Integer>> graph,boolean[] visited){
for(int i = 0;i<visited.length;i++){
if(!visited[i] && graph.get(i).size() != 0){
if(dfs(i, graph, visited)){
return true;
}
}
print1(visited);
}
return false;
}
public static void print1(boolean[] visited){
for(int i = 0;i<visited.length;i++){
System.out.print(visited[i]+" ");
}
System.out.println();
}
public static boolean dfs(int i ,ArrayList<ArrayList<Integer>> g,boolean[] visited){
visited[i] = true;
for(int e : g.get(i)){
if(!visited[e]){
// if(dfs(e,g,visited) == true){
// System.out.println("ji");
// return true;
// }
// dfs(i, g, visited);
}
else{
return true;
}
}
return false;
}
public static boolean checksum(int n){
int temp = 0;
while(n > 0){
temp += n%10;
n /= 10;
}
return (temp == 10)?true:false;
}
public static class Node{
int val;
int freq;
Node(int val,int freq){
this.val = val;
this.freq = freq;
}
}
/* public static void dijk(ArrayList<ArrayList<pair>> graph,int i,boolean[] visited){
int[] dist = new int[visited.length];
for(int j = 0;j<dist.length;i++){
dist[j] = Integer.MAX_VALUE;
}
dist[i] = 0;
PriorityQueue<pair> queue = new PriorityQueue<>((pair a1,pair a2)->(a1.dist - a2.dist));
queue.add(new pair(i, 0));
while(!queue.isEmpty()){
pair p1 = queue.poll();
int current = p1.b;
if(visited[current]){
continue;
}
visited[current] = true;
for(pair p : graph.get(current)){
int childnode = p.b;
int childdist = p.dist;
if(!visited[childnode] && dist[childnode] > dist[current]+childdist){
dist[childnode] = dist[current]+childdist;
queue.add(p);
}
}
}
for(int j = 0;i<visited.length;j++){
System.out.println(dist[j]+" ");
}
}*/
public static int ceil(ArrayList<Long> al,long val){
int low = 0;
int high = al.size()-1;
int pos = 0;
while(low <= high){
int mid = (low+high)/2;
if(al.get(mid) == val){
pos = Math.max(pos,mid);
low = mid+1;
}
else if(al.get(mid) < val){
low = mid+1;
}
else{
high = mid-1;
}
}
return pos;
}
public static int floor(ArrayList<Long> al,long val){
int low = 0;
int high = al.size()-1;
int pos = high;
while(low <= high){
int mid = (low+high)/2;
if(al.get(mid) == val){
pos = Math.min(pos,mid);
high = mid-1;
}
else if(al.get(mid) < val){
low = mid+1;
}
else{
high = mid-1;
}
}
return pos;
}
public static boolean palin(String s){
for(int i = 0;i<s.length()/2;i++){
if(s.charAt(i) == s.charAt(s.length()-i-1)){
continue;
}
else{
return false;
}
}
return true;
}
public static long gcd(long a,long b){
if(b == 0L){
return a;
}
return gcd(b,a%b);
}
public static boolean check(ArrayList<Long> al,long mid,long m){
long cur = 0L;
for(int i = 0;i<al.size();i++){
if(al.get(i) <= mid){
cur++;
}
else{
cur += (al.get(i)/mid);
cur += (al.get(i)%mid != 0)?1L:0L;
}
}
return (cur <= m)?true:false;
}
// public static int bs(int sum,int low,int high){
// }
public static long fin(long n){
return ((long)n)*(n+1)/2;
}
public static int bceil(ArrayList<Integer> al,int val,int low,int high){
int index = 0;
while(low <= high){
int mid = low + (high-low)/2;
if(al.get(mid) <= val){
index = Math.max(mid,index);
low = mid+1;
}
else{
high = mid-1;
}
}
return index;
}
public static int bfloor(ArrayList<Integer> al,int val){
int low = 0;
int high = al.size()-1;
int index = -1;
while(low <= high){
int mid = low + (high-low)/2;
int mval = al.get(mid);
if(mval >= val){
high = mid-1;
index = Math.max(index,mid);
}
else{
low = mid+1;
}
}
return index;
}
public static String rev(String s){
StringBuffer sb = new StringBuffer(s);
sb.reverse();
return s+sb.toString();
}
public static String rev1(String s){
StringBuffer sb = new StringBuffer(s);
sb.reverse();
return sb.toString()+s;
}
public static long fact12(long a){
long l = 1L;
for(long i = 1;i<=a;i++){
l *= i;
}
// System.out.println(l);
return l;
}
public static boolean binary(ArrayList<Integer> al,int a1){
int low = 0;
int high = al.size();
while(low <= high){
int mid = (low+high)/2;
if(a1 == al.get(mid)){
return true;
}
else if(a1 > al.get(mid)){
low = mid+1;
}
else{
high = mid-1;
}
}
return false;
}
public static void primefact(int n){
for(int i = 2;i*i<=n;i++){
if(n%i == 0){
while(n%i == 0){
n /= i;
System.out.println(i);
}
}
}
System.out.println(n);
}
public static boolean prime(long n){
int count = 0;
for(long i = 1;i*i <= n;i++){
if(n%i == 0){
if(i*i == n){
count++;
}
else{
count += 2;
}
}
}
if(count == 2){
return true;
}
return false;
}
public static boolean bsearch(ArrayList<Integer> al,int low,int high,int req){
if(low > high || low < 0 || high < 0 || low >= al.size() || high >= al.size()){
return false;
}
int mid = (low+high)/2;
if(al.get(mid) == req){
return true;
}
else if(al.get(mid) > req){
high = mid-1;
bsearch(al, low, high, req);
}
else{
low = mid+1;
bsearch(al, low, high, req);
}
return false;
}
public static long fact1(int n){
long ans = 1L;
for(int i = 2;i<=n;i++){
ans *= i;
}
return ans;
}
public static String reverse(String s){
StringBuilder sb = new StringBuilder(s);
return sb.reverse().toString();
}
public static int find(int n){
return n*(n+1)/2;
}
public static double calc(int x1,int x2,int y1,int y2){
return Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 9ded46b0d9d3b4578f52b7093c6596b8 | 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.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.sqrt;
import static java.lang.Math.floor;
public class run_code {
static class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
static class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {}
TreeNode(int val) { this.val = val; }
TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
public static int max(int []nums, int s, int e) {
int max = Integer.MIN_VALUE;
for(int i = s; i <= e; i++) {
max = Math.max(max, nums[i]);
}
return max;
}
static int depth(TreeNode root) {
if(root == null)return 0;
int a = 1+ depth(root.left);
int b = 1+ depth(root.right);
return Math.max(a,b);
}
static HashSet<Integer>set = new HashSet<>();
static void deepestLeaves(TreeNode root, int cur_depth, int depth) {
if(root == null)return;
if(cur_depth == depth)set.add(root.val);
deepestLeaves(root.left,cur_depth+1,depth);
deepestLeaves(root.right,cur_depth+1,depth);
}
public static void print(TreeNode root) {
if(root == null)return;
System.out.print(root.val+" ");
System.out.println("er");
print(root.left);
print(root.right);
}
public static HashSet<Integer>original(TreeNode root){
int d = depth(root);
deepestLeaves(root,0,d);
return set;
}
static HashSet<Integer>set1 = new HashSet<>();
static void leaves(TreeNode root) {
if(root == null)return;
if(root.left == null && root.right == null)set1.add(root.val);
leaves(root.left);
leaves(root.right);
}
public static boolean check(HashSet<Integer>s, HashSet<Integer>s1) {
if(s.size() != s1.size())return false;
for(int a : s) {
if(!s1.contains(a))return false;
}
return true;
}
static TreeNode subTree;
public static void smallest_subTree(TreeNode root) {
if(root == null)return;
smallest_subTree(root.left);
smallest_subTree(root.right);
set1 = new HashSet<>();
leaves(root);
boolean smallest = check(set,set1);
if(smallest) {
subTree = root;
return;
}
}
public static TreeNode answer(TreeNode root) {
smallest_subTree(root);
return subTree;
}
}
static class Key<K1, K2>
{
public K1 key1;
public K2 key2;
public Key(K1 key1, K2 key2)
{
this.key1 = key1;
this.key2 = key2;
}
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Key key = (Key) o;
if (key1 != null ? !key1.equals(key.key1) : key.key1 != null) {
return false;
}
if (key2 != null ? !key2.equals(key.key2) : key.key2 != null) {
return false;
}
return true;
}
@Override
public int hashCode()
{
int result = key1 != null ? key1.hashCode() : 0;
result = 31 * result + (key2 != null ? key2.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[" + key1 + ", " + key2 + "]";
}
}
public static int sumOfDigits (long n) {
int sum = 0;
while(n > 0) {
sum += n%10;
n /= 10;
}
return sum;
}
public static void swap(int []ar, int i, int j) {
for(int k= j; k >= i; k--) {
int temp = ar[k];
ar[k] = ar[k+1];
ar[k+1] = temp;
}
}
public static int findOr(int[]bits){
int or=0;
for(int i=0;i<32;i++){
or=or<<1;
if(bits[i]>0)
or=or+1;
}
return or;
}
public static boolean[] getSieve(int n) {
boolean[] isPrime = new boolean[n+1];
for (int i = 2; i <= n; i++) isPrime[i] = true;
for (int i = 2; i*i <= n; i++) if (isPrime[i])
for (int j = i; i*j <= n; j++) isPrime[i*j] = false;
return isPrime;
}
public static Long gcd(Long a, Long b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}
static long nextPrime(long n) {
boolean found = false;
long prime = n;
while(!found) {
prime++;
if(isPrime(prime))
found = true;
}
return prime;
}
// method to return LCM of two numbers
static Long lcm(Long a, Long b)
{
return (a / gcd(a, b)) * b;
}
static boolean isPrime(long n) {
if(n <= 1)return false;
if(n <= 3)return true;
if(n%2 == 0 || n%3 == 0)return false;
for(int i = 5; i*i <= n; i+= 6) {
if(n%i == 0 || n%(i+2) == 0)
return false;
}
return true;
}
static int countGreater(int arr[], int n, int k){
int l = 0;
int r = n - 1;
// Stores the index of the left most element
// from the array which is greater than k
int leftGreater = n;
// Finds number of elements greater than k
while (l <= r) {
int m = l + (r - l) / 2;
// If mid element is greater than
// k update leftGreater and r
if (arr[m] > k) {
leftGreater = m;
r = m - 1;
}
// If mid element is less than
// or equal to k update l
else
l = m + 1;
}
// Return the count of elements greater than k
return (n - leftGreater);
}
static ArrayList<Integer>printDivisors(int n){
ArrayList<Integer>list = new ArrayList<>();
for (int i=1; i<=Math.sqrt(n); i++)
{
if (n%i==0)
{
// If divisors are equal, print only one
if (n/i == i)
list.add(i);
else // Otherwise print both
list.add(i);
list.add(n/i);
}
}
return list;
}
static void leftRotate(int l, int r,int arr[], int d)
{
for (int i = 0; i < d; i++)
leftRotatebyOne(l,r,arr);
}
static void leftRotatebyOne(int l, int r,int arr[])
{
int i, temp;
temp = arr[l];
for (i = l; i < r; i++)
arr[i] = arr[i + 1];
arr[r] = temp;
}
static class pairInPq<F extends Comparable<F>, S extends Comparable<S>>
implements Comparable<pairInPq<F, S>> {
private F first;
private S second;
public pairInPq(F first, S second){
this.first = first;
this.second = second;
}
public F getFirst(){return first;}
public S getSecond(){return second;}
// All the code you already have is fine
@Override
public int compareTo(pairInPq<F, S> o) {
int retVal = getSecond().compareTo(o.getSecond());
if (retVal != 0) {
return retVal;
}
return getFirst().compareTo(o.getFirst());
}
}
static long modInverse(long a, long m)
{
long m0 = m;
long y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
// q is quotient
long q = a / m;
long t = m;
// m is remainder now, process
// same as Euclid's algo
m = a % m;
a = t;
t = y;
// Update x and y
y = x - q * y;
x = t;
}
// Make x positive
if (x < 0)
x += m0;
return x;
}
static long power(long x, long y, long p)
{
long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
if (x == 0)
return 0; // In case x is divisible by p;
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static TreeNode buildTree(TreeNode root,int []ar, int l, int r){
if(l > r)return null;
int len = l+r;
if(len%2 != 0)len++;
int mid = (len)/2;
int v = ar[mid];
TreeNode temp = new TreeNode(v);
root = temp;
root.left = buildTree(root.left,ar,l,mid-1);
root.right = buildTree(root.right,ar,mid+1,r);
return root;
}
static int LIS(int arr[], int n)
{
int lis[] = new int[n];
int i, j, max = 0;
/* Initialize LIS values for all indexes */
for (i = 0; i < n; i++)
lis[i] = 1;
/* Compute optimized LIS values in
bottom up manner */
for (i = 1; i < n; i++)
for (j = 0; j < i; j++)
if (arr[i] >= arr[j] && lis[i] < lis[j] + 1)
lis[i] = lis[j] + 1;
/* Pick maximum of all LIS values */
for (i = 0; i < n; i++)
if (max < lis[i])
max = lis[i];
return max;
}
static void permuteString(String s , String answer)
{
if (s.length() == 0)
{
System.out.print(answer + " ");
return;
}
for(int i = 0 ;i < s.length(); i++)
{
char ch = s.charAt(i);
String left_substr = s.substring(0, i);
String right_substr = s.substring(i + 1);
String rest = left_substr + right_substr;
permuteString(rest, answer + ch);
}
}
static boolean isPowerOfTwo(long n)
{
if(n==0)
return false;
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) ==
(int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
static class Pair1{
long x;
long y;
public Pair1(long x, long y) {
this.x = x;
this.y = y;
}
}
static class Pair {
int x;
int y;
int z;
// Constructor
public Pair(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
static class Sorting implements Comparator<Pair>{
public int compare(Pair p1, Pair p2){
if(p1.x==p2.x){
return p1.y-p2.y;
}
return p1.x - p2.x;
}
}
static class Compare1{
static void compare(Pair arr[], int n)
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
return p1.z - p2.z;
}
});
}
}
static int min;
static int max;
static LinkedList<Integer>[]adj;
static int n;
static void insertlist(int n) {
for(int i = 0; i <= n; i++) {
adj[i] = new LinkedList<>();
}
}
static int []ar;
static boolean []vis;
static HashMap<Key,Integer>map;
static ArrayList<Integer>list;
static int dfs(int parent, int child,LinkedList<Integer>[]adj) {
list.add(parent);
for(int a : adj[parent]) {
if(vis[a] == false) {
vis[a] = true;
return 1+dfs(a,parent,adj);
}
}
return 0;
}
static StringTokenizer st;
static BufferedReader ob;
static int [] readarrayInt( int n)throws IOException {
st = new StringTokenizer(ob.readLine());
int []ar = new int[n];
for(int i = 0; i < n; i++) {
ar[i] = Integer.parseInt(st.nextToken());
}
return ar;
}
static long [] readarrayLong( int n)throws IOException {
st = new StringTokenizer(ob.readLine());
long []ar = new long[n];
for(int i = 0; i < n; i++) {
ar[i] = Long.parseLong(st.nextToken());
}
return ar;
}
static int readInt()throws IOException {
return Integer.parseInt(ob.readLine());
}
static long readLong()throws IOException {
return Long.parseLong(ob.readLine());
}
static int nextTokenInt() {
return Integer.parseInt(st.nextToken());
}
static long nextTokenLong() {
return Long.parseLong(st.nextToken());
}
static int root(int u) {
if(ar[u] == -1)return -1;
if(u == ar[u]) {
return u;
}
return root(ar[u]);
}
static Pair []pairar;
static int numberOfDiv(long num) {
int c = 0;
for(int i = 1; i <= Math.sqrt(num ); i++) {
if(num%i == 0) {
long d = num/i;
if( d == i)c++; else c += 2;
}
}
return c;
}
static long ans;
static int count;
static boolean []computed;
static void NoOfWays(int n) {
if(n == 0 ) {
count++;
}
if(n <= 0)return;
for(int i = 1; i <= n; i++) {
if(n+i <= n)
NoOfWays(n-i);
}
}
static boolean binarylistsearch( List<Integer>list, int l, int r, int s, int e) {
if(s > e)return false;
int mid = (s+e)/2;
if(list.get(mid) >= l && list.get(mid) < r) {
return true;
}else if(list.get(mid) > r) {
return binarylistsearch(list,l,r,s,mid-1);
}else if(list.get(mid) < l) {
return binarylistsearch(list,l,r,mid+1,e);
}
return false;
}
static int [][] readmatrix(int r, int c)throws IOException{
int [][]mat = new int[r][c];
for(int i = 0; i < r; i++) {
st = new StringTokenizer(ob.readLine());
for(int j = 0; j < c; j++) {
mat[i][j] = nextTokenInt();
}
}
return mat;
}
static HashSet<Integer>set1;
static boolean possible;
static int c = 0;
static void isbeautiful(HashSet<Integer>s,int num, List<Integer>good, int i, int x, int count) {
if(c == 2) {
possible = true;
return;
}
if(num >x || i == good.size())return;
if(num > x)return;
if(i >= good.size())return;
for(int j = i; j < good.size(); j++) {
if(!map.containsKey(new Key(num,good.get(j))) &&
!map.containsKey(new Key(good.get(j),num))){
if(s.contains(num) && s.contains(good.get(j)))
map.put(new Key (num,good.get(j)),1);
isbeautiful(s,num*good.get(j),good,i,x,count);
}
}
}
static long sum;
static long mod;
static void recur(HashSet<Integer>set,HashMap<Integer,HashSet<Integer>>map, int n, int j) {
if(j > n)return;
int v = 0;
for(int a : set) {
if(map.get(j).contains(a)) {
v++;
}
}
long d = map.get(j).size()-v;
sum = (sum*d)%mod;
HashSet<Integer> temp = map.get(j);
for(int num : temp) {
if(!set.contains(num)) {
set.add(num);
recur(set,map,n,j+1);
set.remove(num);
}
}
}
static int key1;
static int key2;
static HashSet<Integer>set;
public static TreeNode lowestCommonAncestor(TreeNode root) {
if(root == null)return null;
TreeNode left = lowestCommonAncestor(root.left);
TreeNode right =lowestCommonAncestor(root.right);
if(left == null && right != null) {
System.out.println(right.val);
return right;
}else if(right == null && left != null) {
System.out.println(left.val);
return left;
}else if(left == null && right == null) {
return null;
}else {
System.out.println(root.val);
return root;
}
}
static ArrayList<Integer>res;
static boolean poss = false;
public static void recur1 (char []ar, int i) {
if(i >= ar.length) {
boolean isPalindrome = false;
for(int k = 0; k < ar.length; k++) {
for(int j = 0; j < ar.length; j++) {
if(j-k+1 >= 5) {
int x = k;
int y = j;
while(x < y && ar[x] == ar[y]) {
x++;
y--;
}
if(x == y || x > y) {
isPalindrome = true;
}
}
}
}
if(!isPalindrome) {
poss = true;
}
}
if(i < ar.length && ar[i] == '?' ) {
ar[i] = '0';
recur1(ar,i+1);
ar[i] = '?';
}
if(i < ar.length && ar[i] == '?') {
ar[i] = '1';
recur1(ar,i+1);
ar[i] = '?';
}
if(i < ar.length && ar[i] != '?') {
recur1(ar,i+1);
}
}
static int []theArray;
static int rotate(int []ar, int element, int i) {
int count = 0;
while(ar[i] != element) {
int last = ar[i];
count++;
int prev = ar[1];
for(int j = 2; j <= i; j++) {
int temp = ar[j];
ar[j] = prev;
prev = temp;
}
ar[1] = prev;
}
return count;
}
static int []A;
static long nth(long max, long min, int n){
long mod = 1000000007;
if(max%min == 0){
System.out.println(min*n);
return (min*n)%mod;
}else{
long d = max/min;
d++;
long e = n/d;
long ans = (max*e)%mod;
long r = n%d;
long div = (ans/min);
long temp = (div*min);
long f = (temp*r)%mod;
ans = f;
if(temp == ans){
ans += min;
}
System.out.println(ans);
return ans;
}
}
public static int index(int k, int l, int r) {
if(r-l == 1) {
if(ar[r] >= k && ar[l] < k) {
return l;
}
}else if(l >= r){
return l;
}
int mid = (l+r)/2;
if(ar[mid] >= k) {
return index(k,l,mid-1);
}else {
return index(k,mid+1,r);
}
}
public static int remSnakes(int start, int end, int k) {
int rem = k-ar[end];
if(start+rem > end ) {
return 0;
}else {
return 1+ remSnakes(start+rem,end-1,k);
}
}
static int N;
static int []tree = new int[2*N];
static void build(int []arr,boolean odd) {
for(int i = 0; i < N; i++) {
tree[N+i] = arr[i];
}
for(int i = N-1; i > 0; --i) {
int left = i << 1;
int right = i << 1|1;
if(odd)
tree[i] = tree[i<<1]|tree[i<<1|1];
else
tree[i] = tree[i<<1]^tree[i<<1|1];
}
}
// function to update a tree node
static void updateTreeNode(int p, int value, boolean odd)
{
// set value at position p
tree[p + N] = value;
p = p + N;
// move upward and update parents
for (int i = p; i > 1; i >>= 1)
if(odd)
tree[i >> 1] = tree[i] | tree[i^1];
else
tree[i >> 1] = tree[i]^tree[i^1];
}
static int query(int l ,int r) {
int res = 0;
//loop to build the sum in the range
for(l += N, r += N; l < r; l >>= 1, r >>= 1) {
if((l&1) > 0) {
res += tree[--r];
}
if((r&1) > 0) {
res += tree[l++];
}
}
return res;
}
static int sum1;
static void min_line(int u, int min) {
for(int i : adj[u]) {
min_line(i,min);
}
System.out.println(u);
}
static class Key1 {
public final int X;
public final int Y;
public Key1(final int X, final int Y) {
this.X = X;
this.Y = Y;
}
public boolean equals (final Object O) {
if (!(O instanceof Key1)) return false;
if (((Key1) O).X != X) return false;
if (((Key1) O).Y != Y) return false;
return true;
}
public int hashCode() {
return (X << 16) + Y;
}
}
static void solve() {
int []points = new int[26];
int []top_pos = new int[26];
String []ar = {"ABC"};
Arrays.fill(top_pos, Integer.MAX_VALUE);
for(int i = 0; i < ar.length; i++) {
String s = ar[i];
for(int j = 0; j < s.length(); j++) {
int pos = 97-(s.charAt(j)-'0');
points[pos] += (j);
if(j < top_pos[pos]) {
top_pos[pos] = j;
}
}
}
int i = 0;
boolean []vis = new boolean[26];
StringBuilder sb = new StringBuilder();
while(true) {
int min = Integer.MAX_VALUE;
for(int j = 0; j < 26; j++) {
if(vis[j] == false) {
min = Math.min(min, points[j]);
}
}
if(min == Integer.MAX_VALUE)break;
PriorityQueue<pairInPq>pq = new PriorityQueue<>();
for(int j = 0; j < 26; j++) {
if(points[j] == min) {
vis[j] = true;
char c = (char)(j + 'a');
pq.add(new pairInPq(c,top_pos[j]));
}
}
while(pq.size() > 0) {
pairInPq p = pq.poll();
char c = (char)p.first;
sb.append(c);
}
}
String res = sb.toString();
res = res.toUpperCase();
System.out.println(res);
}
static boolean al_sub(String s, String a) {
int k = 0;
for(int i = 0; i < s.length(); i++) {
if(k == a.length())break;
if(s.charAt(i) == a.charAt(k)) {
k++;
}
}
return k == a.length();
}
static String result(String s, String a) {
char []s_ar = s.toCharArray();
char []a_ar = a.toCharArray();
StringBuilder sb = new StringBuilder();
if(s.length() < a.length()) {
for(int i = 0; i < s.length(); i++) {
if(s_ar[i] == '?')s_ar[i] = 'a';
}
}else {
if(al_sub(s,a)) {
return "-1";
}else {
int k = 0;
char element = 'z';
for(char i = 'a'; i <= 'e'; i++) {
char []temp = s.toCharArray();
boolean pos = true;;
for(int j = 0; j < s.length(); j++) {
if(temp[j] == '?') {
temp[j] = i;
}
}
boolean sub = false;
k = 0;
for(int j = 0; j < s.length(); j++) {
if(k == a.length()) {
pos = false;
break;
}
if(a_ar[k] == temp[j]) {
k++;
}
}
if(pos && k < a.length()) {
element = i;
break;
}
}
if(element == 'z')return "-1";
for(int i = 0; i < s.length(); i++) {
if(s_ar[i] == '?') {
s_ar[i] = element;
}
sb.append(s_ar[i]);
}
return sb.toString();
}
}
return "-1";
}
static void addNodes(ListNode l, int k) {
if(k > 10 )return;
ListNode temp = new ListNode(k);
l.next = temp;
addNodes(l.next,k+1);
}
static ListNode head;
static int listnode_recur(ListNode tail) {
if(tail == null )return 0;
int n = listnode_recur(tail.next);
max = Math.max(max, tail.val+head.val);
head = head.next;
return max;
}
static void recursion(int []fill, int len, int []valid, int k) {
if(k == len) {
int num = 0;
for(int i = 0; i < fill.length; i++) {
num = (num*10)+fill[i];
}
System.out.println(num);
if(!set.contains(num)) {
set.add(num);
}
return;
}
for(int i = 0; i < valid.length; i++) {
if(fill[k] == 0) {
fill[k] = valid[i];
recursion(fill,len,valid,k+1);
fill[k] = 0;
}else {
recursion(fill,len,valid,k+1);
}
}
}
static long minans(Long []ar,Long max) {
Long one = 0l;
Long two = 0l;
for(int i = 0; i < ar.length; i++) {
Long d = (max-ar[i])/2;
two += d;
one += (max-ar[i])%2;
}
Long ans = 0l;
if(one >= two) {
ans += (two*2);
// System.out.println(one+" "+two+" "+ans);
one -= two;
if(one > 0)
ans += (one*2)-1;
}else {
ans += (one*2);
if(two > 0) {
two -= one;
Long d = two/3;
Long temp = d*3;
Long r = two%3;
ans += temp;
ans += d;
if(r == 2) {
ans += 3;
}else if(r == 1){
ans += 2;
}
}
}
if(ans < 0)ans = 0l;
// System.out.println(one+" "+two+" "+ans);
return ans;
}
static int binarySearch(long []dif,long left, int s, int e) {
if(s > e)return s;
int mid = (s+e)/2;
if(dif[mid] > left) {
return binarySearch(dif,left,s,mid-1);
}else {
return binarySearch(dif,left,mid+1,e);
}
}
public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
int size1 = getLength(l1);
int size2 = getLength(l2);
ListNode head = new ListNode(1);
// make sure length l1 >= length2
head.next = size1 < size2?helper(l2,l1,size2-size1):helper(l1,l2,size1-size2);
if(head.next.val > 9) {
head.next.val = head.next.val%10;
return head;
}
return head.next;
}
public static int getLength(ListNode l1) {
int count = 0;
while(l1 != null) {
l1 = l1.next;
count++;
}
return count;
}
public static ListNode helper(ListNode l1, ListNode l2, int offset) {
if(l1 == null)return null;
ListNode result = offset == 0?new ListNode(l1.val+l2.val):new ListNode(l1.val);
System.out.println(l1.val+" "+l2.val);
ListNode post = offset == 0?helper(l1.next,l2.next,0):helper(l1.next,l2,offset-1);
if(post != null && post.val > 9) {
result.val += 1;
post.val = post.val%10;
}
result.next = post;
return result;
}
public static ListNode arrayToLinkedList(int []ar, ListNode head) {
head = new ListNode(0);
head.next = null;
ListNode h = head;
for(int i = 0; i < ar.length; i++) {
ListNode cur = new ListNode(ar[i]);
if(h == null) {
h = cur;
}else{
h.next = cur;
h = h.next;
}
}
return head.next;
}
static Long numLessThanN(Long n, int s, int e,Long []powerful) {
if(s >= e) {
if(powerful[s] > n)return powerful[s-1];
return powerful[s];
}
int mid = (s+e)/2;
if(powerful[mid] == n) {
return powerful[mid];
}else if(powerful[mid] > n && powerful[mid-1] < n) {
return powerful[mid-1];
}else if(powerful[mid] > n){
return numLessThanN(n,0,mid-1,powerful);
}else {
return numLessThanN(n,mid+1,e,powerful);
}
}
static Long minimumX;
static void minX(Long x, Long c) {
Long p = 2l;
Long a = x;
if(x > minimumX)return;
if(x == 1)return;
while(p*p <= x) {
int count = 0;
Long num = (long)Math.pow(p, c);
Long minx = lcm(num,x);
minx = minx/(gcd(num,x));
minimumX = Math.min(minimumX, minx);
// System.out.println(minimumX+" "+x+" "+p+" "+num);
//System.out.println(minx+" "+"df"+" "+p);
if(minx < x) {
minX(minx,c);
}
p++;
}
}
static boolean isConsecutive (List<Integer>list) {
for(int i : list) {
if(i > 3)return false;
}
int x = 0;
int y = 0;
for(int i = 0; i < list.size(); i++) {
if(list.get(i) == 2) {
x++;
}else if(list.get(i) == 3)y++;
}
if(y >= 2 || x >= 3)return false;
if(x > 0 && y > 0)return false;
return true;
}
static int []ismean(int []ar, int one, int minusone, int []temp){
int n = ar.length;
for(int i = 1; i < n-1; i++) {
if(temp[i] == 1 && temp[i-1] == -1 && one > 0) {
one--;
temp[i+1] = 1;
}else if(temp[i-1] == -1 && temp[i] == -1 && one > 0) {
temp[i+1] = 1;
one--;
}else if(temp[i] == -1 && temp[i-1] == 1 && minusone > 0) {
minusone--;
temp[i+1] = -1;
}else if(temp[i] == 1 && temp[i-1] == 1 && minusone > 0) {
minusone--;
temp[i+1] = -1;
}else {
return temp;
}
}
return temp;
}
static boolean isnottwo(int []ar, int one, int minusone,int temp[]) {
int n = ar.length;
int []ans = ismean(ar,one,minusone,temp);
if(ans[n-1] != -2)return true;
return false;
}
public static long findClosest(long arr[], long target)
{
int n = arr.length;
// Corner cases
if (target <= arr[0])
return arr[0];
if (target >= arr[n - 1])
return arr[n - 1];
// Doing binary search
int i = 0, j = n, mid = 0;
while (i < j) {
mid = (i + j) / 2;
if (arr[mid] == target)
return arr[mid];
/* If target is less than array element,
then search in left */
if (target < arr[mid]) {
// If target is greater than previous
// to mid, return closest of two
if (mid > 0 && target > arr[mid - 1])
return getClosest(arr[mid - 1],
arr[mid], target);
/* Repeat for left half */
j = mid;
}
// If target is greater than mid
else {
if (mid < n-1 && target < arr[mid + 1])
return getClosest(arr[mid],
arr[mid + 1], target);
i = mid + 1; // update i
}
}
// Only single element left after search
return arr[mid];
}
// Method to compare which one is the more close
// We find the closest by taking the difference
// between the target and both values. It assumes
// that val2 is greater than val1 and target lies
// between these two.
public static long getClosest(long val1, long val2,
long target)
{
if (target - val1 >= val2 - target)
return val2;
else
return val1;
}
static long minsumairblow;
static void airblow(int p,int n,long [][]ar, int index, long element, long sum) {
if(index == n) {
minsumairblow = Math.min(minsumairblow, sum);
return;
}
long left = Math.abs(element-ar[index][0]);
long right = Math.abs(element-ar[index][p-1]);
if(left <= right) {
airblow(p,n,ar,index+1,ar[index][p-1],sum+left);
}else {
airblow(p,n,ar,index+1,ar[index][0],sum+right);
}
}
static void helper() {
//
int n = 2;
long []ar =new long[n];
ArrayList<Long>odd = new ArrayList<>();
ArrayList<Long>even = new ArrayList<>();
for(int i = 0; i < n; i++) {
if(ar[i]%2 == 0) {
even.add(ar[i]);
}else {
odd.add(ar[i]);
}
}
Collections.sort(odd);
Collections.sort(even);
long alex = 0;
long bob = 0;
int i = even.size()-1;
int j = odd.size()-1;
int k = 0;
while(i > 0 && j > 0) {
alex += odd.get(j);
alex += even.get(i-1);
bob += even.get(i);
bob += odd.get(j-1);
i -= 2;
j -= 2;
}
if(j >= 0) {
alex += odd.get(j);
}
if(i >= 0) {
bob += even.get(i);
}
long alex1 = 0;
long bob1 = 0;
i = even.size()-1;
j = odd.size()-1;
k = 0;
while(i > 0 && j > 0) {
alex1 += even.get(i);
alex1 += odd.get(j-1);
bob1 += odd.get(j);
bob1 += even.get(i-1);
i -= 2;
j -= 2;
}
if(j >= 0) {
bob1 += odd.get(j);
}
if(i >= 0) {
alex1 += even.get(i);
}
long alex2 = 0;
long bob2 = 0;
i = even.size()-1;
j = odd.size()-1;
while(i > 0 && j > 0) {
alex2 += even.get(i);
alex2 += odd.get(j);
i--;
j--;
bob2 += even.get(i);
bob2 += odd.get(j);
i--;
j--;
}
if(i >= 0) {
alex2 += even.get(i);
} if(j >= 0) alex2 += odd.get(j);
long alex3 = 0;
long bob3 = 0;
i = even.size()-1;
j = odd.size()-1;
while(i > 0 && j > 0) {
alex3 += odd.get(j);
alex3 += even.get(i);
i--;
j--;
bob3 += odd.get(j);
bob3 += even.get(i);
i--;
j--;
}
if(i >= 0) {
alex3 += even.get(i);
} if(j >= 0) alex3 += odd.get(j);
long a = 0;
long b = 0;
long fin = alex;
long ans = alex+bob;
long ans1 = alex1+bob1;
long ans2 = alex2+bob2;
long ans3 = alex3+bob3;
long res = ans;
if(ans1 > res) {
fin = alex1;
res = ans1;
}
if(ans2 > res) {
fin = alex2;
res = ans2;
}
if(ans3 > res) {
fin = alex3;
res = ans3;
}
System.out.println(fin);
}
static boolean evenpoweroftwo(long num) {
int count = 0;
while(num > 2 && (num/2)%2 == 0) {
num /= 2;
count++;
}
if(num == 2) {
num = 1;
count++;
}
if(num == 1 && count%2 == 0)return true;
// System.out.println(num+" "+count);
return false;
}
static long maxscore;
static void max_score(int index,long []ar, int k, int z, long sum, int bit ) {
if(k == 0) {
maxscore = Math.max(maxscore,sum);
return;
}
sum += ar[index];
max_score(index+1,ar,k-1,z,sum,0);
if(bit == 0 && z > 0) {
max_score(index-1,ar,k-1,z-1,sum,1);
}
}
static boolean substringtrip(String s) {
int n = s.length();
if(s.length() == 1)return true;
HashSet<Character>set = new HashSet<>();
HashMap<Character,Integer>map = new HashMap<>();
for(int i = 0; i < s.length(); i++) {
set.add(s.charAt(i));
}
int counter = set.size();
HashSet<Character>temp = new HashSet<>();
String res = s;
int number = counter;
for(int i = 0; i < n && counter > 0; i++) {
if(temp.contains(s.charAt(i))) {
return false;
}
temp.add(s.charAt(i));
counter--;
}
int k1 = set.size();
for(int i = k1; i < s.length(); i++) {
if(s.charAt(i) != s.charAt(i-k1))return false;
}
return true;
}
static long res3;
static void maxteampos(long b,long c, long m, long d) {
if(b >= c) {
return;
}
long extra = c-(b);
extra += m-b;
extra += d;
// System.out.println(b);
if(extra >= c) {
res3 = Math.max(res3, b);
maxteampos((b+((c-b)/2))+1,c,m,d);
}else {
maxteampos(b/2,c,m,d);
}
return;
}
public static void main(String args[])throws IOException {
// System.setIn(new FileInputStream("case4.txt"));
BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(ob.readLine());
while(t --> 0) {
StringTokenizer st = new StringTokenizer(ob.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int b = 2;
int p = 0;
int q = 0;
while(b <= 100 ) {
int b1 = b;
int c = 1;
while(b1 <= 100) {
if((b1*x) == y) {
p = c;
q = b1;
break;
}
b1 *= b;
}
if(p != 0 && q != 0)break;
b++;
}
if(x == y) {
System.out.println(1+" "+1);
}else {
System.out.println(p+" "+q);
}
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | b4b3df121731ff21c1617635cc4ff5be | 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 q1 {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// public static long mod = 1000000007;
public static void solve() throws Exception {
String[] parts = br.readLine().split(" ");
int x = Integer.parseInt(parts[0]);
int y = Integer.parseInt(parts[1]);
if(x == y){
System.out.println("1 1");
return;
}
for(int b = 2;b <= 100;b++){
int count = 0,cx = x;
while(cx < y){
cx *= b;
count++;
}
if(cx == y){
System.out.println(count + " " + b);
return;
}
}
System.out.println("0 0");
}
public static void main(String[] args) throws Exception {
int tests = Integer.parseInt(br.readLine());
for (int test = 1; test <= tests; test++) {
solve();
}
}
// public static ArrayList<Integer> primes;
// public static void seive(int n){
// primes = new ArrayList<>();
// boolean[] arr = new boolean[n + 1];
// Arrays.fill(arr,true);
//
// for(int i = 2;i * i <= n;i++){
// if(arr[i]) {
// for (int j = i * i; j <= n; j += i) {
// arr[j] = false;
// }
// }
// }
// for(int i = 2;i <= n;i++) if(arr[i]) primes.add(i);
// }
// public static void sort(int[] arr){
// ArrayList<Integer> temp = new ArrayList<>();
// for(int val : arr) temp.add(val);
//
// Collections.sort(temp);
//
// for(int i = 0;i < arr.length;i++) arr[i] = temp.get(i);
// }
// public static void sort(long[] arr){
// ArrayList<Long> temp = new ArrayList<>();
// for(long val : arr) temp.add(val);
//
// Collections.sort(temp);
//
// for(int i = 0;i < arr.length;i++) arr[i] = temp.get(i);
// }
//
// public static long power(long a,long b,long mod){
// if(b == 0) return 1;
//
// long p = power(a,b / 2,mod);
// p = (p * p) % mod;
//
// if(b % 2 == 1) return (p * a) % mod;
// return p;
// }
// public static long modDivide(long a,long b,long mod){
// return ((a % mod) * (power(b,mod - 2,mod) % mod)) % mod;
// }
//
// public static int GCD(int a,int b){
// return b == 0 ? a : GCD(b,a % b);
// }
// public static long GCD(long a,long b){
// return b == 0 ? a : GCD(b,a % b);
// }
//
// public static int LCM(int a,int b){
// return a * b / GCD(a,b);
// }
// public static long LCM(long a,long b){
// return a * b / GCD(a,b);
// }
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | fb4a606aeb018e00617bab23c17b40a6 | 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 qrgs[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int x=1;x<=t;x++){
//System.out.print("Case #"+x+": ");
int n=sc.nextInt();
int m=sc.nextInt();
if(n>m)
System.out.println(0+" "+0);
else if(m%n==0)
System.out.println(1+" "+m/n);
else
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 11 | 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 | 49fcf16ab687892f10c311bffe1fb533 | 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.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigInteger;
public final class Main{
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();
}
}
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(new FileWriter(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 int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
static Kattio sc = new Kattio();
static long mod = 998244353l;
static PrintWriter out =new PrintWriter(System.out);
//Heapify function to maintain heap property.
public static void swap(int i,int j,int arr[]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,long arr[]) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,char arr[]) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static String endl = "\n" , gap = " ";
public static void main(String[] args)throws IOException {
int t =ri();
// List<Integer> list = new ArrayList<>();
// int MAX = (int)4e4;
// for(int i =1;i<=MAX;i++) {
// if(isPalindrome(i + "")) list.add(i);
// }
// // System.out.println(list);
// long dp[] = new long[MAX +1];
// dp[0] = 1;
// long mod = (long)(1e9+7);
// for(int x : list) {
// for(int i =1;i<=MAX;i++) {
// if(i >= x) {
// dp[i] += dp[i-x];
// dp[i] %= mod;
// }
// }
// }
// int MAK = (int)1e6;
// boolean seive[] = new boolean[MAK];
// Arrays.fill(seive , true);
// seive[1] = false;
// seive[0] = false;
// for (int i = 1; i < MAK; i++) {
// if(seive[i]) {
// for (int j = i+i; j < MAK; j+=i) {
// seive[j] = false;
// }
// }
// }
// for (int i = 1; i <= MAK; i++) {
// seive[i] += seive[i - 1];
// }
int test_case = 1;
while(t-->0) {
// out.write("Case #"+(test_case++)+": ");
solve();
}
out.close();
}
static HashMap<Integer , Boolean>dp;
public static void solve()throws IOException {
int x = ri() , y = ri();
if(x == y ){
System.out.println(1 +" "+ 1);
return;
}
if(y < x) {
System.out.println(0 + " " + 0);
return;
}
for(int a = 2;a<=y;a++) {
int time = 1;
while(true) {
int cur = (int)Math.pow(a , time)*x;
if(cur > y) break;
if(cur == y) {
System.out.println(time + " " + a);
return;
}
time++;
}
}
System.out.println("0 0");
}
public static double getSlope(int a , int b,int x,int y) {
if(a-x == 0) return Double.MAX_VALUE;
if(b-y == 0) return 0.0;
return ((double)b-(double)y)/((double)a-(double)x);
}
public static int callfun(int a[], int []b) {
HashMap<Integer , Integer> map = new HashMap<>();
int n = a.length;
for(int i =0;i<b.length;i++) {
map.put(b[i] , i);
}
HashMap<Integer , Integer> cnt = new HashMap<>();
for(int i =0;i<n;i++) {
int move = (map.get(a[i])-i+n)%n;
cnt.put(move , cnt.getOrDefault(move,0) + 1);
}
int max =0;
for(int x : cnt.keySet()) max = Math.max(max , cnt.get(x));
return max;
}
public static boolean collinearr(long a[] , long b[] , long c[]) {
return (b[1]-a[1])*(b[0]-c[0]) == (b[0]-a[0])*(b[1]-c[1]);
}
public static boolean isSquare(int sum) {
int root = (int)Math.sqrt(sum);
return root*root == sum;
}
public static boolean canPlcae(int prev,int len , int sum,int arr[],int idx) {
// System.out.println(sum + " is sum prev " + prev);
if(len == 0) {
if(isSquare(sum)) return true;
return false;
}
for(int i = prev;i<=9;i++) {
arr[idx] = i;
if(canPlcae(i, len-1,sum + i*i,arr,idx + 1)) {
return true;
}
}
return false;
}
public static boolean isPalindrome(String s) {
int i =0 , j = s.length() -1;
while(i <= j && s.charAt(i) == s.charAt(j)) {
i++;
j--;
}
return i>j;
}
// digit dp hint;
public static long callfun(String num , int N, int last ,int secondLast ,int bound ,long dp[][][][]) {
if(N == 1) {
if(last == -1 || secondLast == -1) return 0;
long answer = 0;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i = 0;i<=max;i++) {
if(last > secondLast && last > i) {
answer++;
}
if(last < secondLast && last < i) {
answer++;
}
}
return answer;
}
if(secondLast == -1 || last == -1 ){
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound, dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return answer;
}
if(dp[N][last][secondLast][bound] != -1) return dp[N][last][secondLast][bound];
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound,dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return dp[N][last][secondLast][bound] = answer;
}
public static Long callfun(int index ,int pair,int arr[],Long dp[][]) {
long mod = (long)998244353l;
if(index >= arr.length) return 1l;
if(dp[index][pair] != null) return dp[index][pair];
Long sum = 0l , ans = 0l;
if(arr[index]%2 == pair) {
return dp[index][pair] = callfun(index + 1,pair^1 , arr,dp)%mod + callfun(index + 1 ,pair , arr , dp)%mod;
}
else {
return dp[index][pair] = callfun(index + 1,pair , arr,dp)%mod;
}
// for(int i =index;i<arr.length;i++) {
// sum += arr[i];
// if(sum%2 == pair) {
// ans = ans + callfun(i + 1,pair^1,arr , dp)%mod;
// ans%=mod;
// }
// }
// return dp[index][pair] = ans;
}
public static boolean callfun(int index , int n,int neg , int pos , String s) {
if(neg < 0 || pos < 0) return false;
if(index >= n) return true;
if(s.charAt(0) == 'P') {
if(neg <= 0) return false;
return callfun(index + 1,n , neg-1 , pos , s.charAt(1) + "N");
}
else {
if(pos <= 0) return false;
return callfun(index + 1 , n , neg , pos-1 , s.charAt(1) + "P");
}
}
public static void getPerm(int n , char arr[] , String s ,List<String>list) {
if(n == 0) {
list.add(s);
return;
}
for(char ch : arr) {
getPerm(n-1 , arr , s+ ch,list);
}
}
public static int getLen(int i ,int j , char s[]) {
while(i >= 0 && j < s.length && s[i] == s[j]) {
i--;
j++;
}
i++;
j--;
if(i>j) return 0;
return j-i + 1;
}
public static int getMaxCount(String x) {
char s[] = x.toCharArray();
int max = 0;
int n = s.length;
for(int i =0;i<n;i++) {
max = Math.max(max,Math.max(getLen(i , i,s) , getLen(i ,i+1,s)));
}
return max;
}
public static double getDis(int arr[][] , int x, int y) {
double ans = 0.0;
for(int a[] : arr) {
int x1 = a[0] , y1 = a[1];
ans += Math.sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
}
return ans;
}
public static boolean valid(String x ) {
if(x.length() == 0) return true;
if(x.length() == 1) return false;
char s[] = x.toCharArray();
if(x.length() == 2) {
if(s[0] == s[1]) {
return false;
}
return true;
}
int r = 0 , b = 0;
for(char ch : x.toCharArray()) {
if(ch == 'R') r++;
else b++;
}
return (r >0 && b >0);
}
public static long callfun(int day , int k, int limit,int n) {
if(k > limit) return 0;
if(day > n) return 1;
long ans = callfun(day + 1 , k , limit, n)*k + callfun(day + 1,k+1,limit,n)*(k+1);
return ans;
}
public static void primeDivisor(HashMap<Long , Long >cnt , long num) {
for(long i = 2;i*i<=num;i++) {
while(num%i == 0) {
cnt.put(i ,(cnt.getOrDefault(i,0l) + 1));
num /= i;
}
}
if(num > 2) {
cnt.put(num ,(cnt.getOrDefault(num,0l) + 1));
}
}
public static boolean isSubsequene(char a[], char b[] ) {
int i =0 , j = 0;
while(i < a.length && j <b.length) {
if(a[i] == b[j]) {
j++;
}
i++;
}
return j >= b.length;
}
public static long fib(int n ,long M) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
long[][] mat = {{1, 1}, {1, 0}};
mat = pow(mat, n-1 , M);
return mat[0][0];
}
}
public static long[][] pow(long[][] mat, int n ,long M) {
if (n == 1) return mat;
else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M);
else return mul(pow(mul(mat, mat,M), n/2,M), mat , M);
}
static long[][] mul(long[][] p, long[][] q,long M) {
long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M;
long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M;
long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M;
long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M;
return new long[][] {{a, b}, {c, d}};
}
public static long[] kdane(long arr[]) {
int n = arr.length;
long dp[] = new long[n];
dp[0] = arr[0];
long ans = dp[0];
for(int i = 1;i<n;i++) {
dp[i] = Math.max(dp[i-1] + arr[i] , arr[i]);
ans = Math.max(ans , dp[i]);
}
return dp;
}
public static void update(int low , int high , int l , int r, int val , int treeIndex ,int tree[]) {
if(low > r || high < l || high < low) return;
if(l <= low && high <= r) {
System.out.println("At " +low + " and " + high + " ans ttreeIndex " + treeIndex);
tree[treeIndex] += val;
return;
}
int mid = low + (high - low)/2;
update(low , mid , l , r , val , treeIndex*2 + 1, tree);
update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree);
}
static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1};
static int coly[] = {0 ,0, 1,-1,1,-1,1,-1};
public static void reverse(char arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static long[] reverse(long arr[]) {
long newans[] = arr.clone();
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , newans);
i++;
j--;
}
return newans;
}
public static long inverse(long x , long mod) {
return pow(x , mod -2 , mod);
}
public static int maxArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static long maxArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static int minArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static long minArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static int sumArray(int arr[]) {
int ans = 0;
for(int x : arr) {
ans += x;
}
return ans;
}
public static long sumArray(long arr[]) {
long ans = 0;
for(long x : arr) {
ans += x;
}
return ans;
}
public static long rl() {
return sc.nextLong();
}
public static char[] rac() {
return sc.next().toCharArray();
}
public static String rs() {
return sc.next();
}
public static char rc() {
return sc.next().charAt(0);
}
public static int [] rai(int n) {
int ans[] = new int[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextInt();
}
return ans;
}
public static long [] ral(int n) {
long ans[] = new long[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextLong();
}
return ans;
}
public static int ri() {
return sc.nextInt();
}
public static int getValue(int num ) {
int ans = 0;
while(num > 0) {
ans++;
num = num&(num-1);
}
return ans;
}
public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][]) {
return x>=0 && x<n && y>=0 && y <n && !(arr[x][y] == '#');
}
// public static Pair join(Pair a , Pair b) {
// Pair res = new Pair(Math.min(a.min , b.min) , Math.max(a.max , b.max) , a.count + b.count);
// return res;
// }
// segment tree query over range
// public static int query(int node,int l , int r,int a,int b ,Pair tree[] ) {
// if(tree[node].max < a || tree[node].min > b) return 0;
// if(l > r) return 0;
// if(tree[node].min >= a && tree[node].max <= b) {
// return tree[node].count;
// }
// int mid = l + (r-l)/2;
// int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree);
// return ans;
// }
// // segment tree update over range
// public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) {
// if(l >= i && j >= r) {
// arr[node] += value;
// return;
// }
// if(j < l|| r < i) return;
// int mid = l + (r-l)/2;
// update(node*2 ,i ,j ,l,mid,value, arr);
// update(node*2 +1,i ,j ,mid + 1,r, value , arr);
// }
public static long pow(long a , long b , long mod) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2 , mod)%mod;
if(b%2 == 0) {
return (ans*ans)%mod;
}
else {
return ((ans*ans)%mod*a)%mod;
}
}
public static long pow(long a , long b ) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2);
if(b%2 == 0) {
return (ans*ans);
}
else {
return ((ans*ans)*a);
}
}
public static boolean isVowel(char ch) {
if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true;
if((ch == 'A' || ch == 'E'||ch == 'I' || ch == 'O' || ch == 'U')) return true;
return false;
}
public static int getFactor(int num) {
if(num==1) return 1;
int ans = 2;
int k = num/2;
for(int i = 2;i<=k;i++) {
if(num%i==0) ans++;
}
return Math.abs(ans);
}
public static int[] readarr()throws IOException {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i =0;i<n;i++) {
arr[i] = sc.nextInt();
}
return arr;
}
public static boolean isPowerOfTwo (long x) {
return x!=0 && ((x&(x-1)) == 0);
}
public static boolean isPrime(long num) {
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(long i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
public static boolean isPrime(int num) {
// System.out.println("At pr " + num);
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(int i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
// public static boolean isPrime(long num) {
// if(num==1) return false;
// if(num<=3) return true;
// if(num%2==0||num%3==0) return false;
// for(int i =5;i*i<=num;i+=6) {
// if(num%i==0) return false;
// }
// return true;
// }
public static long gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int get_gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long get_gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// public static long fac(long num) {
// long ans = 1;
// int mod = (int)1e9+7;
// for(long i = 2;i<=num;i++) {
// ans = (ans*i)%mod;
// }
// return ans;
// }
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 8314e916ca319df3fff7d243169c91fb | 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 G {
static FastScanner fs = new FastScanner();
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder("");
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int t = fs.nextInt();
// int t = 1;
for (int tt = 0; tt < t; tt++) {
int x = fs.nextInt();
int y = fs.nextInt();
if (x > y) sb.append(0 + " " + 0 + "\n");
if (y == x) sb.append(1 + " " + 1 + "\n");
if (y > x) {
if (y % x != 0) sb.append(0 + " " + 0 + "\n");
else sb.append(1 + " " + (y/x) + "\n");
}
}
pw.print(sb.toString());
pw.close();
}
static void sort(int[] a) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a)
al.add(i);
Collections.sort(al);
for (int i = 0; i < a.length; i++)
a[i] = al.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {while (!st.hasMoreTokens())try {st = new StringTokenizer(br.readLine());} catch (IOException e) {}return st.nextToken();}
int nextInt() {return Integer.parseInt(next());}
long nextLong() {return Long.parseLong(next());}
double nextDouble() {return Double.parseDouble(next());}
int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) {a[i] = nextInt();} return a;}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | f0d0310d98f410153a8e8f17de477aa0 | 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 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)
{
int x = n1.nextInt();
int y = n1.nextInt();
solve(x, y, output);
}
output.flush();
}
static void solve(int x, int y, PrintWriter output) throws Exception
{
int mult = y/x;
if(x*mult == y) output.print(1 + " " + mult + "\n");
else output.print(0 + " " + 0 +"\n");
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 1d978514188fafc622d13e03f2b88428 | 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 Answer {
public static void main(String[] args) {
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();
if(x > y) pw.println("0 0");
else if(y % x == 0) pw.println("1 " + (y/x));
else pw.println("0 0");
}
sc.close();
pw.close();
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | af09b5cfc69d6fddf038369135dac84d | 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);
// System.out.println(sc.nextByte());
// foodanimal(sc);
numtrans(sc);
}
private static void numtrans(Scanner scanner){
int testcase=scanner.nextInt();
for(int i=0;i<testcase;i++){
int f=scanner.nextInt();
int s=scanner.nextInt();
if(f>s)System.out.println(0+" "+0);
else{
int ans=s/f;
if(s%f!=0)System.out.println(0+" "+0);
else{
System.out.println(1+" "+ans);
}
}
}
}} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | ccd3e9274648b52141a5c39d99cde36c | 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 FastReader sc;
private static PrintWriter out;
public static void main( String[] args ) throws IOException {
Locale.setDefault( Locale.US );
Scanner in = new Scanner( System.in );
sc = new FastReader();
out = new PrintWriter( new BufferedOutputStream( System.out ));
int n = in.nextInt();
while( n --> 0 ) {
int a = in.nextInt();
int b = in.nextInt();
if( b % a == 0 ) {
System.out.println( 1 + " " + b / a );
} else {
System.out.println( "0 0" );
}
}
}
}
class FastReader {
BufferedReader bufferedReader;
StringTokenizer str;
public FastReader() {
bufferedReader = new BufferedReader( new InputStreamReader( System.in ));
}
String next() throws IOException {
while( str == null || !str.hasMoreElements()){
try {
str = new StringTokenizer( bufferedReader.readLine());
} catch( IOException Error ) {
Error.printStackTrace();
}
}
return str.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt( next());
}
public int[] nextIntArr( int n ) throws IOException {
int[] arr = new int[n];
for( int i = 0; i < n; ++i ) {
arr[i] = nextInt();
}
return arr;
}
long nextLong() throws IOException {
return Long.parseLong( next());
}
public long[] nextLongArr( int n )throws IOException {
long[] arr = new long[n];
for( int i = 0; i < n; ++i ) {
arr[i] = nextLong();
}
return arr;
}
double nextDouble() throws IOException {
return Double.parseDouble( next());
}
String nextLine() throws IOException {
String str = "";
try {
str = bufferedReader.readLine();
} catch( IOException Error ) {
Error.printStackTrace();
}
return str;
}
public char[] nextCharArr() throws IOException {
return next().toCharArray();
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | e2bee3e34657d646163ed2ed36814b7a | 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.FilterOutputStream;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
for(int t = in.nextInt();t>0;t--)
{
int x= in.nextInt(),y = in.nextInt();
System.out.println(y%x!=0 ? 0 + " " + 0 : 1 + " " + y/x);
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 6ee608237d68dd3ea017a2cfb6c9858a | 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_Transformation {
public static void main(String[] args) {
Scanner Scan = new Scanner(System.in);
//System.out.println("Test Cases :");
int t = Scan.nextInt();
for(int i=0; i<t; i++) {
//System.out.println("Enter x :");
int x = Scan.nextInt();
//System.out.println("Enter y :");
int y = Scan.nextInt();
if(x>y) {
System.out.println(0);
System.out.println(0);
}
else {
int f=0;
for(int b=1; b<=100; b++) {
int c=x;
int r=0,u=0;
for(int a=1; a<=100; a++) {
c*=b;
if(c==y) {
r=1;
u=a;
break;
}
}
if(r==1) {
System.out.println(u);
System.out.println(b);
f=1;
break;
}
}
if(f==0) {
System.out.println(0);
System.out.println(0);
}
}
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | c7e470a85df027fd05449cbebbe0376f | 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 i = 0; i < t; i++){
int x = sc.nextInt();
int y = sc.nextInt();
if (y/x == 0 || 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 11 | 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 | 95724ef15146d053fe83ca955f762bd3 | 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.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class A_Number_Transformation{
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc = new FastReader() ;
int check = sc.nextInt();
for(int tp=0;tp<check;tp++)
{
// int n= sc.nextInt();
// long arr[]=new long [n];
// for(int i=0;i<n;i++)
// {
// arr[i]=sc.nextLong();
// }
//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 x = sc.nextLong();
long y=sc.nextLong();
long a=1;
long b=y/x ;
if(y%x==0)
{
System.out.println(1+" "+b);
}
else
{
System.out.println(0+" "+0);
}
}
}
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 | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 6016c20a8af49f2e1f5ebd01e53e77fe | 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.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
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 swap(int []arr,int i,int j) {
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
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) {
int x=sc.nextInt();
int y=sc.nextInt();
if(x==y)System.out.println(1+" "+1);
else if(x>y)System.out.println(0+" "+0);
else {
if(y%x==0) {
int sq=y/x;
System.out.println(1+" "+sq);
}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 11 | 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 | 05605a14bb04238854d31da495849faa | 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 Codeforces11 {
public static void main(String[] args) throws java.lang.Exception {
Scanner i = new Scanner(System.in);
int t = i.nextInt();
while (t-- > 0) {
int x = i.nextInt();
int y = i.nextInt();
int a, b;
if (y % x == 0) {
a = 1;
b = y / x;
} else {
a = 0;
b = 0;
}
System.out.print(a + " ");
System.out.print(b + "\n");
}
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | e9c8a3d7f2a1c0f466e47b7fb5da9fcd | 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.ArrayList;
import java.util.List;
import java.util.Scanner;
public class myclass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
if(x > y || y%x != 0) {
System.out.println("0 0");
continue;
}
if ( x == y ) {
System.out.println("1 1");
continue;
}
int a = 1;
int b = y / x;
System.out.println(a + " " + b);
}
sc.close();
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | d21b99f47eeefe88879535385d592aa0 | 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.Arrays;
import java.util.InputMismatchException;
/*
By : SSD
*/
public class A {
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 A().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();
}
static void swap(int i, int j) {
int t = i;
i = j;
j = t;
}
private void solve() {
int tt = sc.nextInt();
while (tt-- > 0) {
int x = sc.nextInt(), y = sc.nextInt();
int a = 0, b = 0;
if (x == y) {
a = b = 1;
} else if (x < y && y % x == 0) {
int d = y / x;
b = d;
a = 1;
}
out.println(a + " " + b);
}
}
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 | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 85ab10ad8cc3d10bdb152aa264cd04a1 | 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 {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0){
int x = sc.nextInt();
int y = sc.nextInt();
if(y>= x && y%x==0){
System.out.println("1 "+y/x);
}else{
System.out.println("0 0");
}
}
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
if (st.hasMoreTokens()) {
str = st.nextToken("\n");
} else {
str = br.readLine();
}
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 4e5c36838708631bc1a02ca98a7c7bf1 | 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 sc=new Scanner(System.in);
int tc=sc.nextInt();
while(tc>0)
{
int x=sc.nextInt();
int y=sc.nextInt();
int l=y/x;
if(x<=y && y%x==0)
System.out.println("1 "+l);
else
System.out.println("0 "+"0 ");
--tc;
}}} | Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | ca362325d0c372227dcb035c6bd7d42d | 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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(System.out);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
for (int i = 0; i < test; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int a = 0;
int b = 0;
boolean flag = true;
for (int j = 1; j <= 10; j++) { // a
for (int k = 1; k <= 100; k++) { // b
if (x * Math.pow(k, j) == y) {
a = j;
b = k;
flag = false;
break;
}
}
if (!flag)
break;
}
pw.println(a + " " + b);
}
pw.flush();
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 399d4fbcc56f815ab984ec4ae782235b | 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 Lol {
//Hi my name is Vijay, My age is 27, My birthday is 17th Oct 1995.
static boolean isSqrt(int number)
{
double sqrt=Math.sqrt(number);
//finds the floor value of the square root and comparing it with zero
return ((sqrt - Math.floor(sqrt)) == 0);
}
static boolean iscube(int num)
{
int n = (int) Math.round(Math.pow(num, 1.0/3.0));
if((num == n * n * n)) return true;
else return false;
}
static boolean isPowerOfTwo(int n)
{
if(n==0)
return false;
return (int)(Math.ceil((Math.log(n) / Math.log(2)))) ==
(int)(Math.floor(((Math.log(n) / Math.log(2)))));
}
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);
else
{
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 11 | 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 | 5eb9a237b67b4841f0797e6f94716194 | 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.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class cf1674A {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0) {
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println(y%x==0 ? 1 + " " + y/x : "0 0");
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | ff111fa0c0e61aa674d2e7219a6a454e | 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.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class cf1674A {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0) {
int x = sc.nextInt();
int y = sc.nextInt();
int ab = y/x;
if((ab*x == y) && (ab == y/x)) {
System.out.println(1 + " " + ab);
}
else {
System.out.println("0 0");
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble() { return Double.parseDouble(next()); }
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["3\n\n3 75\n\n100 100\n\n42 13"] | 2 seconds | ["2 5\n3 1\n0 0"] | null | Java 11 | 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 | 71118d7c76944d6b17643aedf668ce4c | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
public class qE {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int countOfA = 0;
String s1 = sc.next();
String s2 = sc.next();
int lenS1 = s1.length();
int lenS2 = s2.length();
for(Character ch : s2.toCharArray()){
if(ch == 'a'){
countOfA++;
}
}
if(lenS2-countOfA>0 && countOfA!=0){
System.out.println(-1);
}
else if(lenS2-countOfA == 0 && lenS2>=2){
System.out.println(-1);
}
else if(lenS2-countOfA == 0){
System.out.println(1);
}else{
long ans = (long) Math.pow(2, lenS1);
System.out.println(ans);
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 82d52fbf316aff45ac7c179e768faaef | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
public class qE {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int countOfA = 0;
String s1 = sc.next();
String s2 = sc.next();
int lenS1 = s1.length();
int lenS2 = s2.length();
for(Character ch : s2.toCharArray()){
if(ch == 'a'){
countOfA++;
}
}
if(countOfA == 1 && lenS2 == 1){
System.out.println(1);
}
else if(countOfA > 0){
System.out.println(-1);
}else{
long ans = (long) Math.pow(2, lenS1);
System.out.println(ans);
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | dc46e08fdd84e2bee73966ae4d9afd6c | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
public class scratch{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int test=in.nextInt();
while(test-->0)
{
int flg=0;
String a=in.next();
String st=in.next();
if(st.length()==1&&st.charAt(0)=='a')
System.out.println("1");
else {
for (int i = 0; i < st.length(); i++)
{
if(st.charAt(i)=='a') {
System.out.println("-1");
flg=1;
break;
}
}
if(flg!=1)
{
if(st.length()==1&&a.length()==1)
System.out.println("2");
else {
long d=(long)(Math.pow(2,(a.length())));
System.out.println(d);
}
}
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | a71d696c52dde53518548c0b149caae5 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
// int n = sc.nextInt();
String s = sc.next();
String tt = sc.next();
if (tt.equals("a")) {
System.out.println(1);
continue;
}
long res = -1;
boolean flag = false;
for (var c : tt.toCharArray())
if (c == 'a')
flag = true;
if (!flag)
res = 1L << (s.length());
// boolean[] left = new boolean[n];
// for (int i = 0; i < n; ++i) {
// if (s1.charAt(i) == '1' && (s.charAt(i) == '0'
// || ((i > 0 && s.charAt(i - 1) == '1') || (i < s.length() - 1 && s.charAt(i +
// 1) == '1'))))
// left[i] = true;
// }
// boolean[] right = new boolean[n];
// for (int i = n - 1; i >= 0; --i) {
// if (s1.charAt(i) == '1' &&
// (s.charAt(i) == '0' || ((i > 0 && s.charAt(i - 1) == '1')
// || (i < s.length() - 1 && s.charAt(i + 1) == '1'))))
// right[i] = true;
// }
// for(int i = 0;i<n;++i)
// res += left[i] || right[i] ? 1 : 0;
System.out.println(res);
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 8d8f8c389182e0a4714600d22b96b18d | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
/**
* C_Infinite_Replacement
*/
public class C_Infinite_Replacement {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t= scn.nextInt();
for (int i = 0; i < t; i++) {
String a=scn.next();
String b=scn.next();
if(b.length()==1&&b.charAt(0)=='a')
System.out.println(1);
else if(b.length()>0)
{
long count=0;
for(int j=0;j<b.length();j++)
{
if(b.charAt(j)=='a')
count++;
}
if(count>0)
System.out.println(-1);
else if(count==0)
System.out.println((long)Math.pow(2,a.length()));
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | d1a26b8a7382a6415ea1bde09e686ab9 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class C_Infinite_Replacement {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- != 0) {
String s1 = sc.next(), s2 = sc.next();
if (s2.length() == 1 && s2.charAt(0) == 'a')
System.out.println(1);
else if (s2.contains("" + 'a'))
System.out.println(-1);
else {
long res = (long) 1 << (long) (s1.length());
System.out.println(res);
}
}
sc.close();
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 704be880abf70e2677fe0ac3abecbf95 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class C_Infinite_Replacement {
static long f(long n) {
if (n == 1)
return n;
return n * f(n - 1);
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
long arr[] = new long[51];
for (int i = 1; i < 51; i++) {
arr[i] = f(i + 1);
}
int t = sc.nextInt();
while (t-- != 0) {
String s1 = sc.next(), s2 = sc.next();
if (s2.length() == 1 && s2.charAt(0) == 'a')
System.out.println(1);
else if (s2.contains("" + 'a'))
System.out.println(-1);
else {
long res = (long) 1 << (long) (s1.length());
System.out.println(res);
}
}
sc.close();
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | c88a8085d5c4de0476fe7d00d935b499 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class cp2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for (int tt = 0; tt < t; tt++) {
String s =sc.next();
String k =sc.next();
int counta=0;
for( int i=0;i<k.length();i++){
if(k.charAt(i) == 'a'){
counta++;
}
}
if(counta ==k.length() && k.length()==1){
System.out.println("1");
}else if(counta ==k.length() && k.length()>1){
System.out.println("-1");
}
else if(counta>0 && counta!=k.length()){
System.out.println("-1");
}else if(counta==0){
System.out.println((long)Math.pow(2,s.length()));
}
}
sc.close();
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 84c23a67a68ba2531e5a5f600679b114 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class InfiniteReplacement {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
for (int i = 0; i < n; i++) { // n times iteration == O(n)
String a = s.next();
String b = s.next();
if (b.contains('a' + "") && b.length() == 1){
System.out.println(1);
}
else if (b.contains('a' + "") && b.length() != 1) {
System.out.println(-1);
} else {
System.out.println((long) Math.pow(2, a.length()));
}
}
}
}
| Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 10457815bbeeebc683a37ac37e67e1a0 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Question {
public static long fun(String a,String b){
if(b.length() == 1 && b.charAt(0) == 'a'){
return 1;
}
int count =0;
for(int i=0;i<b.length();i++){
if(b.charAt(i) == 'a'){
count++;
}
}
if(count>1 || count ==1 && b.length() >1){
return -1;
}
return (long)Math.pow(2, a.length());
}
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
input.nextLine();
for(int i =0;i<t;i++){
String a = input.nextLine();
String b = input.nextLine();
long val = fun(a,b);
System.out.println(val);
}
}
}
//next 32
// try more of string manupulation questions | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | e47474d9fd25a9baf9fb8f142bcacd52 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
import java.io.*;
public class C {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
while(T-- >0) {
String s = sc.nextLine().trim();
String t = sc.nextLine().trim();
boolean cA = t.contains("a");
int lt = t.length();
long ans;
if (cA && lt != 1)
ans = -1;
else if (cA)
ans = 1;
else
ans = (long) Math.pow(2, s.length());
System.out.println(ans);
}
sc.close();
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | edf44a826916e3ea263ab0b36afbceec | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
import java.lang.Math;
public class problem4 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
String s = sc.next();
String tk = sc.next();
long length_of_tk=tk.length();
if(length_of_tk == 1 && tk.charAt(0) == 'a'){
System.out.println("1");
}
else{
long cnt = 0;
for(int i=0;i<length_of_tk;i++){
if(tk.charAt(i) == 'a'){
cnt++;
}
}
if(cnt == 0){
System.out.println((long)Math.pow(2, s.length()));
}
else{
System.out.println("-1");
}
}
}
}
}
| Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 09a4cf77b763eda66f2a6bd97db4db83 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 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;
String r=s.nextLine();
String t=s.nextLine();
if(t.length()==1&&t.charAt(0)=='a')
{
System.out.println("1");
}
else
{
boolean a=false;
for(int i=0;i<t.length();i++)
{
if(t.charAt(i)=='a')
{
a=true;
break;
}
}
if(a)
{
System.out.println("-1");
}
else
{
System.out.println((long)Math.pow(2, r.length()));
}
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 1407281456bf632ea05ac1835a6404f4 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
public class Bishop {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
for(int i=0; i<q; i++){
String s = sc.next();
String t = sc.next();
int ssize = s.length();
int tsize = t.length();
if(ssize == 0){
System.out.println(0);
}
else{
if(tsize==0){
System.out.println(1);
}
else if(tsize>1){
int flag = 0;
for(int j=0; j<tsize; j++){
if(t.charAt(j) == 'a'){
flag = -1;
}
}
if(flag == -1){
System.out.println(-1);
}
else{
double x = Math.pow(2, ssize);
System.out.println((long)x);
}
}
else{
if(t.equals("a")){
System.out.println(1);
}
else{
double x = Math.pow(2, ssize);
System.out.println((long)x);
}
}
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | ebfc8be52645bc223ce9638f81033c61 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Solution {
class MathUtils {
static long fastpower(int n, int p) {
if (p == 0)
return 1;
if (p == 1)
return n;
long r = fastpower(n, p/2);
if (p % 2 == 0)
return r * r;
else
return r * n * r;
}
}
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private static PrintWriter pw = new PrintWriter(System.out);
static void getRes() throws Exception{
String a = br.readLine(), b = br.readLine();
if (b.length() == 1 && b.charAt(0) == 'a')
pw.println("1");
else if (b.replace("a", "").length() != b.length())
pw.println("-1");
else
pw.println(MathUtils.fastpower(2, a.length()));
}
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\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | fde60ee8e35eb462c1cfebcccc1c9639 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
char[] word = in.next().toCharArray();
char[] txt = in.next().toCharArray();
int count = 0;
for (char c : word) {
count += c == 'a' ? 1 : 0;
}
if (count == 0) {
out.println(0);
} else {
if (txt.length == 1 && txt[0] == 'a' && count == word.length) {
out.println(1);
return;
}
for (char c : txt) {
if (c == 'a') {
out.println(-1);
return;
}
}
out.println(1L << count);
}
}
}
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\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 7170c26a3f6871c622f77fc035d097e8 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
import static java.lang.Integer.*;
public class codeforces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
String s = sc.next();
String b = sc.next();
long bl =b.length();
long sl =s.length();
if(b.indexOf('a')==-1 )
{
System.out.println(1L<<sl);
continue;
}
if(bl==1)
{
System.out.println(1);
}
else
{
System.out.println(-1);
}
}
}
}
| Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | d885afd83d1b9bd0d2028e9b36411b2c | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class CF1674C {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8);
int q = scanner.nextInt();
for (int i = 0; i < q; i++) {
String s = scanner.next();
String t = scanner.next();
System.out.println(solve(s, t));
}
}
private static String solve(String s, String t) {
// t 等于 "a" 换了等于没换
if (t.equals("a")) {
return "1";
}
// 如果 t 含 'a' 且不为 "a",则无限大
if (t.contains("a")) {
return "-1";
}
int n = s.length();
return String.valueOf((long) Math.pow(2, n));
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 57f8a9cb04430b07d76be1336c9ed3a2 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class Testing {
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int q=s.nextInt();
for(int i=0;i<q;i++){
String S=s.next(),t=s.next();
if (t.contains('a'+"")&&t.length()==1)System.out.println(1);
else if (t.contains('a'+"")&&t.length()!=1){System.out.println(-1);}
else System.out.println((long)Math.pow(2,S.length()));
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 17 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | e8f9b2dac7b1de206f6d483750f81058 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
import java.io.*;
public class G {
static FastScanner fs = new FastScanner();
static PrintWriter pw = new PrintWriter(System.out);
static StringBuilder sb = new StringBuilder("");
static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
int z = fs.nextInt();
// int t = 1;
for (int tt = 0; tt < z; tt++) {
String s = fs.next();
String t = fs.next();
Set<Character> set = new HashSet<>();
for (int i = 0; i < t.length(); i++) set.add(t.charAt(i));
if (t.equals("a")) {
sb.append("1\n");
continue;
}
boolean ok = false;
for (char c : set) {
if (c == 'a') {
ok = true;
break;
}
}
if (ok) sb.append("-1\n");
else {
sb.append(((long) 1 << s.length()) + "\n");
}
}
pw.print(sb.toString());
pw.close();
}
static void sort(int[] a) {
ArrayList<Integer> al = new ArrayList<>();
for (int i : a)
al.add(i);
Collections.sort(al);
for (int i = 0; i < a.length; i++)
a[i] = al.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {while (!st.hasMoreTokens())try {st = new StringTokenizer(br.readLine());} catch (IOException e) {}return st.nextToken();}
int nextInt() {return Integer.parseInt(next());}
long nextLong() {return Long.parseLong(next());}
double nextDouble() {return Double.parseDouble(next());}
int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) {a[i] = nextInt();} return a;}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | d4d1ab6edce17f297050c4add75b1594 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
boolean flag;
while (T-- > 0) {
String s = sc.next();
String t = sc.next();
flag = false;
for (int i = 0; i < t.length(); i++) {
if (t.charAt(i) == 'a') {
flag = true;
}
}
if (flag) {
if (t.length() == 1) {
System.out.println(1);
} else {
System.out.println(-1);
}
} else {
System.out.println(1L << s.length());
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | ca483419688295381906e057c208830d | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
import java.io.*;
public class infiniteReplacement {
public static void main(String[] args) {
Scanner in = new Scanner(System.in );
int lines = Integer.parseInt(in.nextLine());
for(int i = 0; i < lines ; i++) {
long ans = 1;
String s = in.nextLine();
String l = in.nextLine();
if(l.contains("a") && l.length() > 1) {
ans = -1;
}else {
if(!l.contains("a")) {
// System.out.println((long) Math.pow(2, s.length()));
ans = (long) (Math.pow(2, s.length()));
}
}
System.out.println(ans);
}
}
public static int combinations(int num) {
if(num == 1) {
return 1;
}else {
return (combinations(num-1) + num);
}
}
}
| Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 5cd62f42d648b2a9ba2def1cbafbea26 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long count = Integer.parseInt(scanner.nextLine());
while(count-- > 0) {
String s = scanner.nextLine();
String t = scanner.nextLine();
if(t.equals("a")) {
System.out.println(1);
} else if(t.contains("a")) {
System.out.println("-1");
} else {
System.out.println((long)Math.pow(2, s.length()));
}
}
}
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 0522cc18350486d2c51c09979d7f711a | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | // package codeforce;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.io.*;
public class A {
static class Node {
int id1;
int id2;
Node(int v1, int w1){
this.id1= v1;
this.id2=w1;
}
Node(){}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
static boolean[] seiveofEratoSthenes(int n) {
boolean[] isPrime= new boolean[n+1];
Arrays.fill(isPrime, true);
isPrime[0]=false;
isPrime[1]= false;
for(int i=2;i*i<n;i++) {
for(int j=2*i; j<=n;j++) {
isPrime[j]= false;
}
}
return isPrime;
}
static int in = 2;
// Function check whether a number
// is prime or not
public static boolean isPrime(int n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static class SortingComparator implements Comparator<Node>{
@Override
public int compare(Node p1, Node p2) {
int n = p1.id1-p2.id1;
if(n!=0)return n;
return p2.id2-p1.id2;
}
}
static int pp =1;
static long[] dp = new long[500001];
public static void main(String[] args) {
FastReader sc=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int t = sc.nextInt();
// ArrayList<String> al = new ArrayList<>();
while(t--!=0) {
String s = sc.next();
String p = sc.next();
int cs =0;
int cp =0;
for(int i=0; i<s.length(); i++) {
if(s.charAt(i)=='a')cs++;
}
for(int i=0; i<p.length(); i++) {
if(p.charAt(i)=='a')cp++;
}
if(p.equals("a"))System.out.println(1);
else if(cp!=0)System.out.println(-1);
else System.out.println((long)Math.pow(2, s.length()));
}
out.close();
}
public static void rec(int l, int e, int[] arr) {
if(l>e || e>=arr.length || l<=0)return;
int mid = (e-l+1)%2==0?(e+l-1)/2:(e+l)/2;
if(arr[mid]==0 ) {
arr[mid]=pp;
pp++;
// if(pp>1)return;
}
if(e-mid-1<=mid-l-1) {rec(l, mid-1, arr);
rec(mid+1, e, arr);
}
else {
rec(mid+1, e, arr);
rec(l, mid-1, arr);
}
}
static double fact(double n)
{
int i=1;
double fact=1;
while(i<=n)
{
fact=fact*i;
i++;
}
return fact;
}
static double combination(int n,int r)
{
double com=fact(n)/(fact(n-r)*fact(r));
return com;
}
static boolean digit(long n) {
long ans = n;
while(n>0) {
long rem = n%10;
if(rem!=0 && ans%rem!=0)return false;
n=n/10;
}
return true;
}
static int nCr(int n, int r)
{
return fact(n) / (fact(r) *
fact(n - r));
}
// Returns factorial of n
static int fact(int n)
{
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l, Collections.reverseOrder());
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static boolean isPalindrome(char[] arr, int i, int j) {
while(i<j) {
if(arr[i]!=arr[j])return false;
i++;
j--;
}
return true;
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static int max =0;
static void dfs(int i, boolean[] vis , ArrayList<ArrayList<Integer>> adj) {
max = Math.max(max, i);
vis[i]= true;
for(int e: adj.get(i)) {
if(vis[e]==false) {
dfs(e, vis, adj);
}
}
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static double pow(int a, int b) {
long res= 1;
while(b>0) {
if((b&1)!=0) {
res= (res*a);
}
a= (a*a);
b= b>>1;
}
return res;
}
}
| Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 8f71ebe2582de8afa2e6797dc5f522d4 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.*;
@SuppressWarnings("ALL")
public class Main {
private static void solve(String s, String t) {
if (t.equals("a")) {
System.out.println(1);
} else {
if (t.contains("a")) {
System.out.println(-1);
} else {
System.out.println(1L << s.length());
}
}
}
public static void main(String[] args) throws Exception {
int tcnum = scanner.nextInt();
for (int tc = 0; tc < tcnum; tc++) {
String s = scanner.next();
String t = scanner.next();
solve(s, t);
}
}
private static int[] readIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
return arr;
}
private static String[] readStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.next();
}
return arr;
}
private static long[] readLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
return arr;
}
private static int[][] readIntGrid(int n, int m) {
int[][] grid = new int[n][m];
for (int i = 0; i < n; i++) {
grid[i] = readIntArray(m);
}
return grid;
}
private static char[][] readStringsIntoCharGrid(int n, int m) {
char[][] grid = new char[n][m];
for (int i = 0; i < n; i++) {
String s = scanner.next();
for (int j = 0; j < m; j++) {
grid[i][j] = s.charAt(j);
}
}
return grid;
}
private static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
private static final Scanner scanner = new Scanner(System.in);
private static final Map<?, ?> unused_map = new HashMap<>();
private static final List<?> unused_list = new ArrayList<>();
} | Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output | |
PASSED | 1265d097e9c1853fbe3a83c56571ebe6 | train_107.jsonl | 1651502100 | You are given a string $$$s$$$, consisting only of Latin letters 'a', and a string $$$t$$$, consisting of lowercase Latin letters.In one move, you can replace any letter 'a' in the string $$$s$$$ with a string $$$t$$$. Note that after the replacement string $$$s$$$ might contain letters other than 'a'.You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.Two strings are considered different if they have different length, or they differ at some index. | 256 megabytes | import java.util.Scanner;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String args[]) {
int tests = scanner.nextInt();
while (tests-- > 0) {
String original = scanner.next();
String replace = scanner.next();
String replaced = original.replaceAll("a", replace);
if (!original.contains("a")) {
System.out.println(1);
} else if (replaced.equals(original)) {
System.out.println(1);
} else if (replaced.contains("a")) {
System.out.println(-1);
} else {
int count = 0;
for (int i = 0; i < original.length(); i++) {
if (original.charAt(i) == 'a') {
count++;
}
}
System.out.println((long) Math.pow(2, count));
}
}
}
}
| Java | ["3\n\naaaa\n\na\n\naa\n\nabc\n\na\n\nb"] | 2 seconds | ["1\n-1\n2"] | NoteIn the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.In the second example, you can replace the second letter 'a' with "abc". String $$$s$$$ becomes equal to "aabc". Then the second letter 'a' again. String $$$s$$$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.In the third example, you can either leave string $$$s$$$ as is, performing zero moves, or replace the only 'a' with "b". String $$$s$$$ becomes equal to "b", so you can't perform more moves on it. | Java 11 | standard input | [
"combinatorics",
"implementation",
"strings"
] | d6ac9ca9cc5dfd9f43f5f65ce226349e | The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of testcases. The first line of each testcase contains a non-empty string $$$s$$$, consisting only of Latin letters 'a'. The length of $$$s$$$ doesn't exceed $$$50$$$. The second line contains a non-empty string $$$t$$$, consisting of lowercase Latin letters. The length of $$$t$$$ doesn't exceed $$$50$$$. | 1,000 | For each testcase, print the number of different strings $$$s$$$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.