Files
Story-With-Thanh/J08026 - BIẾN ĐỔI S – T.java
T
2022-12-15 23:51:04 +07:00

22 lines
537 B
Java

import java.util.*;
public class non {
static class pair{
int x, y;
public pair(int x, int y){
this.x = x;
this.y = y;
}
}
static int solve(int s, int t){
if(s>=t) return s - t;
if(t%2==1) return 1 + solve(s, t+1);
return 1 + solve(s, t>>1);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T-->0) System.out.println(solve(sc.nextInt(), sc.nextInt()));
}
}