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
5f821ac7e2e007eaae833d7062875795
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class code{ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static int GCD(int a, int b) { if (b == 0) return a; return GCD(b, a % b); } //@SuppressWarnings("unchecked") public static void main(String[] arg) throws IOException{ //Reader in=new Reader(); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(System.in); int t=in.nextInt(); while(t-- > 0){ long n=in.nextLong(); long k=in.nextLong(); long res=0; long count=1; while(count<k){ res++; count*=2; } if(count>=n){ out.println(res); } else{ long val=(n-count)/k; res+=val; if((n-count)%k!=0) res++; out.println(res); } } out.flush(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
c858b4718a1ee2069824dd2c89839c73
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class test { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { long n = in.nextLong() -1; long m = in.nextLong(); long c = 0; long k = 1; while(n>0){ if(k == m){ if(n%k==0){ c+=n/k; }else c+=(n/k)+1; break; } n = n-k; c++; if(k*2<=m){ k*=2; }else{ k = m; } } System.out.println(c); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
1b4bd9fab30c2af3a29c7e1cfc92698d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class codeforcesB{ public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[]){ FastReader sc=new FastReader(); StringBuilder sb=new StringBuilder(); int t=sc.nextInt(); while(t-->0){ long n=sc.nextLong(); long k=sc.nextLong(); long done=1; long time=0; while(done<k){ if(done>=n){break;} done+=done; time++;} if(n>done){ time+=((n-done)/k); if((n-done)%k!=0){time++;} } System.out.println(time); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d11af70565cb66ed4ee01a7d004e4c96
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class B { public static void main(String[] args) throws IOException { Reader sc = new Reader(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long time = 0; // long times = (long)Math.ceil(Math.log(k * 1.0) / Math.log(2.0)); // long comp = (long)Math.pow(2,(times * 1.0)); // out.println(times + " " + comp); // time += times; // long total_comp = comp; long comp = 1; while(comp < k) { comp *= 2; time++; } long x = n - comp; long y = k; time += ((x + y - 1) / y); out.println(time); } out.flush(); } public static boolean checkPalindrome(int[] arr,int x) { int n = arr.length; int start = 0; int end = n - 1; while(start < end) { if(arr[start] == x) start++; else if(arr[end] == x) end--; else if(arr[start] != arr[end]) return false; else { start++; end--; } } return true; } public static String bin(long n,long i) { StringBuilder list = new StringBuilder(); list.append(0); while(n > 0) { list.append(n % i); n = n / i; } return new String(list); } static int[] sort(int[] arr,int n) { List<Integer> list = new ArrayList<>(); for(int i = 0;i < n;i++) list.add(arr[i]); Collections.sort(list); for(int i = 0;i < n;i++) arr[i] = list.get(i); return arr; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static int isPrime(int n) { if(n < 2) return 0; if(n < 4) return 1; if((n % 2) == 0 || (n % 3) == 0) return 0; for(int i = 5; (i * i) <= n; i += 6) if((n % i) == 0 || (n % (i + 2)) == 0) return 0; return 1; } static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()) str = st.nextToken("\n"); else str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } //class Pair { // int a; // char b; // public Pair(int a,char b) { // this.a = a; // this.b = b; // } //} // ********************* Custom Pair Class ********************* //class Pair implements Comparable<Pair> { // int a,b; // public Pair(int a,int b) { // this.a = a; // this.b = b; // } // @Override // public int compareTo(Pair other) { // if(this.b == other.b) // return Integer.compare(other.a,this.a); // return Integer.compare(this.b,other.b); // } //} // ****************** Segment Tree ****************** //public class SegmentTreeNode { // public SegmentTreeNode left; // public SegmentTreeNode right; // public int Start; // public int End; // public int Sum; // public SegmentTreeNode(int start, int end) { // Start = start; // End = end; // Sum = 0; // } //} //public SegmentTreeNode buildTree(int start, int end) { // if(start > end) // return null; // SegmentTreeNode node = new SegmentTreeNode(start, end); // if(start == end) // return node; // int mid = start + (end - start) / 2; // node.left = buildTree(start, mid); // node.right = buildTree(mid + 1, end); // return node; //} //public void update(SegmentTreeNode node, int index) { // if(node == null) // return; // if(node.Start == index && node.End == index) { // node.Sum += 1; // return; // } // int mid = node.Start + (node.End - node.Start) / 2; // if(index <= mid) // update(node.left, index); // else // update(node.right, index); // node.Sum = node.left.Sum + node.right.Sum; //} //public int SumRange(SegmentTreeNode root, int start, int end) { // if(root == null || start > end) // return 0; // if(root.Start == start && root.End == end) // return root.Sum; // int mid = root.Start + (root.End - root.Start) / 2; // if(end <= mid) // return SumRange(root.left, start, end); // else if(start > mid) // return SumRange(root.right, start, end); // return SumRange(root.left, start, mid) + SumRange(root.right, mid + 1, end); //}
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
a956183341327c1f9891e3d78c777aff
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class CodeForces { class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader( new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out); } catch (Exception e) { 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; } } void shuffle(long a[], int n) { for (int i = 0; i < n; i++) { int t = (int) Math.random() * a.length; long x = a[t]; a[t] = a[i]; a[i] = x; } } long lcm(int a, int b) { long val = a * b; return val / gcd(a, b); } void swap(long a[], long b[], int i) { long temp = a[i]; a[i] = b[i]; b[i] = temp; } long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } long mod = (long) 1e9 + 7, c; FastReader in; PrintWriter o; public static void main(String[] args)throws IOException { new CodeForces().run(); } void run() throws IOException{ in = new FastReader(); OutputStream op = System.out; o = new PrintWriter(op); int t; // t = 1; t = in.nextInt(); for (int i = 1; i <= t; i++) { helper(); o.println(); } o.flush(); o.close(); } public void helper() { long n=in.nextLong(),k=in.nextLong(); if(n==1){ o.print(0);return; } long v=1,mul=1,ans=0; while(v<n) { ans++; v+=Math.min(k,mul); if(mul>k && v<n) { ans=ans+((n-v)/k)+(((n-v)%k)==0?0:1); break; } mul*=2; } o.print(ans); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
64755f892efc234f5068487b5ddb30f2
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class CFsolve { public static void main(String[] args) { FastScanner input = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = input.nextInt(); while(t-- > 0) { long n = input.nextLong()-1; long k = input.nextLong(); long i = 1; long count = 0; while(n>0){ n-=i; i+=i; count++; if(i>k) break; //i=k; } if(n<k && n>0){ count+=1; } else if(n>=k) { count += n/k; if(n%k != 0) count += 1; } out.println(count); } out.close(); } static int LCM(int a, int b){ return a/gcd(a,b) * b; } static long LCM(long a, long b){ return (a/gcd(a,b) * b); } static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1)!=0) res = res * a; a = a * a; b >>= 1; } return res; } static int pow(int a, int b) { int res = 1; while (b > 0) { if ((b & 1)!=0) res = res * a; a = a * a; b >>= 1; } return res; } static int gcd(int a,int b){ while(b>0){ a%=b; a=a^b; b=a^b; a=a^b; } return a; } static long gcd(long a,long b){ while(b>0){ a%=b; a=a^b; b=a^b; a=a^b; } return a; } static void swap(int a, int b){ a = a^b; b = a^b; a = a^b; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } byte nextByte(){return Byte.parseByte(next());} long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
6d186309d793ca74970717b7dfee225d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.math.*; import java.net.Inet4Address; import java.util.*; public class sampleEditor_codeforces { static int mod=1000000007; static int mod2=1000003; static Scanner sc = new Scanner(System.in); static class Pair implements Comparable<Pair>{ int x; int y; public Pair(int px , int py){ x = px; y = py; } @Override public int compareTo(Pair pair){ if (x > pair.x) return 1; else if (x == pair.x) return 0; else return -1; } } public static void loop(int [] a,int l,int r){ for(int i=l;i<r;i++){ a[i]=sc.nextInt(); } } public static long binaryToDecimal(String binary){ int n=binary.length(); int i=n-1; long sum=0; long two=1; while(i>=0){ sum+=two*(binary.charAt(i)-'0')%mod2; two*=2; i--; } return sum; } public static boolean isSorted(int[] arr) { int n = arr.length; for (int i = 0; i < n - 1; i++) { if (arr[i] > arr[i + 1]) { return false; } } return true; } public static void reverse(int[] arr) { int l = 0; int r = arr.length - 1; while (l < r) { int temp = arr[l]; arr[l] = arr[r]; arr[r] = temp; l++; r--; } } public static void reverse(int[] arr,int l,int r) { while (l < r) { int temp = arr[l]; arr[l] = arr[r]; arr[r] = temp; l++; r--; } } public static boolean isPalindrome(int n,int [] a,int x1){ int [] b=new int[n]; int m=0; for(int i=0;i<n;i++){ if(a[i]!=x1){ b[m++]=a[i]; } } for(int i=0;i<m;i++){ if(b[i]!=b[m-1-i]){ return false; } } return true; } public static void solve(long n, long k) { long sum=1; long cnt=0; long k1=1; while(sum<k){ sum*=2; cnt++; } cnt+=(n-sum+k-1)/k; System.out.println(cnt); } public static void main(String args[]) { // Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { long n=sc.nextLong(); long k=sc.nextLong(); solve(n,k); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
e3d03884f739cb40aa50462349d2cdf9
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.util.stream.Collectors; import java.io.*; import java.math.*; public class ER116_B { public static FastScanner sc; public static int MOD= 1000000007; public static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static int gcd(int a, int b) { if(b==0) return a; return gcd(b,a%b); } public static int lcm(int a, int b) { return((a*b)/gcd(a,b)); } public static void decreasingOrder(ArrayList<Integer> al) { Comparator<Integer> c = Collections.reverseOrder(); Collections.sort(al,c); } public static boolean[] sieveOfEratosthenes(int n) { boolean isPrime[] = new boolean[n+1]; Arrays.fill(isPrime, true); isPrime[0]=false; isPrime[1]=false; for(int i=2;i*i<n;i++) { for(int j=2*i;j<n;j+=i) { isPrime[j]=false; } } return isPrime; } public static boolean isPalindrome(int n){ int num=0; int temp=n; while(n>0) { num=(num*10)+(n%10); n=n/10; } if(temp==num) return true; else return false; } public static int nCr(int N, int R) { double result=1; for(int i=1;i<=R;i++){ result=((result*(N-R+i))/i); } return (int) result; } public static void printList(List<Integer> al) { System.out.println(al.stream().map(it -> it.toString()).collect(Collectors.joining(" "))); } public static void printList(Deque<Integer> al) { System.out.println(al.stream().map(it -> it.toString()).collect(Collectors.joining(" "))); } public static void printArr(int[] arr) { System.out.println(Arrays.toString(arr).trim().replace("[", "").replace("]","").replace(","," ")); } public static long fastPower_v2(long a, long b, int n) { long result=1; while(b>0) { if((b&1)==1) result=(result*a %n)%n; a=(a%n * a%n)%n; b>>=1; } return result; } public static void solve(int t) { long n=sc.nextLong(); long k=sc.nextLong(); if(n==1) { System.out.println(0); } else { n--; long temp=0; long ans=0; while((long)Math.pow(2,temp)<k) { // System.out.println("YES"); // System.out.println(Math.pow(2, temp)); n=n-(long)Math.pow(2, temp); temp++; ans++; if(n<=0) break; // System.out.println(n+ " TEMP"); } // System.out.println(n+ " TEMP"); if(n>0) { if(n%k==0) ans+= n/k; else ans+= (n/k)+1; } System.out.println(ans); } // n--; // long temp=0; // temp=((k-1)*(k))/2; // long ans=0; // if(temp<=n) { // n-=temp; // ans+=k-1; // if(n%k==0) ans+=n/k; // else if(n%k!=0 && n!=0) ans+=(n/k)+1; // System.out.println(ans); // } // // else { //// System.out.println("YES2"); // long left=1; // long right=k-1; // long ans2=(left+right)/2; // while(left<=right) { // long mid=(left+right)/2; // long sum=(mid*(mid+1))/2; // // if(sum>=n) { // ans2=mid; // right=mid-1; // } // else { // left=mid+1; // } // } // System.out.println(ans2); // } } public static void main(String[] args) { sc = new FastScanner(); int t=sc.nextInt(); for(int i=1;i<=t;i++){ solve(i); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
470ba7e81d601f6655b011f5da1f44e2
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; import java.util.Arrays; import java.lang.Math; public class UpdateFiles { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); String str = sc.nextLine(); while(t-->0) { long n = sc.nextLong(), k = sc.nextLong(); if(n==1){System.out.println(0);continue;} if(n==2){System.out.println(1);continue;} long r = 0l, i = 0l; while((long)Math.pow(2,i)<=k) {i++;} r = n - (long)Math.pow(2,i); long b = (long)Math.pow(2,i-1); if(b == k && b%10==k%10 && n<=Math.pow(2,i) && k==n) System.out.println(i-1); else if(n<=(long)Math.pow(2,i)) System.out.println(i); else if(n>(long)Math.pow(2,i) && r%k == 0) System.out.println(i + (long)r/k); else System.out.println(i + (long)r/k + 1); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
f028066e576d69737e8f6a4fe01f959a
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class Main { static long expow(int x,int y) { long temp=1; while(y>0) { if(y%2==1) { temp*=x; } x*=x; y>>=1; } return temp; } static long ceil(double x) { long y=(long)x; if(x-y>0) { y++; } return y; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t; t=sc.nextInt(); while(t>0) { long n; long k; long now=1; long time=0; n=sc.nextLong(); k=sc.nextLong(); while(now<=k) { now*=2; time++; } // System.out.println(ceil((n-now)*1.0/k)+"///"); time+=(n-now)/k; if((n-now)%k>0) { time++; } System.out.println(time); t--; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
05c610a706732f069b91246a18e741e9
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
//package contests.div2.edu116; import java.io.*; import java.util.StringTokenizer; public class B { static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); static int fasterScanner() { try { boolean in = false; int res = 0; for (; ; ) { int b = System.in.read() - '0'; if (b >= 0) { in = true; res = 10 * res + b; } else if (in) { return res; } } } catch (IOException e) { throw new Error(e); } } public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = fasterScanner(); while (t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); if (k == 1) { out.println(n - 1); } else { long computers = 1; long remaining = n - 1; long ans = 0; while (computers < n && k >= computers) { remaining -= computers; computers += computers; ans++; } if (remaining > 0) { ans += (remaining + k - 1) / k; } out.println(ans); } } out.close(); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
713885229bacb817a3399c7b21b9eed8
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Coder { static StringBuffer str=new StringBuffer(); static long n,k; static void solve(){ long num=1; long cnt=0; while(num<=k && num < n){ num *= 2; cnt++; } if(num<n) cnt += (n-num+k-1)/k; str.append(cnt).append("\n"); } public static void main(String[] args) throws java.lang.Exception { BufferedReader bf; PrintWriter pw; boolean lenv=false; if(lenv){ bf = new BufferedReader( new FileReader("input.txt")); pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); }else{ bf = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); } int q = Integer.parseInt(bf.readLine().trim()); while (q-- > 0) { String s[]=bf.readLine().trim().split("\\s+"); n=Long.parseLong(s[0]); k=Long.parseLong(s[1]); solve(); } pw.print(str); pw.flush(); // System.out.print(str); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
6f37ab5fe16e40b2653b3bd430b1024a
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Div2_Round_116_No9 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { long n = sc.nextLong(); long k = sc.nextLong(); if(n==1) System.out.println(0); else if(k==1) System.out.println((long)n-1); else if(n==2) System.out.println(1); else if(n==3 || n==4) System.out.println(2); else if(k==n) { long ans=2; for(long p=4; p<n; p*=2) { ans++; if(p>n) break; } System.out.println(ans); } else { long ans=1; long mul=1; n-=2; long rem = 0; while(n>0) { mul *= 2; if(mul <= k) { ans++; n -= mul; } else { rem = n/k; ans += rem; n -= rem*k; if(n%k != 0) { ans++; n=0; } } } System.out.println(ans); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
eaa3d602643adb3a1275418c19d9c18c
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { //your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t>0){ t--; long n=sc.nextLong(); long k=sc.nextLong(); long ans=0; n--; long x=1; while(x<k&&n>0){ n=n-x; x=x*2; ans++; } if(n>0){ if(n%k==0){ ans=ans+n/k; } else{ ans=ans+n/k+1; } } System.out.println(ans); } }}
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
7010b4c79329b9d072d16161a05a655b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Codechef { public static void main(String[] args) throws java.lang.Exception { FastReader in = new FastReader(System.in); StringBuilder sb = new StringBuilder(); int t = 1; t = in.nextInt(); while (t > 0) { --t; long n = in.nextLong(); long k = in.nextLong(); long sum = 1; n = n-1; long count = 0; long temp = 1; while(sum<=k && n>0) { n-=sum; ++count; sum+=sum; } if(n>0) { if(n<=k) ++count; else { count+=((n/k)); if(n%k!=0) ++count; } } sb.append(count+"\n"); } System.out.print(sb); } static long gcd(long a, long b) { if (a == 0) return b; else return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } } class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
28b1fb8faa60d1c3d600c2fa16b356b0
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class ferrisWheel { static PrintWriter pw = new PrintWriter(System.out); static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws IOException, InterruptedException { int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(),k=sc.nextLong(); n--; if(n==0)pw.println(0); else { long ans=1; long c=1; n--; while(c<<1<=k && n>0) { c<<=1; n-=c; ans++; //pw.println(n+" "+c+" "+ans); } if(n<=0) { pw.println(ans); } else { pw.println(ans+(n%k==0?n/k:(n/k+1))); } } } // 1000000000000000000 pw.flush(); } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static class PairPoint { pair p1; pair p2; public PairPoint(pair p1, pair p2) { this.p1 = p1; this.p2 = p2; } public String toString() { return p1.toString() + p2.toString(); } public boolean equals(PairPoint pp) { if (p1.equals(pp.p1) && p2.equals(pp.p2)) return true; return false; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
24fe589a1c949c828f2a230eb9d0d66d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class Linked_List_implement { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t-- != 0 ) { long n = scan.nextLong(); long k = scan.nextLong(); long kk = 1 , cnt = 0; while( n >= kk * 2 && kk < k ) { kk*=2; cnt++; } long lft = n - kk; cnt+= lft / k ; if(lft % k != 0 ) { cnt++; } System.out.println(cnt); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
117c5cdbfe8855b10edc2e045452b02a
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { long cnt = 0; long n = sc.nextLong(), k = sc.nextLong(); if(n==1 && k==1) { System.out.println(0); } else if(k==1) { System.out.println(n-1); } else { long kabel = 1; n--; while(n>0) { n-=kabel; kabel*=2; cnt++; if(kabel>k) { cnt+=(n+k-1)/k; break; } } System.out.println(cnt); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
6a18f00553202ebdf35772771b7be99b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.sql.Time; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; public class Practice1 { public static void main(String[] args) { PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); // out.print(); //out.println(); FastReader sc=new FastReader(); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long ans=0,curr=1; while(curr<k) { curr *=2; ans++; } if(curr<n) { ans +=(n-curr+k-1)/k; } System.out.println(ans); } //out.close(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
79e9481cfc75d68ddca97bd2563037b5
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int tc = sc.nextInt(); while(tc-->0){ long n = sc.nextLong() - 1, k = sc.nextLong(); long able = 1; long hours = 0; while(n > 0){ n -= able; hours++; long temp = able; if(temp<<1 > k)break; else able = able<<1; } //hours += Math.ceil((double)(n) / (double) (able)); if(n > 0) { if(n % k == 0)hours += n/k; else hours += n/k + 1; } pw.println(hours); } pw.flush(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
6ac2df899e17a9a5839b9a6ee0b5a139
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class b { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ long n = sc.nextLong(); long k = sc.nextLong(); long ans = 1; long steps = 0; long used = 1; while(ans < n){ if(used < k){ ans *= 2; steps++; used *= 2; } else{ break; } } if(ans < n){ long rem = n - ans; if(rem%k == 0){ steps += rem/k; } else{ steps += rem/k + 1; } } System.out.println(steps); } } } class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
7d8946f0524f828946a78013994a1062
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; /** * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools * <p> * To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { Long n = sc.nextLong(); Long k = sc.nextLong(); Long tot = Find(n , k ); System.out.println(tot); } } public static Long Find(Long n , Long k){ // System.out.println("Enter"); if(k==1){ return n-1; } if(n==2){ return 1L; } if(n<=4){ return 2L; } Long ans = 2L; Long no = 4L; Long mul = 4L; while(no<n){ if(k<mul){ long rem = n - no; ans=ans+(rem+k-1)/k; break; }else{ no+=mul; mul=mul*2; ans++; } // System.out.print("The value of no is "+no); } // System.out.println(); return ans; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
999039ff364c729db25eef85fa248e43
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Main { static int arr[]; static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); static FastReader input = new FastReader(); //static Scanner input = new Scanner(System.in); public static void main(String[] args) { //System.out.println(Math.ceil(2)); int t= input.nextInt(); while(t-->0) solve(); } static void solve( ){ long n=input.nextLong(); long k=input.nextLong(),current=1; if(n==k&&k==1){ System.out.println(0);return; } long count=0; while (current<=k&&current<n){ current=current*2; count++; } if(current<n){ long d=n-current; if(d%k==0){ count+=(d/k); }else{ count+=(d/k)+1; } } System.out.println(count); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } long nextLong(){ return Long.parseLong(next());} } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
fa6bd2ec46dfdc63dc65f5af83f1c3b4
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class B1 { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); m: while(t-->0) { long n=in.nextLong(),k=in.nextLong(),time=0; if(n==1) { out.println(0); continue m; } for(int i=1;i<=64;i++) { long val=1L<<i; long rec_val=1l<<(i-1); if(val<=n) { if(rec_val<=k) time++; else { long rest=n-rec_val; if(rest<=k) time++; else { if(rest%k==0) time+=(rest/k); else time+=(rest/k)+1; } break; } if(val==n) break; } else { long rest=n-rec_val; if(rest<=k) time++; else { if(rest%k==0) time+=(rest/k); else time+=(rest/k)+1; } break; } } out.println(time); } out.close(); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static boolean checkprime(int n1) { if(n1%2==0||n1%3==0) return false; else { for(int i=5;i*i<=n1;i+=6) { if(n1%i==0||n1%(i+2)==0) return false; } return true; } } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
29e8bf2aef894f9d353af7e6ba3bb520
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class B1 { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); m: while(t-->0) { long n=in.nextLong(),k=in.nextLong(),time=0; if(n==1) { out.println(0); continue m; } for(int i=1;i<=64;i++) { long val=1L<<i; long rec_val=(long)Math.pow(2,i-1); if(val<=n) { if(rec_val<=k) time++; else { long rest=n-rec_val; if(rest<=k) time++; else { if(rest%k==0) time+=(rest/k); else time+=(rest/k)+1; } break; } if(val==n) break; } else { long rest=n-rec_val; if(rest<=k) time++; else { if(rest%k==0) time+=(rest/k); else time+=(rest/k)+1; } break; } } out.println(time); } out.close(); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static boolean checkprime(int n1) { if(n1%2==0||n1%3==0) return false; else { for(int i=5;i*i<=n1;i+=6) { if(n1%i==0||n1%(i+2)==0) return false; } return true; } } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
c7d3fd26a4fa95a7093c3f0d102b8beb
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class B1 { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); m: while(t-->0) { long n=in.nextLong(),k=in.nextLong(),time=0; if(n==1) { out.println(0); continue m; } for(int i=1;i<=64;i++) { long val=(long)Math.pow(2,i); long rec_val=(long)Math.pow(2,i-1); if(val<=n) { if(rec_val<=k) time++; else { long rest=n-rec_val; if(rest<=k) time++; else { if(rest%k==0) time+=(rest/k); else time+=(rest/k)+1; } break; } if(val==n) break; } else { long rest=n-rec_val; if(rest<=k) time++; else { if(rest%k==0) time+=(rest/k); else time+=(rest/k)+1; } break; } } out.println(time); } out.close(); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static boolean checkprime(int n1) { if(n1%2==0||n1%3==0) return false; else { for(int i=5;i*i<=n1;i+=6) { if(n1%i==0||n1%(i+2)==0) return false; } return true; } } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
9e24e42afadf17d9b139ade598b48789
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.*; import java.util.*; public class Main { static int i, j, k, n, m, t, y, x, sum = 0; static long mod = 998244353; static FastScanner fs = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static String str; static long ans; public static void main(String[] args) { t =fs.nextInt(); while(t-- >0) { long n = fs.nextLong(); long k = fs.nextLong(); n--; long x =0; int f =0; ans = 0; for(long i=1;i<=k;i*=2){ ans++; x+=i; if(x>=n){ f=1; break; } } if(n==0) out.println(0); else if(f==1) out.println(ans); else{ long a = n-x; ans+=(a/k); if(a%k!=0) ans++; out.println(ans); } } out.close(); } public static long find(long l,long r, long f){ long m = (l+r)/2; long a = m*(m+1); long b = m*(m-1); if(a>=f && b <f) return m; else if(m*(m+1)<f) return find(m,r,f); else return find(l,m,f); } /*static long nck(int n , int k){ long a = fact[n]; long b = modInv(fact[k]); b*= modInv(fact[n-k]); b%=mod; return (a*b)%mod; } static void populateFact(){ fact[0]=1; fact[1] = 1; for(i=2;i<300005;i++){ fact[i]=i*fact[i-1]; fact[i]%=mod; } } */ static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long exp(long base, long pow) { if (pow==0) return 1; long half=exp(base, pow/2); if (pow%2==0) return mul(half, half); return mul(half, mul(half, base)); } static long mul(long a, long b) { return ((a%mod)*(b%mod))%mod; } static long add(long a, long b) { return ((a%mod)+(b%mod))%mod; } static long modInv(long x) { return exp(x, mod-2); } static void ruffleSort(int[] a) { //ruffle int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n), temp = a[i]; a[i] = a[oi]; a[oi] = temp; } //then sort Arrays.sort(a); } static void ruffleSort(long[] a) { //ruffle int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); long temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } static class Pair implements Comparable<Pair>{ public int x, y; Pair(int x, int y){ this.x = x; this.y = y; } @Override public int compareTo(Pair o) { if(x==o.x) return Integer.compare(y,o.y); return Integer.compare(x,o.x); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
00a411bcc35f227ab745f8afa84fcdca
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.PriorityQueue; import java.util.Scanner; import java.util.TreeSet; public class Main { StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int t,r,b,i; long n,k,tmp,ans; long p[]=new long[64]; long p2[]=new long[64]; void run() throws IOException{ Scanner in=new Scanner(System.in); for(i=0;i<63;i++) { p[i]=1<<i; } for(i=1;i<63;i++) { p2[i]=p[i-1]; } t=in.nextInt(); while(t-->0) { n=in.nextLong(); k=in.nextLong(); tmp=1; ans=0; while(tmp<n) { if(tmp<=k) { tmp<<=1; ans++; }else { n-=tmp; ans+=n/k+(n%k==0?0:1); break; } } out.println(ans); } out.flush(); } public static void main(String[]args) throws IOException { new Main().run(); } public int in() throws IOException { in.nextToken(); return(int)in.nval; } public long inl() throws IOException { in.nextToken(); return(long)in.nval; } public double ind() throws IOException { in.nextToken(); return in.nval; } public String ins() throws IOException { in.nextToken(); return in.sval; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d0634b5dd3764f2ec0403c7cfea5bbc2
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.math.BigInteger; public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { BigInteger n = sc.nextBigInteger(); BigInteger k = sc.nextBigInteger(); BigInteger countHrs = new BigInteger("0"); BigInteger hrs = new BigInteger("1"); BigInteger zero = new BigInteger("0"); while(hrs.compareTo(n)==-1) { if(hrs.compareTo(k)==-1) { hrs = hrs.add(hrs); countHrs = countHrs.add(BigInteger.ONE); } else { n = n.subtract(hrs); if((n.mod(k)).compareTo(zero)==0) { countHrs = countHrs.add(n.divide(k)); } else { countHrs = countHrs.add(n.divide(k)); countHrs = countHrs.add(BigInteger.ONE); } break; } } System.out.println(countHrs); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
c8097095a1866e622d0508099a8e1d3f
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class MyClass { public static void main(String[] args) { Scanner sc= new Scanner (System.in); long t=sc.nextInt(); while (t-->0){ long c=sc.nextLong(); long k=sc.nextLong(); long count=0; long x=1; while (x<k){ x+=x; count++; } if(x<c){ long req=c-x; count+=( req ) / k; if (req%k!=0) count++; } System.out.println(count); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
8924f841edf541f79e569d7fd5f675bb
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class PracticeProblems { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); PrintWriter out = new PrintWriter(System.out); int x = Integer.parseInt(st.nextToken()); for(int i = 0; i < x; i++) { st = new StringTokenizer(br.readLine()); long y = Long.parseLong(st.nextToken()); long z = Long.parseLong(st.nextToken()); long counter = 0; long num = 1; while(num < z) { num*=2; counter++; } counter+=(y - num + z - 1) / z; out.println(counter); } out.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
407e282628f9c8433a2b7a0e9f2f7a0a
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class UpdateFiles { public static PrintWriter out; public static void main(String[] args)throws IOException{ Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long a=0; long c=1; while(c<k) { c*=2; a++; } //a+=(n-c+k-1)/k; if((n-c)%k==0) { a+=(n-c)/k; }else { a+=((n-c)+k)/k; } out.println(a); } out.close(); } public static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { 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
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
168aceedfbd44e9b8b80fcc71b255a1d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class UpdateFiles { public static PrintWriter out; public static void main(String[] args)throws IOException{ Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long a=0; long c=1; while(c<k) { c*=2; a++; } a+=(n-c+k-1)/k; out.println(a); } out.close(); } public static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() { 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
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
fbc61521343f57ad0bb387d6f76b78c2
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static class Pair implements Comparable < Pair > { int d; int i; Pair(int d, int i) { this.d = d; this.i = i; } public int compareTo(Pair o) { return this.d - o.d; } } public static class SegmentTree { long[] st; long[] lazy; int n; SegmentTree(long[] arr, int n) { this.n = n; st = new long[4 * n]; lazy = new long[4 * n]; construct(arr, 0, n - 1, 0); } public long construct(long[] arr, int si, int ei, int node) { if (si == ei) { st[node] = arr[si]; return arr[si]; } int mid = (si + ei) / 2; long left = construct(arr, si, mid, 2 * node + 1); long right = construct(arr, mid + 1, ei, 2 * node + 2); st[node] = left + right; return st[node]; } public long get(int l, int r) { return get(0, n - 1, l, r, 0); } public long get(int si, int ei, int l, int r, int node) { if (r < si || l > ei) return 0; if (lazy[node] != 0) { st[node] += lazy[node] * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } if (l <= si && r >= ei) return st[node]; int mid = (si + ei) / 2; return get(si, mid, l, r, 2 * node + 1) + get(mid + 1, ei, l, r, 2 * node + 2); } public void update(int index, int value) { update(0, n - 1, index, 0, value); } public void update(int si, int ei, int index, int node, int val) { if (si == ei) { st[node] = val; return; } int mid = (si + ei) / 2; if (index <= mid) { update(si, mid, index, 2 * node + 1, val); } else { update(mid + 1, ei, index, 2 * node + 2, val); } st[node] = st[2 * node + 1] + st[2 * node + 2]; } public void rangeUpdate(int l, int r, int val) { rangeUpdate(0, n - 1, l, r, 0, val); } public void rangeUpdate(int si, int ei, int l, int r, int node, int val) { if (r < si || l > ei) return; if (lazy[node] != 0) { st[node] += lazy[node] * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } if (l <= si && r >= ei) { st[node] += val * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += val; lazy[2 * node + 2] += val; } return; } int mid = (si + ei) / 2; rangeUpdate(si, mid, l, r, 2 * node + 1, val); rangeUpdate(mid + 1, ei, l, r, 2 * node + 2, val); st[node] = st[2 * node + 1] + st[2 * node + 2]; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main(String[] args) throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { try { System.setIn(new FileInputStream(new File("input.txt"))); System.setOut(new PrintStream(new File("output.txt"))); } catch (Exception e) { } } Reader sc = new Reader(); int tc = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (tc-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long hr = 0; long com = 1; long tn = 1; while (tn < n) { com = 2 * com; hr += 1; tn = com; if (com >= k) break; } if (n > tn) hr += (n - tn + k - 1) / k; sb.append(hr); sb.append("\n"); } System.out.println(sb); } public static boolean isEqual(HashMap<Integer, Integer> a, HashMap<Integer, Integer> b) { if (a.size() != b.size()) return false; for (int key : a.keySet()) if (a.getOrDefault(key, 0) != b.getOrDefault(key, 0)) return false; return true; } public static double digit(long num) { return Math.floor(Math.log10(num) + 1); } public static int count(ArrayList<Integer> al, int num) { if (al.get(al.size() - 1) == num) return 0; int k = al.get(al.size() - 1); ArrayList<Integer> temp = new ArrayList<>(); for (int i = 0; i < al.size(); i++) { if (al.get(i) > k) temp.add(al.get(i)); } return 1 + count(temp, num); } public static String Util(String s) { for (int i = s.length() - 1; i >= 1; i--) { int l = s.charAt(i - 1) - '0'; int r = s.charAt(i) - '0'; if (l + r >= 10) { return s.substring(0, i - 1) + (l + r) + s.substring(i + 1); } } int l = s.charAt(0) - '0'; int r = s.charAt(1) - '0'; return (l + r) + s.substring(2); } public static boolean isPos(int idx, long[] arr, long[] diff) { if (idx == 0) { for (int i = 0; i <= Math.min(arr[0], arr[1]); i++) { diff[idx] = i; arr[0] -= i; arr[1] -= i; if (isPos(idx + 1, arr, diff)) { return true; } arr[0] += i; arr[1] += i; } } else if (idx == 1) { if (arr[2] - arr[1] >= 0) { long k = arr[1]; diff[idx] = k; arr[1] = 0; arr[2] -= k; if (isPos(idx + 1, arr, diff)) { return true; } arr[1] = k; arr[2] += k; } else return false; } else { if (arr[2] == arr[0] && arr[1] == 0) { diff[2] = arr[2]; return true; } else { return false; } } return false; } public static boolean isPal(String s) { for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) return false; } return true; } static int upperBound(ArrayList<Long> arr, long key) { int mid, N = arr.size(); // Initialise starting index and // ending index int low = 0; int high = N; // Till low is less than high while (low < high && low != N) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is greater than or equal // to arr[mid], then find in // right subarray if (key >= arr.get(mid)) { low = mid + 1; } // If key is less than arr[mid] // then find in left subarray else { high = mid; } } // If key is greater than last element which is // array[n-1] then upper bound // does not exists in the array return low; } static int lowerBound(ArrayList<Long> array, long key) { // Initialize starting index and // ending index int low = 0, high = array.size(); int mid; // Till high does not crosses low while (low < high) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is less than or equal // to array[mid], then find in // left subarray if (key <= array.get(mid)) { high = mid; } // If key is greater than array[mid], // then find in right subarray else { low = mid + 1; } } // If key is greater than last element which is // array[n-1] then lower bound // does not exists in the array if (low < array.size() && array.get(low) < key) { low++; } // Returning the lower_bound index return low; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
f130e3011cfd1d42e1b9589707f88afc
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class UpdateFiles { public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t-->0){ long n = sc.nextLong() , k = sc.nextLong() , ans = 0 , c = 1; while(c<k){ ans++; c *= 2; } if(c<n) ans += (n - c + k - 1) / k; pw.println(ans); } pw.flush(); } static class UnionFind { int[] p, rank, setSize; int numSets; public UnionFind(int N) { p = new int[numSets = N]; rank = new int[N]; setSize = new int[N]; for (int i = 0; i < N; i++) { p[i] = i; setSize[i] = 1; } } public int findSet(int i) { return p[i] == i ? i : (p[i] = findSet(p[i])); } public boolean isSameSet(int i, int j) { return findSet(i) == findSet(j); } public void unionSet(int i, int j) { if (isSameSet(i, j)) return; numSets--; int x = findSet(i), y = findSet(j); if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; } else { p[x] = y; setSize[y] += setSize[x]; if (rank[x] == rank[y]) rank[y]++; } } public int numDisjointSets() { return numSets; } public int sizeOfSet(int i) { return setSize[findSet(i)]; } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(FileReader r) { br = new BufferedReader(r); } public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int[] nextIntArr(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
41b370f8442851c8022799feb5774b81
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Dec10B { static boolean[] isPrime; public static void main(String[] args) { FastScanner sc=new FastScanner(); PrintWriter pw=new PrintWriter(System.out); int ts=sc.nextInt(); while(ts-- > 0){ long n=sc.nextLong(); long k=sc.nextLong(); long temp=1,c=0; while(temp<k){ temp=temp<<1; c++; } n=n-temp; System.out.println(c+(n/k)+( (n)%k+k-1)/k); } pw.flush(); } public static long npr(int n, int r) { long ans = 1; for(int i= 0 ;i<r; i++) { ans*= (n-i); } return ans; } public static double ncr(int n, int r) { double ans = 1; for(int i= 0 ;i<r; i++) { ans*= (n-i); } for(int i= 0 ;i<r; i++) { ans/=(i+1); } return ans; } static long power(int a, long b, int mod) { if(b == 0) return 1; long x = power(a, b/2, mod); if(b % 2 == 0) return (x * x) % mod; else return (((a * x) % mod) * x) % mod; } public static void fillPrime() { int n = 1000007; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i * i < n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) { isPrime[j] = false; } } } } static final Random random = new Random(); static void sort(int[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); int cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static void sortl(long[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); long cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (st == null || !st.hasMoreTokens()) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
7d2e90f6366062be8dd18de1d3f4e608
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Dec10B { static boolean[] isPrime; public static void main(String[] args) { FastScanner sc=new FastScanner(); PrintWriter pw=new PrintWriter(System.out); int ts=sc.nextInt(); while(ts-- > 0){ long n=sc.nextLong(); long k=sc.nextLong(); long temp=1,c=0; while(temp<k){ temp=temp<<1; c++; } if(temp<n){ c += (n - temp + k - 1) / k; } System.out.println(c); } pw.flush(); } public static long npr(int n, int r) { long ans = 1; for(int i= 0 ;i<r; i++) { ans*= (n-i); } return ans; } public static double ncr(int n, int r) { double ans = 1; for(int i= 0 ;i<r; i++) { ans*= (n-i); } for(int i= 0 ;i<r; i++) { ans/=(i+1); } return ans; } static long power(int a, long b, int mod) { if(b == 0) return 1; long x = power(a, b/2, mod); if(b % 2 == 0) return (x * x) % mod; else return (((a * x) % mod) * x) % mod; } public static void fillPrime() { int n = 1000007; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i * i < n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) { isPrime[j] = false; } } } } static final Random random = new Random(); static void sort(int[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); int cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static void sortl(long[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); long cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (st == null || !st.hasMoreTokens()) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
af68ede02e9c31c0d8281242100810b4
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class cf { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ long n = sc.nextLong(); long k = sc.nextLong(); long hour = 0; long cmp=1; while (cmp<k){ cmp*=2; hour++; //System.out.println(1); } if(cmp<n){ if((n-cmp)%k==0){ hour+=((n-cmp)/k); } else{ hour+=(n-cmp)/k+1; } } System.out.println(hour); } } } ////////////////////////////////////////////////////////////// // LCM AND GCD /* public static int gcd(int a,int b){ if(b == 0){ return a; } return gcd(b,a%b); } public static int lcm(int a,int b){ return (a / gcd(a, b)) * b; }*/ /////////////////////////////////////////////////////////////////////////////////// //Iterator /*Iterator iterator = object.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next() + " "); }*/ /////////////////////////////////////////////////////////////////////////////////// class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } public char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
4b5ca3c17efc9152db5eba4c4194a1ed
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class cf { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ long n = sc.nextLong(); long k = sc.nextLong(); long hour = 0; long cmp=1; while (cmp<k){ cmp*=2; hour++; } hour+=(n-cmp+k-1)/k; System.out.println(hour); } } } ////////////////////////////////////////////////////////////// // LCM AND GCD /* public static int gcd(int a,int b){ if(b == 0){ return a; } return gcd(b,a%b); } public static int lcm(int a,int b){ return (a / gcd(a, b)) * b; }*/ /////////////////////////////////////////////////////////////////////////////////// //Iterator /*Iterator iterator = object.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next() + " "); }*/ /////////////////////////////////////////////////////////////////////////////////// class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } public char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
3f0c58941c313e22f915aa855af76bf4
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.StringTokenizer; public class UpdateComputers { static int mod = 1000000007; public static void main(String[] args) throws IOException { FastReader reader = new FastReader(); FastWriter writer = new FastWriter(); int numTests = reader.readSingleInt(); for(int t = 0; t < numTests; t++){ long[] longs = reader.readLongArray(2); long numComps = longs[0]; long numCables = longs[1]; if (numComps <= 1){ writer.writeSingleInteger(0); continue; } long patchedComps = 1; long hours = 0; while (patchedComps <= numCables && patchedComps < numComps) { patchedComps = patchedComps + patchedComps; hours++; } hours += Math.max(0, numComps-patchedComps)/numCables; if (Math.max(0, numComps-patchedComps) % numCables != 0) hours++; writer.writeSingleLong(hours); } } public static void mergeSort(int[] a) { mergeSort(a, a.length); } public static void mergeSort(int[] a, int n) { if (n < 2) { return; } int mid = n / 2; int[] l = new int[mid]; int[] r = new int[n - mid]; for (int i = 0; i < mid; i++) { l[i] = a[i]; } for (int i = mid; i < n; i++) { r[i - mid] = a[i]; } mergeSort(l, mid); mergeSort(r, n - mid); merge(a, l, r, mid, n - mid); } public static void merge(int[] a, int[] l, int[] r, int left, int right) { int i = 0, j = 0, k = 0; while (i < left && j < right) { if (l[i] <= r[j]) { a[k++] = l[i++]; } else { a[k++] = r[j++]; } } while (i < left) { a[k++] = l[i++]; } while (j < right) { a[k++] = r[j++]; } } public static class FastReader { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer; public int readSingleInt() throws IOException { return Integer.parseInt(reader.readLine()); } public int[] readIntArray(int numInts) throws IOException { int[] nums = new int[numInts]; tokenizer = new StringTokenizer(reader.readLine()); for(int i = 0; i<numInts; i++){ nums[i] = Integer.parseInt(tokenizer.nextToken()); } return nums; } public long[] readLongArray(int numLongs) throws IOException { long[] nums = new long[numLongs]; tokenizer = new StringTokenizer(reader.readLine()); for(int i = 0; i<numLongs; i++){ nums[i] = Long.parseLong(tokenizer.nextToken()); } return nums; } public String readString() throws IOException { return reader.readLine(); } } public static class FastWriter { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); public void writeSingleInteger(int i) throws IOException { writer.write(Integer.toString(i)); writer.newLine(); writer.flush(); } public void writeSingleLong(long i) throws IOException { writer.write(Long.toString(i)); writer.newLine(); writer.flush(); } public void writeIntArrayWithSpaces(int[] nums) throws IOException { for(int i = 0; i<nums.length; i++){ writer.write(nums[i] + " "); } writer.newLine(); writer.flush(); } public void writeIntArrayListWithSpaces(ArrayList<Integer> nums) throws IOException { for(int i = 0; i<nums.size(); i++){ writer.write(nums.get(i) + " "); } writer.newLine(); writer.flush(); } public void writeIntArrayWithoutSpaces(int[] nums) throws IOException { for(int i = 0; i<nums.length; i++){ writer.write(Integer.toString(nums[i])); } writer.newLine(); writer.flush(); } public void writeString(String s) throws IOException { writer.write(s); writer.newLine(); writer.flush(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
04007b2b96690007a0bef4464dd41837
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt() ; while (n -- != 0){ long sum = sc.nextLong() ; long line = sc.nextLong() ; long ans = 0 ; long cur = 1 ; while (cur < line){ cur *= 2 ; ans ++ ; } if(cur < sum){ long leave = sum - cur ; ans += (leave / line) ; if( (leave % line ) != 0 ){ ans++ ; } } System.out.println(ans); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
b8d8b59eceac6e13c5a2ff036d064fee
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; // import java.lang.*; // import java.math.*; public class Codeforces { static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=1000000007; // static long mod=998244353; static int MAX=Integer.MAX_VALUE; static int MIN=Integer.MIN_VALUE; static long MAXL=Long.MAX_VALUE; static long MINL=Long.MIN_VALUE; static ArrayList<Integer> graph[]; static long fact[]; static StringBuffer sb; public static void main (String[] args) throws java.lang.Exception { // code goes here int t=I(); outer:while(t-->0) { long n=L(),k=L(); n--; int p=0; long ans=0; while(n>=(1L<<p) && (1L<<p)<=k){ ans++; n-=(1L<<p); p++; } ans+=(n+k-1)/k; out.println(ans); } out.close(); } public static class pair { long a; long b; public pair(long val,long index) { a=val; b=index; } } public static class myComp implements Comparator<pair> { //sort in ascending order. // public int compare(pair p1,pair p2) // { // if(p1.a==p2.a) // return 0; // else if(p1.a<p2.a) // return -1; // else // return 1; // } // sort in descending order. public int compare(pair p1,pair p2) { if(p1.a==p2.a) return 0; else if(p1.a<p2.a) return 1; else return -1; } } public static long nPr(int n,int r) { long ans=divide(fact(n),fact(n-r),mod); return ans; } public static long nCr(int n,int r) { long ans=divide(fact[n],mul(fact[n-r],fact[r]),mod); return ans; } public static long kadane(long a[],int n) //largest sum subarray { long max_sum=Long.MIN_VALUE,max_end=0; for(int i=0;i<n;i++){ max_end+=a[i]; if(max_sum<max_end){max_sum=max_end;} if(max_end<0){max_end=0;} } return max_sum; } public static void DFS(int s,boolean visited[]) { visited[s]=true; for(int i:graph[s]){ if(!visited[i]){ DFS(i,visited); } } } public static void setGraph(int n,int m) { graph=new ArrayList[n+1]; for(int i=0;i<=n;i++){ graph[i]=new ArrayList<>(); } for(int i=0;i<m;i++){ int u=I(),v=I(); graph[u].add(v); graph[v].add(u); } } public static int BS(int a[],int x,int ii,int jj) { // int n=a.length; int mid=0; int i=ii,j=jj; while(i<=j) { mid=(i+j)/2; if(a[mid]<x){ i=mid+1; }else if(a[mid]>x){ j=mid-1; }else{ return mid+1; } } return 0; } //LOWER_BOUND and UPPER_BOUND functions public static int lower_bound(int arr[],int X,int start, int end) //start=0,end=n-1 { if(start>end)return -1; if(arr[arr.length-1]<X)return end; if(arr[0]>X)return -1; int left=start,right=end; while(left<right){ int mid=(left+right)/2; if(arr[mid]==X){ //Returns last index of lower bound value. if(mid<end && arr[mid+1]==X){ left=mid+1; }else{ return mid; } } // if(arr[mid]==X){ //Returns first index of lower bound value. // if(mid>start && arr[mid-1]==X){ // right=mid-1; // }else{ // return mid; // } // } else if(arr[mid]>X){ if(mid>start && arr[mid-1]<X){ return mid-1; }else{ right=mid-1; } }else{ if(mid<end && arr[mid+1]>X){ return mid; }else{ left=mid+1; } } } return left; } public static int upper_bound(int arr[],int X,int start,int end) //start=0,end=n-1 { if(arr[0]>=X)return start; if(arr[arr.length-1]<X)return -1; int left=start,right=end; while(left<right){ int mid=(left+right)/2; if(arr[mid]==X){ //returns first index of upper bound value. if(mid>start && arr[mid-1]==X){ right=mid-1; }else{ return mid; } } // if(arr[mid]==X){ //returns last index of upper bound value. // if(mid<end && arr[mid+1]==X){ // left=mid+1; // }else{ // return mid; // } // } else if(arr[mid]>X){ if(mid>start && arr[mid-1]<X){ return mid; }else{ right=mid-1; } }else{ if(mid<end && arr[mid+1]>X){ return mid+1; }else{ left=mid+1; } } } return left; } //END public static boolean isSorted(int a[]) { int n=a.length; for(int i=0;i<n-1;i++){ if(a[i]>a[i+1])return false; } return true; } public static boolean isSorted(long a[]) { int n=a.length; for(int i=0;i<n-1;i++){ if(a[i]>a[i+1])return false; } return true; } public static int computeXOR(int n) //compute XOR of all numbers between 1 to n. { if (n % 4 == 0) return n; if (n % 4 == 1) return 1; if (n % 4 == 2) return n + 1; return 0; } public static ArrayList<Integer> primeSieve(int n) { ArrayList<Integer> arr=new ArrayList<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } // Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n); public static class FenwickTree { int farr[]; int n; public FenwickTree(int c) { n=c+1; farr=new int[n]; } // public void update_range(int l,int r,long p) // { // update(l,p); // update(r+1,(-1)*p); // } public void update(int x,int p) { for(;x<n;x+=x&(-x)) { farr[x]+=p; } } public long get(int x) { long ans=0; for(;x>0;x-=x&(-x)) { ans=ans+farr[x]; } return ans; } } //Disjoint Set Union public static class DSU { int par[],rank[]; public DSU(int c) { par=new int[c+1]; rank=new int[c+1]; for(int i=0;i<=c;i++) { par[i]=i; rank[i]=0; } } public int find(int a) { if(a==par[a]) return a; return par[a]=find(par[a]); } public void union(int a,int b) { int a_rep=find(a),b_rep=find(b); if(a_rep==b_rep) return; if(rank[a_rep]<rank[b_rep]) par[a_rep]=b_rep; else if(rank[a_rep]>rank[b_rep]) par[b_rep]=a_rep; else { par[b_rep]=a_rep; rank[a_rep]++; } } } public static class myComp1 implements Comparator<pair1> { //sort in ascending order. public int compare(pair1 p1,pair1 p2) { if(p1.a==p2.a) return 0; else if(p1.a<p2.a) return -1; else return 1; } //sort in descending order. // public int compare(pair p1,pair p2) // { // if(p1.a==p2.a) // return 0; // else if(p1.a<p2.a) // return 1; // else // return -1; // } } public static class pair1 { long a; long b; public pair1(long val,long index) { a=val; b=index; } } public static ArrayList<pair1> mergeIntervals(ArrayList<pair1> arr) { //****************use this in main function-Collections.sort(arr,new myComp1()); ArrayList<pair1> a1=new ArrayList<>(); if(arr.size()<=1) return arr; a1.add(arr.get(0)); int i=1,j=0; while(i<arr.size()) { if(a1.get(j).b<arr.get(i).a) { a1.add(arr.get(i)); i++; j++; } else if(a1.get(j).b>arr.get(i).a && a1.get(j).b>=arr.get(i).b) { i++; } else if(a1.get(j).b>=arr.get(i).a) { long a=a1.get(j).a; long b=arr.get(i).b; a1.remove(j); a1.add(new pair1(a,b)); i++; } } return a1; } public static ArrayList<Long> primeFact(long a) { ArrayList<Long> arr=new ArrayList<>(); while(a%2==0){ arr.add(2L); a=a/2; } for(long i=3;i*i<=a;i+=2){ while(a%i==0){ arr.add(i); a=a/i; } } if(a>2)arr.add(a); return arr; } public static boolean isInteger(double N) { int X = (int)N; double temp2 = N - X; if (temp2 > 0) { return false; } return true; } public static boolean isPalindrome(String s,int n) { for(int i=0;i<=n/2;i++){ if(s.charAt(i)!=s.charAt(n-i-1)){ return false; } } return true; } public static int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } public static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } public static long fact(long n) { long fact=1; for(long i=2;i<=n;i++){ fact=((fact%mod)*(i%mod))%mod; } return fact; } public static long fact(int n) { long fact=1; for(int i=2;i<=n;i++){ fact=((fact%mod)*(i%mod))%mod; } return fact; } public static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static void printArray(long a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(int a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(char a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]); } out.println(); } public static void printArray(String a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(boolean a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(pair a[]) { for(pair p:a){ out.println(p.a+"->"+p.b); } } public static void printArray(int a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(long a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArray(char a[][]) { for(int i=0;i<a.length;i++){ for(int j=0;j<a[i].length;j++){ out.print(a[i][j]+" "); }out.println(); } } public static void printArrayL(ArrayList<Long> arr) { for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); } out.println(); } public static void printArrayI(ArrayList<Integer> arr) { for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); } out.println(); } public static void printArrayS(ArrayList<String> arr) { for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); } out.println(); } public static void printMapInt(HashMap<Integer,Integer> hm){ for(Map.Entry<Integer,Integer> e:hm.entrySet()){ out.println(e.getKey()+"->"+e.getValue()); }out.println(); } public static void printMapLong(HashMap<Long,Long> hm){ for(Map.Entry<Long,Long> e:hm.entrySet()){ out.println(e.getKey()+"->"+e.getValue()); }out.println(); } //Modular Arithmetic public static long add(long a,long b) { a+=b; if(a>=mod)a-=mod; return a; } public static long sub(long a,long b) { a-=b; if(a<0)a+=mod; return a; } public static long mul(long a,long b) { return ((a%mod)*(b%mod))%mod; } public static long divide(long a,long b,long m) { a=mul(a,modInverse(b,m)); return a; } public static long modInverse(long a,long m) { int x=0,y=0; own p=new own(x,y); long g=gcdExt(a,m,p); if(g!=1){ out.println("inverse does not exists"); return -1; }else{ long res=((p.a%m)+m)%m; return res; } } public static long gcdExt(long a,long b,own p) { if(b==0){ p.a=1; p.b=0; return a; } int x1=0,y1=0; own p1=new own(x1,y1); long gcd=gcdExt(b,a%b,p1); p.b=p1.a - (a/b) * p1.b; p.a=p1.b; return gcd; } public static long pwr(long m,long n) { long res=1; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m); } n=n>>1; m=(m*m); } return res; } public static long modpwr(long m,long n) { long res=1; m=m%mod; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m)%mod; } n=n>>1; m=(m*m)%mod; } return res; } public static class own { long a; long b; public own(long val,long index) { a=val; b=index; } } //Modular Airthmetic public static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(char[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { char tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static int I(){return sc.I();} public static long L(){return sc.L();} public static String S(){return sc.S();} public static double D(){return sc.D();} } 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 I(){ return Integer.parseInt(next()); } long L(){ return Long.parseLong(next()); } double D(){ return Double.parseDouble(next()); } String S(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
9e31b995f8044358620853706c314757
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { FastScanner f= new FastScanner(); int ttt=1; ttt=f.nextInt(); PrintWriter out=new PrintWriter(System.out); outer: for(int tt=0;tt<ttt;tt++) { long n=f.nextLong(); long k=f.nextLong(); long ans=0; long curr=1; while(curr<=k) { curr*=2; ans++; if(curr>=n) break; } // System.out.println(curr+" "+ans); ans+=((n-curr+k-1)/k); System.out.println(ans); } out.close(); } static void sort(int[] p) { ArrayList<Integer> q = new ArrayList<>(); for (int i: p) q.add( i); Collections.sort(q); for (int i = 0; i < p.length; i++) p[i] = q.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } long[] readLongArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
add97eba93d94eddb13a333d662fb996
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i; long n,k; long h; long c; int t = sc.nextInt(); for(i = 0; i <t;i++){ n= sc.nextLong(); k= sc.nextLong(); h=0; c=1; while (c<k){ c *= 2; h++; } if(c < n) h+= (n-c+k-1)/k; System.out.println(h); /*while(n!=0){ if(n-c < 0 && n-k < 0){ n=0; c+=n; } else{ if (c >= k) { n -= k; c += k; } else { n -= c; c *= 2; } } h++; } System.out.println(h); */ } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
786b9518762002ddb44721f60dee3bea
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class MyAnswer { static class FastScanner{ //10^5 -- .15 sec && 4*10^6 ---> .86 sec BufferedReader br; StringTokenizer st; public FastScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); } public String next(){ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } public int[] nextIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = nextLong(); } return arr; } public double[] nextDoubleArray(int n){ double arr[] = new double[n]; for(int i = 0;i<n;i++){ arr[i] = nextDouble(); } return arr; } public String[] nextStringArray(int n){ String arr[] = new String[n]; for(int i = 0;i<n;i++){ arr[i] = next(); } return arr; } } public static void main(String[] args)throws IOException{ FastScanner scan = new FastScanner(); //SuperFastScanner scan = new SuperFastScanner(); PrintWriter out = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); int t = scan.nextInt(); while (t-- > 0){ long n = scan.nextLong(); long k = scan.nextLong(); long ans = 0; long now = 1; while(now < k){ ans++; now = now*2; } if(now < n){ long rem = n-now; ans += rem % k == 0 ? rem/k : rem / k + 1; } sb.append(ans); sb.append("\n"); } out.println(sb); out.flush(); } public static int solve(){ return 0; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
26e3a88ae5831176da83f86f12eb43de
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; public class B { public static void main(String[] args) throws IOException { FastScanner fs=new FastScanner(); PrintWriter out = new PrintWriter(System.out); int T = fs.nextInt(); for (int tt=0; tt<T; tt++) { long n = fs.nextLong(); long k = fs.nextLong(); long res = (long)((Math.log(k)/Math.log(2))); if ((long)Math.pow(2,res)<k) { res++; } long rem = n-(long)Math.pow(2,res); if (rem>0) { res+=rem/k+(rem%k==0?0:1); } out.println(res); } out.close(); } static final Random random=new Random(); static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d763e6e7e4c610a460eae740110450c0
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class Update_files { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int tc = Integer.parseInt(scanner.next()); while(tc-- > 0) { long n = Long.parseLong(scanner.next()); long k = Long.parseLong(scanner.next()); long comp = 1 ; long hr = 0; while(comp < k) { comp *= 2; hr++; } if(comp < n) hr += (n-comp)%k == 0 ? (n-comp)/k : (n-comp)/k +1 ; System.out.println(hr); }scanner.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
ad2622b8f4f2d80829123a5176a51fde
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.math.*; import java.util.* ; import java.io.* ; @SuppressWarnings("unused") /* * * SEND HELP * */ //Scanner s = new Scanner(new File("input.txt")); //s.close(); //PrintWriter writer = new PrintWriter("output.txt"); //writer.close(); public class cf { static final int mod = (int)1e9+7 ; static final double pi = 3.1415926536 ; static boolean not_prime[] = new boolean[1000001] ; static void sieve() { for(int i=2 ; i*i<1000001 ; i++) { if(not_prime[i]==false) { for(int j=2*i ; j<1000001 ; j+=i) { not_prime[j]=true ; } } }not_prime[0]=true ; not_prime[1]=true ; } public static long bexp(long base , long power) { long res=1L ; base = base%mod ; while(power>0) { if((power&1)==1) { res=(res*base)%mod ; power-- ; } else { base=(base*base)%mod ; power>>=1 ; } } return res ; } static long modInverse(long n, long p){return power(n, p - 2, p); } static long power(long x, long y, long p) { // Initialize result long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; x = (x * x) % p; } return res; } static long nCrModPFermat(int n, int r, long p){if(n<r) return 0 ;if (r == 0)return 1; long[] fac = new long[n + 1];fac[0] = 1;for (int i = 1; i <= n; i++)fac[i] = fac[i - 1] * i % p;return (fac[n] * modInverse(fac[r], p) % p* modInverse(fac[n - r], p) % p) % p;} static long mod_add(long a, long b){ return ((a % mod) + (b % mod)) % mod; } static long mod_sub(long a, long b){ return ((a % mod) - (b % mod) + mod) % mod; } static long mod_mult(long a, long b){ return ((a % mod) * (b % mod)) % mod; } static long lcm(int a, int b){ return (a / gcd(a, b)) * b; } static long gcd(long a, long b){if (b == 0) {return a;}return gcd(b, a % b);} public static void main(String[] args)throws IOException//throws FileNotFoundException { FastReader in = new FastReader() ; StringBuilder op = new StringBuilder() ; int T = in.nextInt() ; // int T=1 ; for(int tt=0 ; tt<T ; tt++) { long n = in.nextLong() ; long k = in.nextLong() ; long curr=1 ; long ans=0 ; while(curr<n) { if(curr<k) { curr*=2 ; ans++ ; } else { long req = n-curr ; if(req%k==0) { ans+=req/k ; } else { ans+=req/k; ans++ ; } break ; } } op.append(ans+"\n") ; } System.out.println(op.toString()); } static class pair implements Comparator<pair> { int first , second ; pair(int first , int second){ this.first=first ; this.second=second; } public pair() {} public int compare(pair arg0, pair arg1) { return arg0.first-arg1.first; } } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); }; String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
7ddb75bdd7edb625823294840b88a7db
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.math.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; /////////////// ///////// ////////// /// // // // // /// // // // // /// // // // // /// // // // // /// // // // // /// /// // // // // ///// ///////// ////////// public class CodeForces { final static String no = "NO"; final static String yes = "YES"; static int count = 0; static public OutputWriter w = new OutputWriter(System.out); static public FastScanner sc = new FastScanner(); class Pair{ int x ,y; public Pair(int x,int y) { this.x = x; this.y = y; } } public static void main(String[] args) { int t = sc.nextInt(); in: while(t-->0) { long n = sc.nextLong(); long k = sc.nextLong(); long completed = 1; long loop = 0; for(;completed<k;) { completed +=Math.min(completed, k); loop++; } long by = (n-completed)/k; if(by*k<n-completed) by++; w.writer.println(loop+by); } w.writer.flush(); } static int gcd(int a, int b){ if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } // method to return LCM of two numbers static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long getPairsCount(long[] arr, long sum) { Map<Long, Long> hm = new HashMap<>(); int n = arr.length; long count = 0; for(int i =0;i<n;i++) { if(hm.containsKey(sum - arr[i])) { count+=hm.get(sum-arr[i]); } if(hm.get(arr[i])!=null) { hm.put(arr[i], hm.get(arr[i])+1); } else { hm.put(arr[i], 1l); } } return count; } static long sumLong(int[]arr) { long sum =0; for(int x:arr) { sum+=x; } return sum; } static boolean isEqualList(ArrayList<Integer> arr,ArrayList<Integer> temp){ for(int i =0;i<arr.size();i++){ if(arr.get(i)!=temp.get(i)){ return true; } } return false; } static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sort(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sortDec(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static void sortDec(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static int[] countInversions(int[]arr,int low,int high){ if(low==high) { int base[] = new int[1]; base[0] = arr[low]; return base; } int mid = low+(high-low)/2; int left[] = countInversions(arr,low,mid); int right[] = countInversions(arr,mid+1,high); int[]merged = merge(left,right); return merged; } static int[] merge(int first[], int[]next) { int i = 0; int j = 0; int k = 0; int[]merged = new int[first.length+next.length]; while(j<first.length && k<next.length) { if(first[j]>=next[k]) { merged[i++] = first[j++]; }else { merged[i++] = next[k++]; count += first.length -j; } } while(j<first.length) { merged[i++] = first[j++]; } while(k<next.length) { merged[i++] = next[k++]; } return merged; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int [] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } long [] longArray(int n) { long[] a=new long[n]; for(int i=0 ; i<n ; i++) a[i]=nextLong(); return a; } double nextDouble() { return Double.parseDouble(next()); } } static public class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
547f5b8041554e15e8c36f717f3edd2a
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); while (a-->0) { long n=sc.nextLong(); long k=sc.nextLong(); if(n==1) { System.out.println("0"); } else if(k==1) { System.out.println((n-1)); } else { n=n-1; long t=0,i=1; while(n>0 && i<k) { t++; n=n-i; i=i*2; } if(n>0) { t=t+((n%k>0)?((n/k)+1):(n/k));} System.out.println(t); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
862cb8c0d43ede962a6a3eb9c6515efa
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.math.*; public class cf2{ public static void main (String [] args){ Scanner sc = new Scanner (System.in); int t = sc.nextInt(); sc.nextLine(); while(t-->0){ String s= sc.next(); String s2 = sc.next(); BigInteger n = new BigInteger(s); n = n.subtract(BigInteger.valueOf(1)); BigInteger k = new BigInteger(s2); BigInteger l = new BigInteger("0"); BigInteger b = new BigInteger("0"); BigInteger ans = new BigInteger("0"); int c= n.compareTo(b); boolean flag=false; int d=0; if (c!=0){ b = b.add(BigInteger.valueOf(2)); ans = ans.add(BigInteger.valueOf(1)); n = n.add(BigInteger.valueOf(1)); c=n.compareTo(b); } while(c>0){ d=k.compareTo(b); if (d>0) b = b.multiply(BigInteger.valueOf(2)); else { flag = true; break; } ans = ans.add(BigInteger.valueOf(1)); c=n.compareTo(b); } if (flag){ BigInteger kk = n.subtract(b); BigInteger f = kk.divide(k); ans = ans.add(f); int mm = BigInteger.valueOf(0).compareTo(kk.mod(k)); if (mm!=0){ ans = ans.add(BigInteger.valueOf(1)); } } System.out.println (ans); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
41d26172a8c6fb6d8a61d8d0e257bf05
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; //import javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar; import java.lang.*; import java.io.*; public class Main { public static class FastReader { BufferedReader b; StringTokenizer s; public FastReader() { b=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(s==null ||!s.hasMoreElements()) { try { s=new StringTokenizer(b.readLine()); } catch(IOException e) { e.printStackTrace(); } } return s.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=b.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (s != null && s.hasMoreTokens()) { return true; } String tmp; try { b.mark(1000); tmp = b.readLine(); if (tmp == null) { return false; } b.reset(); } catch (IOException e) { return false; } return true; } } public static long gcd(long a,long b) {if(a==0)return b; return gcd(b%a,a);} public static int gcd(int a,int b) {if(a==0)return b; return gcd(b%a,a);}; static int power(int x, int y){ if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } static long power(long x , long y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } public static void main (String[] args) throws java.lang.Exception { long mod=1000000007; FastReader in=new FastReader(); if(in.hasNext()){ if(in.hasNext()){ BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int test=in.nextInt(); while(test-->0) { long n=in.nextLong(); long k=in.nextLong(); long total=1; long ans=0; while(total<n) { if(total<k) { total+=total; ans++; } else { long req=n-total; ans+=(req-1)/k+1; break; } } System.out.println(ans); log.flush(); } } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
01a7ae40979d8b42196aa5d1ed981e6d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; //start of Scanner class public class msa { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw = new PrintWriter(System.out); static StringTokenizer st; static Snner sc = new Snner(System.in); static public int maximumProduct(int[] num) { int max1 = 1, max2 = 1; Arrays.sort(num); for (int i = 0; i < 3; i++) { max1 *= num[num.length - 1 - i]; if (i < 2) max2 *= num[i]; } max2 *= num[num.length - 1]; return max1 > max2 ? max1 : max2; } public static void main(String args[]) throws NumberFormatException, IOException { long t = sc.nextLong(); while (t-- > 0) { pw.println(solveb(sc.nextLong(), sc.nextLong())); /* int caves = sc.nextInt(); int arr[][] = new int[caves][]; while (caves-- > 0) { int mon = sc.nextInt(); int ca = arr.length - caves - 1; arr[ca] = new int[mon]; for (int i = 0; i < mon; i++) arr[ca][i] = sc.nextInt(); } pw.println(b(arr)); }*/ } pw.close(); } //segtree static long b(int arr[][]) { int s = 1; int e = (int) 10e9; int mid; while (s <= e) { mid = s + ((e - s) >> 1); int temp = sum(arr, mid); if (temp < 0) s = mid + 1; else if (temp == 0) return mid; else e = mid - 1; } return s; } static long solve(long arr[][]) { long b[] = new long[arr.length]; long max0 = Long.MIN_VALUE; for (int i = 0; i < arr.length; i++) { long max = Long.MIN_VALUE; for (int j = 1; j < arr[i].length; j++) { max = Math.max(max, arr[i][j] - j + 1); } long k = arr[i].length; b[i] = max - k; } Arrays.sort(b); return b[b.length - 1]; } private static int sum(int[][] arr, int mid) { int sum = arr[0][0] + 1; for (int i = 0; i < arr.length; i++) { for (int j = 1; j < arr[i].length; j++) { if (sum < arr[i][j]) sum += 1 + arr[i][j] - sum; sum++; } } return mid - sum; } static long solve_b(long n, long k) { int i = 0; long done = 1; while (done < k) { done = done * 2; i++; } i += Math.ceil(((double) n - (double) done) / (double) k); return i; } static long solveb(long n, long k) { long done = 1; long poss = 1; long i = 0; if (k == 1) return n - 1; if (k > n) k = n; while (done < k && done < n) { i++; done += poss; poss = done; } if ((n - done) % k > 0) i++; i += (n - done) / k; return i; } // //end of public clas static String solve_a(String x) { int a = 0, b = 0; for (int i = 0; i < x.length() - 1; i++) { if (x.charAt(i) != x.charAt(i + 1)) { if (x.charAt(i) == 'a') a++; else b++; } } //char aa[] = x.toCharArray(); StringBuilder xx = new StringBuilder(x); if (a == b) return x; else if (a > b) { for (int i = 0; i < x.length(); i++) { if (x.charAt(i) == 'a') { xx.setCharAt(i, 'b'); break; } } } else { for (int i = 0; i < x.length(); i++) { if (x.charAt(i) == 'b') { xx.setCharAt(i, 'a'); break; } } } return xx.toString(); } int count(String x) { int c = 0; for (int i = 0; i < x.length() - 1; i++) { if (x.charAt(i) != x.charAt(i + 1)) c++; } return c; } boolean prime_or_not(long x) { if (x % 2 == 0 || x % 3 == 0) return false; for (long i = 6; i * i < x; i += 6) if (x % (i + 1) == 0 || x % (i - 1) == 0) return false; return true; } static class Snner { StringTokenizer st; BufferedReader br; public Snner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Snner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } class SegmentTree { int N, n; long[] arr, a; long ident; //arr = segment tree; //a is input_array but (1 based , its len is completed to power 2 with identity values if possible ); //N =len of a; //n=num of input array element ; // All index are 1 based except for am array (in the constructor); SegmentTree(long[] am, long ident) { n = am.length; N = 1; while (N < n) N *= 2; a = new long[N + 1]; this.ident = ident; Arrays.fill(a, ident); for (int i = 0; i < n; i++) a[i + 1] = am[i]; arr = new long[2 * N]; Arrays.fill(arr, ident); build(1, 1, N); } long build(int node, int l, int r) { if (l == r) return arr[node] = a[node - (N - 1)]; int mid = (l + r) / 2; return arr[node] = build(2 * node, l, mid) + build(2 * node + 1, mid + 1, r); } void update_point(int index, long new_value) { arr[N - 1 + index] = new_value; index = index + N - 1; while (index > 1) { index /= 2; arr[index] = arr[2 * index] + arr[2 * index + 1]; } } long query(int l, int r) { return q(1, 1, N, l, r); } private long q(int node, int s, int e, int l, int r) { if (l > e || r < s) return ident; if (s >= l && e <= r) return arr[node]; int mid = (s + e) / 2; return q(node * 2, s, mid, l, r) + q(node * 2 + 1, mid + 1, e, l, r); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
1a5a3a4a86a27562ffd8e31c49099bcf
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class P2 { public static void main(String[] args) { FastIO io = new FastIO(); int t = io.nextInt(); while (t --> 0) { long n = io.nextLong(), k = io.nextLong(); long activated = 1, answer = 0; while (activated<n) { if (k < activated) { answer += (n-activated)/k; if ((n-activated)%k != 0) { answer++; } break; } else { answer++; activated += Math.min(activated, k); } } io.println(answer); } io.close(); } static class FastIO extends PrintWriter { BufferedReader br; StringTokenizer st; public FastIO() { super(System.out); br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.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()); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } super.close(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
fff473e10cc313dc0fc9beae3d7167b7
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class C { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); if(k==1) { System.out.println((long)n-1); }else { long let =0; long test=n; long mul=1; test-=2; long chk=0; boolean andr=false; while(test>0) { // System.out.println("dfd"); mul*=2; if(mul<=k) { test-=mul; chk++; }else { let=(long)(test/k); if(test%k!=0) { andr=true; } test-=(long)(let*k); chk+=let; if(andr) { test=0; chk+=1; } } } System.out.println((long)chk+1); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
b43b94e8d13397e8a6fc61f598de777f
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ long n=sc.nextLong(); long k=sc.nextLong(); n=n-1; long sum=0,ans=0,p=1; while(p< k && sum+p < n) { sum += p; p = p*2; ans++; } ans+=(n-sum)/k; if(((n-sum)%k)!=0) ans++; System.out.println(ans); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
322e6f4075c6d7662d24d4f22e98e796
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class B_Update_Files{ public static void main(String[] arge){ Scanner sc= new Scanner(System.in); int t= sc.nextInt(); while(t-->0){ long c= sc.nextLong(); long p=sc.nextLong(); if(c==1){ System.out.println(0); } else{ long done=2; long time =1; long cables=1; while(cables<p&&done<c){ cables=cables<<1; if(cables>p) break; time++; done+=cables; } if(done<c){ time+=(c-done)/p; if((c-done)%p>0) time++; } System.out.println(time); } } sc.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d29403033c0b10967cd86ced8e236c82
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { //br = new BufferedReader(new FileReader("input.txt")); //out = new PrintWriter("output.txt"); int t = 1; t = nextInt(); while (t-- != 0) { long n = nextLong() - 1; long k = nextLong(); long ans = 0; long now = 1; while (n > 0) { if (now < k) { n -= now; if (now * 2 < k) now *= 2; else now = k; ans++; } else { ans += (n + k - 1) / k; n = 0; } } out.println(ans); } out.close(); } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); static StringTokenizer in = new StringTokenizer(""); public static boolean hasNext() throws IOException { if (in.hasMoreTokens()) return true; String s; while ((s = br.readLine()) != null) { in = new StringTokenizer(s); if (in.hasMoreTokens()) return true; } return false; } public static String nextToken() throws IOException { while (!in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static long nextLong() throws IOException { return Long.parseLong(nextToken()); } public static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
da46b600ba0ac1a79cfe9ebb928901ad
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class B { public static void main(String[] args)throws IOException { FastScanner scan = new FastScanner(); PrintWriter output = new PrintWriter(System.out); int t = scan.nextInt(); for(int tt = 0;tt<t;tt++) { long n = scan.nextLong(), k = scan.nextLong(); long hours = 0; long comps = 1; while(comps<k) { comps*=2; hours++; } if(comps < n) { hours+= (n-comps)/k; if((n-comps)%k!=0) hours++; } System.out.println(hours); } } public static int[] sort(int arr[]) { List<Integer> list = new ArrayList<>(); for(int i:arr) list.add(i); Collections.sort(list); for(int i = 0;i<list.size();i++) arr[i] = list.get(i); return arr; } public static int gcd(int a, int b) { if(a == 0) return b; return gcd(b%a, a); } static boolean isPrime(int n) { if (n <= 1) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= Math.sqrt(n); i += 2) if (n % i == 0) return false; return true; } public static void printArray(int arr[]) { for(int i:arr) System.out.print(i+" "); System.out.println(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d8e57ca00a90c3ad7add6d77e4c9960b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; //import javafx.util.*; public class Main { static FastReader in = new FastReader(); public static void main(String args[])throws IOException { /* * star,rope,TPST * BS,LST,MS,MQ */ int t = i(); while(t-- > 0){ long n = in.nextLong(); long k = in.nextLong(); long total = 1; long hour = 0; while(total < n){ if(total < k){ total *= 2; hour++; }else{ long remaining = n - total; if(remaining%k == 0){ hour += remaining/k; }else{ hour += remaining/k; hour++; } break; } } System.out.println(hour); } } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i<N; i++) { A[i]=in.nextInt(); } return A; } static long[] inputLong(int N) { long A[]=new long[N]; for(int i=0; i<A.length; i++)A[i]=in.nextLong(); return A; } } class Pair{ int x; int y; Pair(int x, int y){ this.x = x; this.y = 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
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
9bce38a3c20468d5f1cef5c9ae655a3a
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class UpdateFiles{ static long mod = 1000000007L; static MyScanner sc = new MyScanner(); static void solve(){ long n = sc.nextLong(); long k = sc.nextLong(); if(n==1){ out.println(0); return; } if(k==1){ out.println(n-1); return; } long ans = 0, cur = 1; while (cur < k) { cur *= 2; ++ans; } if (cur < n) ans += (n - cur + k - 1) / k; out.println(ans); } static boolean isPali(String str){ int i = 0; int j = str.length()-1; while(i<j){ if(str.charAt(i)!=str.charAt(j)){ return false; } i++; j--; } return true; } static long gcd(long a,long b){ if(b==0) return a; return gcd(b,a%b); } static String reverse(String str){ char arr[] = str.toCharArray(); int i = 0; int j = arr.length-1; while(i<j){ char temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } String st = new String(arr); return st; } static boolean isprime(int n){ if(n==1) return false; if(n==3 || n==2) return true; if(n%2==0 || n%3==0) return false; for(int i = 5;i*i<=n;i+= 6){ if(n%i== 0 || n%(i+2)==0){ return false; } } return true; } static class Pair implements Comparable<Pair>{ int val; int ind; int ans; Pair(int v,int f){ val = v; ind = f; } public int compareTo(Pair p){ return p.val - this.val; } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ // solve(); solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i=0; i<arr.length; i++){ list.add(arr[i]); } Collections.sort(list); // collections.sort uses nlogn in backend for (int i = 0; i < arr.length; i++){ arr[i] = list.get(i); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
74aebf36ed4579d365cc649f326b0dd3
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.StringTokenizer; public class CodeForces { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } public FastScanner(File f){ try { br=new BufferedReader(new FileReader(f)); st=new StringTokenizer(""); } catch(FileNotFoundException e){ br=new BufferedReader(new InputStreamReader(System.in)); st=new StringTokenizer(""); } } String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a =new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } public static long factorial(int n){ if(n==0)return 1; return (long)n*factorial(n-1); } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void sort (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sortReversed (int[]a){ ArrayList<Integer> b = new ArrayList<>(); for(int i:a)b.add(i); Collections.sort(b,new Comparator<Integer>(){ @Override public int compare(Integer o1, Integer o2) { return o2-o1; } }); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static void sort (long[]a){ ArrayList<Long> b = new ArrayList<>(); for(long i:a)b.add(i); Collections.sort(b); for(int i=0;i<b.size();i++){ a[i]=b.get(i); } } static ArrayList<Integer> sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } ArrayList<Integer> ans = new ArrayList<>(); for (int i = 2; i <= n; i++) { if (prime[i] == true) ans.add(i); } return ans; } static int binarySearchSmallerOrEqual(int arr[], int key) { int n = arr.length; int left = 0, right = n; int mid = 0; while (left < right) { mid = (right + left) >> 1; if (arr[mid] == key) { while (mid + 1 < n && arr[mid + 1] == key) mid++; break; } else if (arr[mid] > key) right = mid; else left = mid + 1; } while (mid > -1 && arr[mid] > key) mid--; return mid; } public static int binarySearchStrictlySmaller(int[] arr, int target) { int start = 0, end = arr.length-1; if(end == 0) return -1; if (target > arr[end]) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static int binarySearch(long arr[], long x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } static void init(int[]arr,int val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static void init(int[][]arr,int val){ for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j]=val; } } } static void init(long[]arr,long val){ for(int i=0;i<arr.length;i++){ arr[i]=val; } } static<T> void init(ArrayList<ArrayList<T>>arr,int n){ for(int i=0;i<n;i++){ arr.add(new ArrayList()); } } static int binarySearchStrictlySmaller(ArrayList<Pair> arr, int target) { int start = 0, end = arr.size()-1; if(end == 0) return -1; if (target > arr.get(end).y) return end; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr.get(mid).y >= target) { end = mid - 1; } else { ans = mid; start = mid + 1; } } return ans; } static int binarySearchStrictlyGreater(int[] arr, int target) { int start = 0, end = arr.length - 1; int ans = -1; while (start <= end) { int mid = (start + end) / 2; if (arr[mid] <= target) { start = mid + 1; } else { ans = mid; end = mid - 1; } } return ans; } static long sum (int []a, int[][] vals){ long ans =0; int m=0; while(m<5){ for (int i=m+1;i<5;i+=2){ ans+=(long)vals[a[i]-1][a[i-1]-1]; ans+=(long)vals[a[i-1]-1][a[i]-1]; } m++; } return ans; } public static long pow(long n, long pow) { if (pow == 0) { return 1; } long retval = n; for (long i = 2; i <= pow; i++) { retval *= n; } return retval; } static String reverse(String s){ StringBuffer b = new StringBuffer(s); b.reverse(); return b.toString(); } static String charToString (char[] arr){ String t=""; for(char c :arr){ t+=c; } return t; } public static void main(String[] args) { // StringBuilder sbd = new StringBuilder(); // PrintWriter out = new PrintWriter("output.txt"); // File input = new File("input.txt"); // FastScanner fs = new FastScanner(input); // FastScanner fs = new FastScanner(); // Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int testNumber =fs.nextInt(); // ArrayList<Integer> arr = new ArrayList<>(); for (int T =0;T<testNumber;T++){ // StringBuffer sbf = new StringBuffer(); long n = fs.nextLong()-1; long k = fs.nextLong(); long ans= 0; for (long i=1;i<=k;i*=2){ if(n<=0)break; n-=i; ans++; } if(n>0){ long d = n/k; ans+=d; if(n%k!=0)ans++; } out.print(ans+"\n"); } out.flush(); } static class Pair { int x;//l int y;//r public Pair(int x,int y){ this.x=x; this.y=y; } @Override public boolean equals(Object o) { if(o instanceof Pair){ if(o.hashCode()!=hashCode()){ return false; } else { return x==((Pair)o).x&&y==((Pair)o).y; } } return false; } @Override public int hashCode() { return x+2*y; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
ead7d1322b15aec2beedf2454a897d2d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
/** * @Jai_Bajrang_Bali * @Har_Har_Mahadev */ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Scanner; public class practice2 { static long mod = (int) 1e9 + 7; static long gcd(long a, long b) { if (b > a) { return gcd(b, a); } if (b == 0) { return a; } return gcd(b, a % b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t= sc.nextInt(); while (t-- > 0) { long n=sc.nextLong(); long k=sc.nextLong(); long count=1; long ans=0; while(count<k){ count*=2; ans++; } if(count<n) ans+=(n-count+k-1)/k; System.out.println(ans); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
e09fdab79d0b375d8e1fdc570e57a778
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.lang.*; import java.util.*; import java.io.*; public class B_Update_Files { public static void main(String[] arg){ Scanner s=new Scanner(System.in); try { int t=s.nextInt(); while(t-->0){ long n=s.nextLong(); long k=s.nextLong(); long remaining=n-1; long pc=1; long ans=0; while(pc<=k && remaining>0){ ans++; remaining-=pc; pc*=2; } if(remaining>0){ if(remaining%k==0){ System.out.println(ans+=remaining/k); continue; }else{ ans++; System.out.println(ans+=remaining/k); continue; } } System.out.println(ans); } } catch (Exception e) { } s.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
553a16218a09eef6c48eb52c3314c0c2
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class MyClass { public static void main(String[] args) { Scanner sc= new Scanner (System.in); long t=sc.nextInt(); while (t-->0){ long c=sc.nextLong(); long k=sc.nextLong(); long count=0; long x=1; while (x<k){ x+=x; count++; } if(x<c){ long req=c-x; count+=( req ) / k; if (req%k!=0) count++; } System.out.println(count); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
072372dae0b74ecf77e014785cfbd899
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws Exception { int tc = io.nextInt(); for (int i = 0; i < tc; i++) { solve(); } io.close(); } private static void solve() throws Exception { long n = io.nextLong() - 1; long k = io.nextLong(); long step = 0; long curr = 1; while (n > 0) { if (curr < k) { n -= curr; curr = curr << 1L; step++; } else { step += n / k; if (n % k != 0) step++; break; } } io.println(step); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(a.length); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } //-----------PrintWriter for faster output--------------------------------- public static FastIO io = new FastIO(); //-----------MyScanner class for faster input---------- static class FastIO extends PrintWriter { private InputStream stream; private byte[] buf = new byte[1 << 16]; private int curChar, numChars; // standard input public FastIO() { this(System.in, System.out); } public FastIO(InputStream i, OutputStream o) { super(o); stream = i; } // file input public FastIO(String i, String o) throws IOException { super(new FileWriter(o)); stream = new FileInputStream(i); } // throws InputMismatchException() if previously detected end of file private int nextByte() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars == -1) return -1; // end of file } return buf[curChar++]; } // to read in entire lines, replace c <= ' ' // with a function that checks whether c is a line break public String next() { int c; do { c = nextByte(); } while (c <= ' '); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > ' '); return res.toString(); } public String nextLine() { int c; do { c = nextByte(); } while (c < '\n'); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = nextByte(); } while (c > '\n'); return res.toString(); } public int nextInt() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } public long nextLong() { int c; do { c = nextByte(); } while (c <= ' '); int sgn = 1; if (c == '-') { sgn = -1; c = nextByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = 10 * res + c - '0'; c = nextByte(); } while (c > ' '); return res * sgn; } int[] nextInts(int n) { int[] data = new int[n]; for (int i = 0; i < n; i++) { data[i] = io.nextInt(); } return data; } public double nextDouble() { return Double.parseDouble(next()); } } //-------------------------------------------------------- }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
b57fc41c83e81de4953a88e658819d18
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; public class codeforces1606B { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); for (int rep=1;rep<=numCases;rep++) { StringTokenizer st = new StringTokenizer(br.readLine()); long numComputers = Long.parseLong(st.nextToken()); long cables = Long.parseLong(st.nextToken()); long computerCounter=1; long time=0; while(computerCounter<cables) { computerCounter=computerCounter*2; time++; } if (computerCounter<numComputers) { time = time + (numComputers - computerCounter) / cables; if ((numComputers - computerCounter) % cables != 0) { time++; } } System.out.println(time); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
e9ae14b9b4d038d8e98b9e24ecd7991b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.lang.*; 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++) { long n = sc.nextLong(); long k = sc.nextLong(); long a = 0,c=1; while (c<k){ c*=2; a++; } a+=(n-c+k-1)/k; System.out.println(a); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
e2fe37ac8268c6154f1eccc6bd184975
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.*; public class Codeforces { static String ab,b; static class Node { int val; Node left; Node right; public Node(int x) { // TODO Auto-generated constructor stub this.val=x; this.left=null; this.right=null; } } static class Pair<U, V> implements Comparable<Pair<U, V>> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int compareTo(Pair<U, V> o) { int value = ((Comparable<U>) x).compareTo(o.x); if (value != 0) return value; return ((Comparable<V>) y).compareTo(o.y); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return x.equals(pair.x) && y.equals(pair.y); } public int hashCode() { return Objects.hash(x, y); } } 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[] nextArray(int n) { int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=nextInt(); return arr; } } static String string; static int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater return gcd(b, a % b); } static long gcd(long a, long b) { // Everything divides 0 for(long i=2;i<=b;i++) { if(a%i==0&&b%i==0) return i; } return 1; } static int fac(int n) { int c=1; for(int i=2;i<n;i++) if(n%i==0) c=i; return c; } static int lcm(int a,int b) { for(int i=Math.min(a, b);i<=a*b;i++) if(i%a==0&&i%b==0) return i; return 0; } static int maxHeight(char[][] ch,int i,int j,String[] arr) { int h=1; if(i==ch.length-1||j==0||j==ch[0].length-1) return 1; while(i+h<ch.length&&j-h>=0&&j+h<ch[0].length&&ch[i+h][j-h]=='*'&&ch[i+h][j+h]=='*') { String whole=arr[i+h]; //System.out.println(whole.substring(j-h,j+h+1)); if(whole.substring(j-h,j+h+1).replace("*","").length()>0) return h; h++; } return h; } static boolean all(BigInteger n) { BigInteger c=n; HashSet<Character> hs=new HashSet<>(); while((c+"").compareTo("0")>0) { String d=""+c; char ch=d.charAt(d.length()-1); if(d.length()==1) { c=new BigInteger("0"); } else c=new BigInteger(d.substring(0,d.length()-1)); if(hs.contains(ch)) continue; if(d.charAt(d.length()-1)=='0') continue; if(!(n.mod(new BigInteger(""+ch)).equals(new BigInteger("0")))) return false; hs.add(ch); } return true; } static int cal(long n,long k) { System.out.println(n+","+k); if(n==k) return 2; if(n<k) return 1; if(k==1) return 1+cal(n, k+1); if(k>=32) return 1+cal(n/k, k); return 1+Math.min(cal(n/k, k),cal(n, k+1)); } static Node buildTree(int i,int j,int[] arr) { if(i==j) { //System.out.print(arr[i]); return new Node(arr[i]); } int max=i; for(int k=i+1;k<=j;k++) { if(arr[max]<arr[k]) max=k; } Node root=new Node(arr[max]); //System.out.print(arr[max]); if(max>i) root.left=buildTree(i, max-1, arr); else { root.left=null; } if(max<j) root.right=buildTree(max+1, j, arr); else { root.right=null; } return root; } static int height(Node root,int val) { if(root==null) return Integer.MAX_VALUE-32; if(root.val==val) return 0; if((root.left==null&&root.right==null)) return Integer.MAX_VALUE-32; return Math.min(height(root.left, val), height(root.right, val))+1; } static void shuffle(int a[], int n) { for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index int x = a[t]; a[t] = a[i]; a[i] = x; } } static void sort(int[] arr ) { shuffle(arr, arr.length); Arrays.sort(arr); } static boolean arraySortedInc(int arr[], int n) { // Array has one or no element if (n == 0 || n == 1) return true; for (int i = 1; i < n; i++) // Unsorted pair found if (arr[i - 1] > arr[i]) return false; // No unsorted pair found return true; } static boolean arraySortedDec(int arr[], int n) { // Array has one or no element if (n == 0 || n == 1) return true; for (int i = 1; i < n; i++) // Unsorted pair found if (arr[i - 1] > arr[i]) return false; // No unsorted pair found return true; } static int largestPower(int n, int p) { // Initialize result int x = 0; // Calculate x = n/p + n/(p^2) + n/(p^3) + .... while (n > 0) { n /= p; x += n; } return x; } // Utility function to do modular exponentiation. // It returns (x^y) % p static int power(int x, int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y % 2 == 1) { res = (res * x) % p; } // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n! % p static int modFact(int n, int p) { if (n >= p) { return 0; } int res = 1; // Use Sieve of Eratosthenes to find all primes // smaller than n boolean isPrime[] = new boolean[n + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= n; j += i) { isPrime[j] = false; } } } // Consider all primes found by Sieve for (int i = 2; i <= n; i++) { if (isPrime[i]) { // Find the largest power of prime 'i' that divides n int k = largestPower(n, i); // Multiply result with (i^k) % p res = (res * power(i, k, p)) % p; } } return res; } static boolean[] seiveOfErathnos(int n2) { boolean isPrime[] = new boolean[n2 + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n2; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= n2; j += i) { isPrime[j] = false; } } } return isPrime; } static boolean[] seiveOfErathnos2(int n2,int[] ans) { boolean isPrime[] = new boolean[n2 + 1]; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n2; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= n2; j += i) { if(isPrime[j]) ans[i]++; isPrime[j] = false; } } } return isPrime; } static int calculatePower(PriorityQueue<Integer>[] list,int[] alive) { // List<Integer> dead=new ArrayList<>(); for(int i=1;i<alive.length;i++) { if(alive[i]==1) { if(list[i].size()==0) { continue; } if(list[i].peek()>i) { // dead.add(i); // System.out.println(i); alive[i]=0; for(int j:list[i]) { // list[i].remove((Integer)j); list[j].remove((Integer)i); } list[i].clear(); return 1+calculatePower(list,alive); } } } return 0; } static boolean helper(int i,int j,int[] index,int k,HashMap<String,String> hm) { // System.out.println(i+","+j); if(k<=0) return false; if(i==j) return true; String key=i+","+j; if(hm.containsKey(key)) { String[] all=hm.get(key).split(","); int prev=Integer.parseInt(all[0]); // String val=Integer.parseInt(all[1]); if(prev==k) return all[1].equals("true")?true:false; else if(prev>k&&all[1].equals("false")) return false; else if(prev<k&&all[1].equals("true")) return true; } if(i+1==j) { if(index[i]+1==index[j]||k>=2) return true; return false; } boolean flag=false; for(int p=i;p<j;p++) { if(index[p]+1!=index[p+1]) { flag=true; break; } } if(!flag) { hm.put(key,k+","+ true); return true; } if(k==1) { hm.put(key,k+","+ false); return false; } for(int p=i;p<j;p++) { if(helper(i,p,index,k-1,hm)&&helper(p+1,j,index,k-1,hm)) { hm.put(key,k+","+ true); return true; } } hm.put(key, k+","+false); return false; } static int set(int[] arr,int start) { int count=0; for(int i=0;i<arr.length;i++) { if(arr[i]%2==0) { count+=Math.abs(start-i); start+=2; } } return count; } public static void main(String[] args)throws IOException { BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in)); FastReader fs=new FastReader(); // int[] ans=new int[1000001]; int T=fs.nextInt(); // seiveOfErathnos2(1000000, ans); StringBuilder sb=new StringBuilder(); while(T-->0) { // int n=fs.nextInt(); long n=fs.nextLong(),k=fs.nextLong(); long ans=0,curr=1; while(curr<k) { curr*=2; ans++; } if(curr<n) ans+=(n-curr+k-1)/k; // System.out.println(); sb.append(ans); sb.append("\n"); } System.out.println(sb); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
10ad62f8f401ea0bf93f0523a02b9efa
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class Contest_yandexA{ public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); for(int tt = 0;tt<t;tt++){ long n = input.nextLong(); long k = input.nextLong(); long m = 1; long time = 0; while(k > m){ m*= 2; time++; } //System.out.println(time); if(n > m){ time+= (n-m + k-1)/k; } System.out.println(time); } } public static int gcd(int a,int b){ if(b == 0){ return a; } return gcd(b,a%b); } public static int lcm(int a,int b){ return (a / gcd(a, b)) * b; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d077a6ff58715e310b7e6b9e2a549945
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class CF3 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws java.lang.Exception { // TODO Auto-generated method stub FastReader in=new FastReader(); int t=in.nextInt(); while(t-->0) { long n=in.nextLong(); long k=in.nextLong(); long sum = 0, cur = 1; while (cur < k) { cur *= 2; ++sum; } if (cur < n) sum += (n - cur + k - 1) / k; System.out.println(sum); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
2f503138b1dbce59795db522ea58c2fc
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
//package Div2.B; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class UpdateFiles { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t > 0) { String[] nk = br.readLine().split(" "); long n = Long.parseLong(nk[0]); long k = Long.parseLong(nk[1]); long rem = n - 1;//remaining computers long cables = 1; //no of cables which can be used right now long h = 0; while (rem > 0 && cables <= k) { rem = Math.max(0, rem - cables); h += 1; cables *= 2; } System.out.println(h + (rem / k + (rem % k == 0 ? 0 : 1))); t--; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
8c79585089266bfc3965e5b8eb94611e
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /** * @author Naitik * */ public class Main { static FastReader sc=new FastReader(); static int dp[][][]; //static int v[][]; static int mod=998244353;; // static int mod=1000000007; static long max; static long bit[]; //static long bit1[]; // static long seg[]; //static long fact[]; // static long A[]; // static TreeMap<Integer,Integer> map; //static StringBuffer sb=new StringBuffer(""); static HashMap<Long,Integer> map; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { long n=l(),k=l(); if(n==1) { out.println("0"); continue outer; } long ans=0; long res=0; for(long i=1;i<63;i++) { long y=1L<<i; if(y>=n) { out.println(i); continue outer; } if(y>k) { ans=y; res+=i; break; } } n-=ans; if(n%k==0) { res+=n/k; } else { res+=n/k+1; } out.println(res); } //System.out.println(sb.toString()); out.close(); //CHECK FOR N=1 //CHECK FOR M=0 //CHECK FOR N=1 //CHECK FOR M=0 //CHECK FOR N=1 } static class Pair implements Comparable<Pair> { long x; int y; int z; Pair(long x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return +1; else if(this.x<o.x) return -1; else { if(this.y>o.y) return 1; else if(this.y<o.y) return -1; else return 0; } } // public int hashCode() // { // final int temp = 14; // int ans = 1; // ans =x*31+y*13; // return ans; // } // @Override // public boolean equals(Object o) // { // if (this == o) { // return true; // } // if (o == null) { // return false; // } // if (this.getClass() != o.getClass()) { // return false; // } // Pair other = (Pair)o; // if (this.x != other.x || this.y!=other.y) { // return false; // } // return true; // } // /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } //static int find(int A[],int a) { // if(A[a]<0) // return a; // return A[a]=find(A, A[a]); //} static int find(int A[],int a) { if(A[a]==a) return a; return find(A, A[a]); } //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END static void add(long v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(long v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } public static int upper(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { ans=mid; l=mid+1; } else { u=mid-1; } } return ans; } public static int lower(int A[],int k,int si,int ei) { int l=si; int u=ei; int ans=-1; while(l<=u) { int mid=(l+u)/2; if(A[mid]<=k) { l=mid+1; } else { ans=mid; u=mid-1; } } return ans; } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static long[] copy(long A[]) { long B[]=new long[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } return A; } static long[] inputL(int n) { long A[]=new long[n]; for(int i=0;i<n;i++) { A[i]=sc.nextLong(); } return A; } static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i<n;i++) { A[i]=sc.next(); } return A; } static long sum(int A[]) { long sum=0; for(int i : A) { sum+=i; } return sum; } static long sum(long A[]) { long sum=0; for(long i : A) { sum+=i; } return sum; } static void reverse(long A[]) { int n=A.length; long B[]=new long[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void reverse(int A[]) { int n=A.length; int B[]=new int[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void input(int A[],int B[]) { for(int i=0;i<A.length;i++) { A[i]=sc.nextInt(); B[i]=sc.nextInt(); } } static int[][] input(int n,int m){ int A[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=i(); } } return A; } static char[][] charinput(int n,int m){ char A[][]=new char[n][m]; for(int i=0;i<n;i++) { String s=s(); for(int j=0;j<m;j++) { A[i][j]=s.charAt(j); } } return A; } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static int min(int A[]) { int min=Integer.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long max(long A[]) { long max=Long.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static long min(long A[]) { long min=Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long [] prefix(long A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] prefix(int A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] suffix(long A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(int dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(int dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static void fill(long dp[]) { Arrays.fill(dp, -1); } static void fill(long dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(long dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(long dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static int min(int a,int b) { return Math.min(a, b); } static int min(int a,int b,int c) { return Math.min(a, Math.min(b, c)); } static int min(int a,int b,int c,int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a,int b) { return Math.max(a, b); } static int max(int a,int b,int c) { return Math.max(a, Math.max(b, c)); } static int max(int a,int b,int c,int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a,long b) { return Math.min(a, b); } static long min(long a,long b,long c) { return Math.min(a, Math.min(b, c)); } static long min(long a,long b,long c,long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a,long b) { return Math.max(a, b); } static long max(long a,long b,long c) { return Math.max(a, Math.max(b, c)); } static long max(long a,long b,long c,long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long power(long x, long y, long p) { if(y==0) return 1; if(x==0) return 0; long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void print(int A[]) { for(int i : A) { System.out.print(i+" "); } System.out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+" "); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[]=new Character[s.length()]; for(int i=0;i<s.length();i++) { ch[i]=s.charAt(i); } Arrays.sort(ch); StringBuffer st=new StringBuffer(""); for(int i=0;i<s.length();i++) { st.append(ch[i]); } return st.toString(); } static HashMap<Integer,Integer> hash(int A[]){ HashMap<Integer,Integer> map=new HashMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static HashMap<Long,Integer> hash(long A[]){ HashMap<Long,Integer> map=new HashMap<Long, Integer>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Integer,Integer> tree(int A[]){ TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Long,Integer> tree(long A[]){ TreeMap<Long,Integer> map=new TreeMap<Long, Integer>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static 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
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
24c5d893733592a9aec83fb49ddc63eb
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class FirstProblem { public static void main(String[] args) { FastReader in =new FastReader(); int test = in.nextInt(); for(int i = 0; i<test; i++) { long n, k; n = in.nextLong(); k = in.nextLong(); long ans = 0, cur = 1; while (cur < k) { cur *= 2; ++ans; } if (cur < n) ans += (n - cur + k - 1) / k; System.out.println(ans); } } static class FastReader{ BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stringTokenizer = new StringTokenizer(" "); String next() { while(!stringTokenizer.hasMoreTokens()) { try { stringTokenizer = new StringTokenizer(bReader.readLine()); }catch (Exception e) { e.printStackTrace(); } } return stringTokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
b1168d824d9c263865b98f774d06afdd
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import static java.lang.System.out; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; /** * * @author abhishekraj */ public class Moritozza { static final long mod = (int) 1e9 + 7; static long f[] = new long[1000000]; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); long t =sc.nextLong(); while(t-->0) { long n = sc.nextLong() - 1; long k = sc.nextLong(); long current = 1; long result = 0; while (n > 0) { if (current >= k) { result += n / k; if (n % k != 0) { result++; } break; } long add = current; n -= add; current += add; result++; } out.println(result); } } 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[1000000000]; // 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(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
0e879e0ca983e2df1c843da06c82f99b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.awt.Container; import java.awt.image.SampleModel; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.concurrent.CountDownLatch; import javax.naming.TimeLimitExceededException; import java.io.PrintStream; public class Solution { static class Pair<T,V>{ T first; V second; public Pair(T first, V second) { super(); this.first = first; this.second = second; } } // public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null; private static FastScanner fs=new FastScanner(); private static Scanner sc=new Scanner(System.in); private static int uperBound(long[] arr, long val) { int start= 0; int end=arr.length; while(start<end) { int mid=(start+end)/2; if( arr[mid]==val ) { return mid; } if( arr[mid]>val ) { end=mid-1; }else { start=mid+1; } } if( start >= arr.length || arr[start]>val) { return start; }else { return start+1; } } private static int log2(int n) { if(n<=1) { return 0; } return 1+log2(n/2); } private static int pow(int a, int b ) { if(b==0) return 1; long ans=1; for(int i=0;i<b;i++) { ans= (ans*a)%1000000007; } return (int)(ans%1000000007); } public static void main(String[] args) throws Exception { int tcr=1; //tcr = sc.nextInt(); tcr=fs.nextInt(); while(tcr-->0) { solve(tcr); } System.gc(); } private static void solve(int TC) throws Exception{ long n=fs.nextLong(); long k=fs.nextLong(); long time=0; long done=1; while( done < k ) { done*=2; time++; } long left= n-done; time+= (left+k-1)/k; System.out.println(time); /*String s=fs.next(); if( s.charAt(0)==s.charAt(s.length()-1) ) { System.out.println(s); }else { System.out.println(s.substring(0, s.length()-1)+s.charAt(0)); } /*int n=fs.nextInt(); if(n==1) { System.out.println(1); }else if(n==2) { System.out.println(-1); }else { int arr[][]=new int[n][n]; int num=1; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { arr[i][j]=num; num+=2; if(num> n*n) { num=2; } } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { System.out.print(arr[i][j]+" "); } System.out.println(); } } /*WRITE CODE HERE*/ /*String s=fs.next(); int count=0; for(int i=0;i<s.length()-1;i++) { if( s.charAt(i)=='a' && s.charAt(i+1)=='b' ) { count++; i++; } } int count2=0; for(int i=0;i<s.length()-1;i++) { if( s.charAt(i)=='b' && s.charAt(i+1)=='a' ) { count2++; i++; } } char arr[]= s.toCharArray(); if( count>count2) { for(int i=0;i<s.length()-1;i++) { if( arr[i]=='b' && arr[i+1]=='b' ) { arr[i]='a'; count--; if(count==count2) break; } } }else if( count2> count) { for(int i=0;i<s.length()-1;i++) { if( arr[i]=='a' && arr[i+1]=='a' ) { arr[i]='b'; count2--; if(count==count2) break; } } } if(count==count2) { System.out.println(String.copyValueOf(arr)); }else { for(int i=0;i<s.length();i++) { System.out.print("b"); } System.out.println(); } /*int n=fs.nextInt(); int arr1[]=new int[n]; for(int i=0;i<n;i++) { arr1[i]=fs.nextInt(); } int m=fs.nextInt(); int arr2[]=new int[m]; for(int i=0;i<m;i++) { arr2[i]=fs.nextInt(); } int max1=Integer.MIN_VALUE; for(int i=0;i<n;i++) { max1=Math.max(max1, arr1[i]); } int max2=Integer.MIN_VALUE; for(int i=0;i<m;i++) { max2=Math.max(max2, arr2[i]); } System.out.println(max1+" "+max2); /*int n=fs.nextInt(); char c=fs.next().charAt(0); String s=fs.next(); ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0;i<n;i++) { if(s.charAt(i)==c) { list.add(i); } } if( list.size()==n ) { System.out.println(0); }else if( list.size()==0) { System.out.println(2); System.out.println(2); if(n%2==0) { System.out.println(n-1); }else { System.out.println(n); } } else { if( (list.get(list.size()-1)+1)*2 > n ) { System.out.println(1); System.out.println(list.get(list.size()-1)+1); }else { System.out.println(2); System.out.print(2+" "); if(n%2==0) { System.out.println(n-1); }else { System.out.println(n); } } } /*int n=fs.nextInt(); int k=fs.nextInt(); long sum=0; while(k>3) { int log=log2(k); k= k- (int) pow(2, log); //System.out.println(log); sum= (long) (sum+ ( pow(n, log)%1000000007 ) ) % 1000000007; } if(k==1) { sum=(sum+1)%1000000007;; }else if(k==2) { sum=(sum+n)%1000000007; }else if(k==3) { sum=(sum+n+1)%1000000007;; } System.out.println(sum); /*int arr[]=new int[n]; for(int i=0;i<n;i++) { arr[i]=fs.nextInt(); } for(int i=0;i<n;i++) { arr[i]=~arr[i]; } Arrays.sort(arr); for(int i=0;i<n;i++) { arr[i]=~arr[i]; } for(int i=0;i<n;i++) { System.out.print(arr[i]+" "); } /*long max=Long.MIN_VALUE; for(int i=1;i<n;i++) { max=Math.max(max, 1l*arr[i-1]*arr[i]); } System.out.println(max); /*int n=fs.nextInt(); int m=fs.nextInt(); int k=fs.nextInt(); k=k-2; if( m< n-1 ) { System.out.println("NO"); return ; } if( m*1l > (n*1l*(n-1))/2 ) { System.out.println("NO"); return; } if(k<=-1) { System.out.println("NO"); } else if(k==0) { if(n==1) System.out.println("YES"); else System.out.println("NO"); } else if(k==1 ) { if( m*1l==(n*1l*(n-1))/2 ) System.out.println("YES"); else System.out.println("NO"); } else System.out.println("YES"); /*int n=fs.nextInt(); int arr[]=new int[n]; int min=Integer.MAX_VALUE; for(int i=0;i<n;i++) { arr[i]=fs.nextInt(); if(min>arr[i]) { min=arr[i]; } } ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0;i<n;i++) { int diff=arr[i]-min; if(diff>0) { list.add(diff); } } int gcd; if(list.size()==0) { gcd=-1; }else { gcd=list.get(0); } for(int i=1;i<list.size();i++) { gcd=(int)gcd(gcd, list.get(i)); } System.out.println(gcd); /*int n=fs.nextInt(); int k=fs.nextInt(); ArrayList<Integer> mic=new ArrayList<Integer>(); for(int i=0;i<k;i++) { mic.add(fs.nextInt()); } int ans=0; Collections.sort(mic, Collections.reverseOrder()); /*for(int i:mic) { System.out.print(i+" "); } System.out.println(); int catMov=0; for(int i=0; i< mic.size();i++) { if(catMov<mic.get(i)) { int mov= n- mic.get(i); catMov+=mov; ans++; }else { break; } } System.out.println(ans); /*String n=fs.next(); int i=0; for(i=n.length()-1 ; i>=0 ; i--) { if(n.charAt(i)=='0') { break; } } int ans1=Integer.MAX_VALUE; int ans2=Integer.MAX_VALUE; if( i!=-1 ) { ans1=n.length()-i-1; ans2=n.length()-i-1; int j=i-1; for(; j>=0 ; j--) { if(n.charAt(j)=='0') { break; } } if(j==-1) { ans1=Integer.MAX_VALUE; }else { ans1+= i-j-1; } j=i-1; for(; j>=0 ; j--) { if(n.charAt(j)=='5') { break; } } if(j==-1) { ans2=Integer.MAX_VALUE; }else { ans2+= i-j-1; } } i=0; for(i=n.length()-1 ; i>=0 ; i--) { if(n.charAt(i)=='5') { break; } } int ans3=Integer.MAX_VALUE; int ans4=Integer.MAX_VALUE; if( i!=-1 ) { ans3=n.length()-i-1; ans4=n.length()-i-1; int j=i-1; for(; j>=0 ; j--) { if(n.charAt(j)=='2') { break; } } if(j==-1) { ans3=Integer.MAX_VALUE; }else { ans3+= i-j-1; } j=i-1; for(; j>=0 ; j--) { if(n.charAt(j)=='7') { break; } } if(j==-1) { ans4=Integer.MAX_VALUE; }else { ans4+= i-j-1; } } int min= Math.min(ans1, Math.min(ans2, Math.min(ans3, ans4 ) ) ); System.out.println(min); /*int a=fs.nextInt(); int b=fs.nextInt(); int c=fs.nextInt(); int max=Math.max(a, Math.max(b, c)); int ans1= max==a ? 0 : (max-a+1); int ans2= max==b ? 0 : (max-b+1); int ans3= max==c ? 0 : (max-c+1); if(max==a && max==b && max==c) { System.out.println(1+" "+1+" "+1); } else if(a==b && max==a) { c=max-c; System.out.println(1+" "+1+" "+(c+1)); }else if( b==c && max==b ) { a=max-a; System.out.println((a+1)+" "+1+" "+1); }else if( a==c && max==a ) { b=max-b; System.out.println(1+" "+(b+1)+" "+1); } else System.out.println(ans1+" "+ans2+" "+ans3); /*Queue<Integer> q=new LinkedList<Integer>(); q.add(23); //q.poll(); System.out.println(q.peek()); /* int n=fs.nextInt(); int m=fs.nextInt(); ArrayList<String> list=new ArrayList<String>(); Map<String, Integer> map=new HashMap<String, Integer>(); for(int i=0;i<n;i++) { list.add(fs.next()); map.put(list.get(i), i); } Collections.sort(list, new Comparator<String>() { public int compare(String o1, String o2) { // TODO Auto-generated method stub for (int i = 0; i < o1.length(); i++) { int t = i+1; if (o1.charAt(i) == o2.charAt(i)) continue; if (t%2==1) { return o1.charAt(i)- o2.charAt(i); } else { return o2.charAt(i) - o1.charAt(i); } } return 0; } }); for(int i=0;i<n;i++) { System.out.print(map.get(list.get(i))+1+" "); } System.out.println(); //System.out.println(list); /*for(int i=0;i<m;i++) { for(int j=1;j<n;j++) { if(i%2==0) { int k=0; while( j-1-k>=0 && list.get(j-1-k).substring(0,i).equals(list.get(j-k).substring(0,i)) && list.get(j-1-k).charAt(i) > list.get(j-k).charAt(i) ) { //System.out.println(list.get(j-1-k)+" "+list.get(j-k)); String temp=list.get(j-1-k); list.set(j-1-k, list.get(j-k)); list.set(j-k, temp); k++; //System.out.println(list); } }else { int k=0; while( j-1-k>=0 && list.get(j-1-k).substring(0,i).equals(list.get(j-k).substring(0,i)) && list.get(j-1-k).charAt(i) < list.get(j-k).charAt(i) ) { String temp=list.get(j-1-k); list.set(j-1-k, list.get(j-k)); list.set(j-k, temp); k++; } } } } for(int i=0;i<n;i++) { System.out.print(map.get(list.get(i))+1+" "); } System.out.println(); //System.out.println(list); /*int a=fs.nextInt(); int b=fs.nextInt(); int n=fs.nextInt(); for(int i=0;i<n;i++) { int sum=a; for(int j=0;j<=i;j++) { sum+=Math.pow(2, j)*b; } System.out.print(sum+" "); } System.out.println(); /*int n=fs.nextInt(); int temp=n; ArrayList<Pair<Integer,Integer>> list=new ArrayList<Solution.Pair<Integer,Integer>>(); for(int i=2;i*i<=temp;i++) { if(temp%i==0) { int cnt=0; while(temp%i==0) { cnt++; temp/=i; } list.add(new Pair<Integer, Integer>(i,cnt)); } } if(temp!=1) { list.add(new Pair<Integer, Integer>(temp, 1)); } if(list.size()==1) { if(list.get(0).second<6) { System.out.println("NO"); } else { System.out.println("YES"); int num=list.get(0).first; System.out.println(num+" "+(num*num)+" "+ (n/(num*num*num))); } return; } int a=list.get(0).first; int b=list.get(1).first; int c= n/(a*b); if( a==c || b==c || c==1 ) { System.out.println("NO"); }else { System.out.println("YES"); System.out.println(a+" "+b+" "+c); } return; /*long n=fs.nextLong(); System.out.println((-(n-1))+" "+n); /*int n=fs.nextInt(); int arr[]=new int[n+1]; for(int i=2;i<=n;i++) { //System.out.println("#1"); if( arr[i]==0 ) { for(int j=2*i;j<=n;j+=i) { arr[j]++; //System.out.println("#2"); } } } int count=0; for(int i=2;i<=n;i++) { //System.out.println("#3"); if(arr[i]==2) { count++; } } System.out.println(count); /*int n = fs.nextInt(), x = fs.nextInt(); int[] a =new int[n]; for(int i=0;i<n;i++) { a[i]=fs.nextInt(); } int[] b = a.clone(); Arrays.sort(b); for (int i = 0; i < n; i++) { if (i < x && n - 1 - i < x && a[i] != b[i]) { System.out.println("NO"); return; } } System.out.println("YES"); /*int n=fs.nextInt(); int x=fs.nextInt(); ArrayList<Long> list=new ArrayList<Long>(); for(int i=0;i<n;i++) { list.add(fs.nextLong()); } ArrayList<Long> copy=(ArrayList<Long>)list.clone(); Collections.sort(copy); for(int i=0;i<n;i++) { if( copy.get(i)!=list.get(i) ) { if( i < x && n - 1 - i < x ) { System.out.println("NO"); return; } } } System.out.println("YES"); /*int n=fs.nextInt(); int h=fs.nextInt(); ArrayList<Integer> list=new ArrayList<Integer>(); for(int i=0;i<n;i++) { list.add(fs.nextInt()); } Collections.sort(list, Collections.reverseOrder()); int sum=list.get(0)+list.get(1); int count= (h/sum)*2 ; int left=h%sum; if( left<=list.get(0) && left!=0 ) { count++; }else if(left!=0){ count+=2; } System.out.println(count); /*int n=fs.nextInt(); PriorityQueue<Pair<Integer,Integer>> pq=new PriorityQueue<Solution.Pair<Integer,Integer>>( (o1,o2)-> o2.first.compareTo(o1.first) ); for(int i=1;i<=n;i++) { int num=fs.nextInt(); if(num==0) { continue; } pq.add(new Pair<Integer,Integer>(num, i)); } ArrayList<Pair<Integer,Integer>> ans=new ArrayList<Solution.Pair<Integer,Integer>>(); while(pq.size()>1) { Pair p1=pq.poll(); Pair p2=pq.poll(); ans.add(new Pair(p1.second, p2.second)); p1.first=(int)p1.first-1; p2.first=(int)p2.first-1; if(!p1.first.equals(0)) pq.add(p1); if(!p2.first.equals(0)) pq.add(p2); } System.out.println(ans.size()); for(Pair p:ans) { System.out.println(p.first+" "+p.second); } /*int r=fs.nextInt(); int col=fs.nextInt(); int k=fs.nextInt(); char arr[][]=new char[r][col]; for(int i=0;i<r;i++) { char ch[]=fs.next().toCharArray(); arr[i]=ch; } boolean visited[][]=new boolean[r][col]; for(boolean b[]:visited) { Arrays.fill(b, false); } for(int i=r-1;i>=1;i--) { for(int j=1;j<col-1;j++) { if( arr[i][j]=='*' ) { int len = 0; int a1 = i - 1, l1 = j - 1, l2 = j + 1; ArrayList<Pair<Integer, Integer>> v=new ArrayList<Solution.Pair<Integer,Integer>>(); while (a1 >= 0 && l1 >= 0 && l2 < col) { if (arr[a1][l1] == '*' && arr[a1][l2] == '*') { len++; v.add(new Pair(a1,l1)); v.add(new Pair(a1,l2)); l1--; l2++; a1--; continue; } break; } if (len < k && visited[i][j] == false) { System.out.println("NO"); return; } if (len >= k) { for (Pair p:v) { visited[(int)p.first][(int)p.second] = true; } } visited[i][j] = true; } } } for (int i = 0; i < r; i++) { for (int j = 0; j < col; j++) { if (arr[i][j] == '*' && !visited[i][j]) { System.out.println("NO"); return; } } } System.out.println("YES"); /*int n=fs.nextInt(); int arr[]=new int[n+1]; for(int i=1;i<=n;i++) { arr[i]=fs.nextInt(); } ArrayList<int[]> list=new ArrayList<int[]>(); int smallAns[]=new int[3]; for(int i=1;i<=n ;i++) { int minI=i; for(int j=i+1;j<=n;j++) { if(arr[minI]>arr[j]) { minI=j; } } if(minI==i) { continue; } //System.out.println(minI); int temp=arr[minI]; for(int j=minI;j>i;j--) { arr[j]=arr[j-1]; } arr[i]=temp; smallAns[0]=i; smallAns[1]=minI; smallAns[2]=minI-i; list.add(Arrays.copyOf(smallAns,smallAns.length)); } System.out.println(list.size()); for(int i=0;i<list.size();i++) { System.out.println(list.get(i)[0]+" "+list.get(i)[1]+" "+list.get(i)[2]); } /*System.out.println("sort"); for(int i=1;i<=n;i++) { System.out.print(arr[i]+" "); } System.out.println(); /*String s=fs.next(); int a=0; int b=0; int c=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)=='A') { a++; }else if( s.charAt(i)=='B' ) { b++; }else { c++; } } if( a+c==b ) { System.out.println("YES"); }else { System.out.println("NO"); } /*int w=fs.nextInt(); int h=fs.nextInt(); int x1=fs.nextInt(); int y1=fs.nextInt(); int x2=fs.nextInt(); int y2=fs.nextInt(); int tw=fs.nextInt(); int th=fs.nextInt(); if( !( ( w>= (Math.abs(x1-x2)+tw) || h>= (Math.abs(y1-y2)+th) ) || ( w>= ( Math.abs(x1-x2)+th ) || h>= ( Math.abs(y1-y2)+tw ) ) ) ) { System.out.println(-1); return ; } int ans=Integer.MAX_VALUE; if( y1>= th || h-y2>=th ) { ans=0; }else if( th+y2-y1 <= h ) { ans= th-y1; ans = Math.min(ans, th-( h-y2 ) ); } if( x1>=tw || w-x2 >= tw) { ans=0; }else if( tw+ x2-x1 <= w ) { ans=Math.min(ans, tw-x1 ); ans= Math.min(ans, tw-(w-x2) ); } if(ans== Integer.MAX_VALUE ) { System.out.println(-1); }else if( ans<0 ) { System.out.println(0); }else System.out.println(ans); /*int col=fs.nextInt(); int in[][]=new int[2][col]; for(int i=0;i<col;i++) { in[0][i]=fs.nextInt(); } for(int i=0;i<col;i++) { in[1][i]=fs.nextInt(); } int leftSum[][]=new int[2][col]; leftSum[0][0]=in[0][0]; leftSum[1][0]=in[1][0]; for(int i=1;i<col;i++) { leftSum[0][i]=in[0][i]+leftSum[0][i-1]; leftSum[1][i]=in[1][i]+leftSum[1][i-1]; } int rightSum[][]=new int[2][col]; rightSum[0][col-1]=in[0][col-1]; rightSum[1][col-1]=in[1][col-1]; for(int i=col-2;i>=0;i--) { rightSum[0][i]=rightSum[0][i+1] + in[0][i]; rightSum[1][i]=rightSum[1][i+1] + in[1][i]; } int minScore=Integer.MAX_VALUE; for(int i=0;i<col;i++) { int score1= ( i+1<col ) ? rightSum[0][i+1] : 0; int score2= (i-1>=0) ? leftSum[1][i-1] : 0; minScore= Math.min(minScore, Math.max(score1, score2)); } System.out.println(minScore); /*int n=fs.nextInt(); long input[]=new long[n]; for(int i=0;i<n;i++) { input[i]=fs.nextLong(); } int even=0; for(int i=0;i<n;i++) { if( (input[i]&1) ==0 ) { even++; } } int odd=n-even; if( Math.abs(odd-even) > 1 ) { System.out.println(-1); return ; } for(int i=0;i<n;i++) { input[i]= ( (input[i]&1)==1 )?1 :0; } int ans=Integer.MAX_VALUE; if( (n&1)==0 ) { int output[]=new int[n]; for(int i=0;i<n;i++) { output[i] = ( i&1 )==1 ? 1:0; } ArrayList<Integer> oddpos=new ArrayList<Integer>(); ArrayList<Integer> evenpos=new ArrayList<Integer>(); for(int i=0;i<n;i++) { if( input[i] != output[i] ) { if( (i&1)==1 ) oddpos.add(i); else evenpos.add(i); } } int smallAns=0; for(int i=0;i<oddpos.size();i++) { smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i)); } ans=Math.min(ans, smallAns); output=new int[n]; for(int i=0;i<n;i++) { output[i] = ( i&1 )==0 ? 1:0; } oddpos=new ArrayList<Integer>(); evenpos=new ArrayList<Integer>(); for(int i=0;i<n;i++) { if( input[i] != output[i] ) { if( (i&1)==1 ) oddpos.add(i); else evenpos.add(i); } } smallAns=0; for(int i=0;i<oddpos.size();i++) { smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i)); } ans=Math.min(ans, smallAns); }else if( odd> even ) { int output[]=new int[n]; for(int i=0;i<n;i++) { output[i] = ( i&1 )==0 ? 1:0; } ArrayList<Integer> oddpos=new ArrayList<Integer>(); ArrayList<Integer> evenpos=new ArrayList<Integer>(); for(int i=0;i<n;i++) { if( input[i] != output[i] ) { if( (i&1)==1 ) oddpos.add(i); else evenpos.add(i); } } int smallAns=0; for(int i=0;i<oddpos.size();i++) { smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i)); } ans=Math.min(ans, smallAns); }else { int output[]=new int[n]; for(int i=0;i<n;i++) { output[i] = ( i&1 )==1 ? 1:0; } ArrayList<Integer> oddpos=new ArrayList<Integer>(); ArrayList<Integer> evenpos=new ArrayList<Integer>(); for(int i=0;i<n;i++) { if( input[i] != output[i] ) { if( (i&1)==1 ) oddpos.add(i); else evenpos.add(i); } } int smallAns=0; for(int i=0;i<oddpos.size();i++) { smallAns+= Math.abs(oddpos.get(i)-evenpos.get(i)); } ans=Math.min(ans, smallAns); } System.out.println(ans); /* int len=fs.nextInt(); String row1=fs.next(); String row2=fs.next(); int prev=-1; int count=0; for(int i=0;i<len; i++) { if( row1.charAt(i) != row2.charAt(i) ) { count+=2; prev=-1; }else if ( row1.charAt(i)=='1') { if(prev==0) { count++; prev=-1; }else { prev=1; } }else { if(prev==1) { count+=2; prev=-1; }else { count++; prev=0; } } } System.out.println(count); /*int a=fs.nextInt(); int b=fs.nextInt(); int c=fs.nextInt(); int m=fs.nextInt(); int max=a+b+c-3; int arr[]= {a,b,c}; Arrays.parallelSort(arr); int min=arr[2]-arr[1]-arr[0]-1; if(m>=min && m<=max) { System.out.println("YES"); }else { System.out.println("No"); } */ /* int n=fs.nextInt(); long hero[]=new long[n]; long sum=0; for(int i=0;i<n;i++) { hero[i]=Long.parseLong(fs.next()); sum+=hero[i]; } //System.out.println(sum); Arrays.sort(hero); //for(long x: hero) //System.out.print(x+" "); //System.out.println(); int m=fs.nextInt(); while(m-->0) { long df=Long.parseLong(fs.next()); long at=Long.parseLong(fs.next()); long nextGrt=(long)Math.pow(10, 18); long nextSmall=-1; int index=uperBound(hero, df); //System.out.println(hero[index]); //System.out.println(index); if(index>=n) { nextSmall=hero[n-1]; }else if(index<=0 ) { nextGrt=hero[0]; }else { nextGrt=hero[index]; nextSmall=hero[index-1]; } /*for(int i=0;i<n;i++) { if(hero[i]>=df && hero[i]<nextGrt ) { nextGrt=hero[i]; } if(hero[i]<=df && hero[i]>nextSmall ) { nextSmall=hero[i]; } } //System.out.println(nextGrt +" : "+nextSmall); if( nextGrt!= (long) Math.pow(10, 18) && sum-nextGrt >=at ) { System.out.println(0); }else { if(nextGrt==(long)Math.pow(10, 18)) { long ans= df- nextSmall; ans+= ( at<= ( sum-nextSmall ) ) ? 0 : (at- sum+nextSmall); System.out.println(ans); } else if(nextSmall==-1) { long ans= ( at <= sum- nextGrt ) ? 0 : ( at- sum+nextGrt); System.out.println(ans); }else { long ans1=df- nextSmall; ans1+= ( at<= ( sum-nextSmall ) ) ? 0 : (at- sum+nextSmall); long ans2= ( at <= sum- nextGrt ) ? 0 : ( at- sum+nextGrt); System.out.println(Math.min(ans1, ans2)); } } } /*int n=fs.nextInt(); for(int i=1;i<=n;i++) { String open=""; String close=""; for(int j=1;j<=i;j++) { open+="("; close+=")"; } int j=0; while( j+2*i <= 2* n) { System.out.print(open); System.out.print(close); j=j+2*i; } //System.out.println(j); if(j<2*n) { while(j<2*n) { System.out.print("("); System.out.print(")"); j+=2; } } System.out.println(); } */ } static int computeXOR(int n) { // If n is a multiple of 4 if (n % 4 == 0) return n; // If n%4 gives remainder 1 if (n % 4 == 1) return 1; // If n%4 gives remainder 2 if (n % 4 == 2) return n + 1; // If n%4 gives remainder 3 return 0; } static boolean isSorted (int[] nums) { for (int i = 0; i < nums.length - 1; i++) { if (nums[i] > nums[i + 1]) { return false; } } return true; } static void firstOperation (int[] nums) { for (int i = 1; i < nums.length; i += 2) { int temp = nums[i]; nums[i] = nums[i - 1]; nums[i - 1] = temp; } } static void secondOperation (int[] nums) { int n = nums.length / 2; for (int i = 0; i < n; i++) { int temp = nums[i]; nums[i] = nums[i + n]; nums[i + n] = temp; } } private static long numOfDigits(long a) { long ans=0; while(a!=0) { ans++; a/=10; } return ans; } private static String reverse(String s) { String ans=""; for(int i=s.length()-1;i>=0;i--) { ans+=s.charAt(i); } return ans; } private static boolean isPalindrome(String s) { int i=0; int j=s.length()-1; while(i<j) { if(s.charAt(i)!=s.charAt(j)) { return false; } i++; j--; } return true; } static class FastScanner { BufferedReader br; StringTokenizer st ; FastScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } FastScanner(String file) { try { br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); st = new StringTokenizer(""); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("file not found"); e.printStackTrace(); } } 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()); } String readLine() throws IOException{ return br.readLine(); } } public static long[] sort(long arr[]){ List<Long> list = new ArrayList<>(); for(long n : arr){list.add(n);} Collections.sort(list); for(int i=0;i<arr.length;i++){ arr[i] = list.get(i); } return arr; } public static int[] sort(int arr[]){ List<Integer> list = new ArrayList<>(); for(int n : arr){list.add(n);} Collections.sort(list); for(int i=0;i<arr.length;i++){ arr[i] = list.get(i); } return arr; } // return the (index + 1) // where index is the pos of just smaller element // i.e count of elemets strictly less than num public static int justSmaller(long arr[],long num){ // System.out.println(num+"@"); int st = 0; int e = arr.length - 1; int ans = -1; while(st <= e){ int mid = (st + e)/2; if(arr[mid] >= num){ e = mid - 1; }else{ ans = mid; st = mid + 1; } } return ans + 1; } //return (index of just greater element) //count of elements smaller than or equal to num public static int justGreater(long arr[],long num){ int st = 0; int e = arr.length - 1; int ans = arr.length; while(st <= e){ int mid = (st + e)/2; if(arr[mid] <= num){ st = mid + 1; }else{ ans = mid; e = mid - 1; } } return ans; } public static boolean isPrime(int n) { for(int i=2;i<n;i++) { if(n%i==0) { return false; } } return true; } public static void println(Object obj){ System.out.println(obj.toString()); } public static void print(Object obj){ System.out.println(obj.toString()); } public static long gcd(long a,long b){ if(b == 0l){ return a; } return gcd(b,a%b); } public static int find(int parent[],int v){ if(parent[v] == v){ return v; } return parent[v] = find(parent, parent[v]); } public static List<Integer> sieve(){ List<Integer> prime = new ArrayList<>(); int arr[] = new int[100001]; Arrays.fill(arr,1); arr[1] = 0; arr[2] = 1; for(int i=2;i<=100000;i++){ if(arr[i] == 1){ prime.add(i); for(long j = (i*1l*i);j<100001;j+=i){ arr[(int)j] = 0; } } } return prime; } static boolean isPower(long n,long a){ long log = (long)(Math.log(n)/Math.log(a)); long power = (long)Math.pow(a,log); if(power == n){return true;} return false; } private static int mergeAndCount(int[] arr, int l,int m, int r) { // Left subarray int[] left = Arrays.copyOfRange(arr, l, m + 1); // Right subarray int[] right = Arrays.copyOfRange(arr, m + 1, r + 1); int i = 0, j = 0, k = l, swaps = 0; while (i < left.length && j < right.length) { if (left[i] <= right[j]) arr[k++] = left[i++]; else { arr[k++] = right[j++]; swaps += (m + 1) - (l + i); } } while (i < left.length) arr[k++] = left[i++]; while (j < right.length) arr[k++] = right[j++]; return swaps; } // Merge sort function private static int mergeSortAndCount(int[] arr, int l,int r) { // Keeps track of the inversion count at a // particular node of the recursion tree int count = 0; if (l < r) { int m = (l + r) / 2; // Total inversion count = left subarray count // + right subarray count + merge count // Left subarray count count += mergeSortAndCount(arr, l, m); // Right subarray count count += mergeSortAndCount(arr, m + 1, r); // Merge count count += mergeAndCount(arr, l, m, r); } return count; } static class Debug { //change to System.getProperty("ONLINE_JUDGE")==null; for CodeForces public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null; private static <T> String ts(T t) { if(t==null) { return "null"; } try { return ts((Iterable) t); }catch(ClassCastException e) { if(t instanceof int[]) { String s = Arrays.toString((int[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; } try { return ts((Object[]) t); }catch(ClassCastException e1) { return t.toString(); } } } private static <T> String ts(T[] arr) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: arr) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } private static <T> String ts(Iterable<T> iter) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: iter) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } public static void dbg(Object... o) throws Exception { if(LOCAL) { PrintStream ps = new PrintStream("src/Debug.txt"); System.setErr(ps); System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": ["); for(int i = 0; i<o.length; i++) { if(i!=0) { System.err.print(", "); } System.err.print(ts(o[i])); } System.err.println("]"); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
ac9113731b5446a8d25cacb7e0d79191
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.concurrent.LinkedBlockingDeque; import java.io.PrintStream; import java.io.PrintWriter; import java.io.DataInputStream; public class Solution { public static boolean Local(){ try{ return System.getenv("LOCAL_SYS")!=null; }catch(Exception e){ return false; } } public static boolean LOCAL; static class FastScanner { BufferedReader br; StringTokenizer st ; FastScanner(){ br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } FastScanner(String file) { try{ br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); st = new StringTokenizer(""); }catch(FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("file not found"); e.printStackTrace(); } } 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()); } String readLine() throws IOException{ return br.readLine(); } } static class Pair<T,X> { T first; X second; Pair(T first,X second){ this.first = first; this.second = second; } @Override public int hashCode(){ return Objects.hash(first,second); } @Override public boolean equals(Object obj){ return obj.hashCode() == this.hashCode(); } } static PrintStream debug = null; static long mod = (long)(Math.pow(10,9) + 7); public static void main(String[] args) throws Exception { FastScanner s = new FastScanner(); LOCAL = Local(); //PrintWriter pw = new PrintWriter(System.out); if(LOCAL){ s = new FastScanner("src/input.txt"); PrintStream o = new PrintStream("src/sampleout.txt"); debug = new PrintStream("src/debug.txt"); System.setOut(o); // pw = new PrintWriter(o); } long mod = 1000000007; int tcr = s.nextInt(); StringBuilder sb = new StringBuilder(); for(int tc=0;tc<tcr;tc++){ long n = s.nextLong(); long k = s.nextLong(); if(n == 1l){sb.append("0\n");continue;} long hour = 0l; // if(k >= (n-1l)){ // sb.append(hour+"\n"); // continue; // } long done = 1l; while(done < n && done <= k){ done += (done); hour+=1l; } // println(done+" "); long rem = n - done; // println(rem+"--"); if(rem <= 0l){ sb.append(hour+"\n"); continue; } //println((long)Math.ceil(rem / (k))); hour += (long)(rem / (k)); if(rem % k != 0l){ hour++; } sb.append(hour+"\n"); } print(sb.toString()); } public static int justGreater(long arr[],long num,int st,long mag_dec){ // int st = 0; int e = arr.length - 1; int ans = arr.length; while(st <= e){ int mid = (st + e)/2; if((arr[mid] - mag_dec) <= num){ st = mid + 1; }else{ ans = mid; e = mid - 1; } } return ans; } public static List<int[]> print_prime_factors(int n){ List<int[]> list = new ArrayList<>(); for(int i=2;i<=(int)(Math.sqrt(n));i++){ if(n % i == 0){ int cnt = 0; while( (n % i) == 0){ n = n/i; cnt++; } list.add(new int[]{i,cnt}); } } if(n!=1){ list.add(new int[]{n,1}); } return list; } public static boolean inRange(int r1,int r2,int val){ return ((val >= r1) && (val <= r2)); } static int len(long num){ return Long.toString(num).length(); } static long mulmod(long a, long b,long mod) { long ans = 0l; while(b > 0){ long curr = (b & 1l); if(curr == 1l){ ans = ((ans % mod) + a) % mod; } a = (a + a) % mod; b = b >> 1; } return ans; } public static void dbg(PrintStream ps,Object... o) throws Exception{ if(ps == null){ return; } Debug.dbg(ps,o); } public static long modpow(long num,long pow,long mod){ long val = num; long ans = 1l; while(pow > 0l){ long bit = pow & 1l; if(bit == 1){ ans = (ans * (val%mod))%mod; } val = (val * val) % mod; pow = pow >> 1; } return ans; } public static char get(int n){ return (char)('a' + n); } public static long[] sort(long arr[]){ List<Long> list = new ArrayList<>(); for(long n : arr){list.add(n);} Collections.sort(list); for(int i=0;i<arr.length;i++){ arr[i] = list.get(i); } return arr; } public static int[] sort(int arr[]){ List<Integer> list = new ArrayList<>(); for(int n : arr){list.add(n);} Collections.sort(list); for(int i=0;i<arr.length;i++){ arr[i] = list.get(i); } return arr; } // return the (index + 1) // where index is the pos of just smaller element // i.e count of elemets strictly less than num public static int justSmaller(long arr[],long num){ // System.out.println(num+"@"); int st = 0; int e = arr.length - 1; int ans = -1; while(st <= e){ int mid = (st + e)/2; if(arr[mid] >= num){ e = mid - 1; }else{ ans = mid; st = mid + 1; } } return ans + 1; } public static int justSmaller(int arr[],int num){ // System.out.println(num+"@"); int st = 0; int e = arr.length - 1; int ans = -1; while(st <= e){ int mid = (st + e)/2; if(arr[mid] >= num){ e = mid - 1; }else{ ans = mid; st = mid + 1; } } return ans + 1; } //return (index of just greater element) //count of elements smaller than or equal to num public static int justGreater(long arr[],long num){ int st = 0; int e = arr.length - 1; int ans = arr.length; while(st <= e){ int mid = (st + e)/2; if(arr[mid] <= num){ st = mid + 1; }else{ ans = mid; e = mid - 1; } } return ans; } public static int justGreater(int arr[],int num){ int st = 0; int e = arr.length - 1; int ans = arr.length; while(st <= e){ int mid = (st + e)/2; if(arr[mid] <= num){ st = mid + 1; }else{ ans = mid; e = mid - 1; } } return ans; } public static void println(Object obj){ System.out.println(obj.toString()); } public static void print(Object obj){ System.out.print(obj.toString()); } public static int gcd(int a,int b){ if(b == 0){return a;} return gcd(b,a%b); } public static long gcd(long a,long b){ if(b == 0l){ return a; } return gcd(b,a%b); } public static int find(int parent[],int v){ if(parent[v] == v){ return v; } return parent[v] = find(parent, parent[v]); } public static List<Integer> sieve(){ List<Integer> prime = new ArrayList<>(); int arr[] = new int[100001]; Arrays.fill(arr,1); arr[1] = 0; arr[2] = 1; for(int i=2;i<=100000;i++){ if(arr[i] == 1){ prime.add(i); for(long j = (i*1l*i);j<100001;j+=i){ arr[(int)j] = 0; } } } return prime; } static boolean isPower(long n,long a){ long log = (long)(Math.log(n)/Math.log(a)); long power = (long)Math.pow(a,log); if(power == n){return true;} return false; } private static int mergeAndCount(int[] arr, int l,int m, int r) { // Left subarray int[] left = Arrays.copyOfRange(arr, l, m + 1); // Right subarray int[] right = Arrays.copyOfRange(arr, m + 1, r + 1); int i = 0, j = 0, k = l, swaps = 0; while (i < left.length && j < right.length) { if (left[i] <= right[j]) arr[k++] = left[i++]; else { arr[k++] = right[j++]; swaps += (m + 1) - (l + i); } } while (i < left.length) arr[k++] = left[i++]; while (j < right.length) arr[k++] = right[j++]; return swaps; } // Merge sort function private static int mergeSortAndCount(int[] arr, int l,int r) { // Keeps track of the inversion count at a // particular node of the recursion tree int count = 0; if (l < r) { int m = (l + r) / 2; // Total inversion count = left subarray count // + right subarray count + merge count // Left subarray count count += mergeSortAndCount(arr, l, m); // Right subarray count count += mergeSortAndCount(arr, m + 1, r); // Merge count count += mergeAndCount(arr, l, m, r); } return count; } static class Debug{ //change to System.getProperty("ONLINE_JUDGE")==null; for CodeForces public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null; private static <T> String ts(T t) { if(t==null) { return "null"; } try { return ts((Iterable) t); }catch(ClassCastException e) { if(t instanceof int[]) { String s = Arrays.toString((int[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return "{"+s.substring(1, s.length()-1)+"}\n"; } try { return ts((Object[]) t); }catch(ClassCastException e1) { return t.toString(); } } } private static <T> String ts(T[] arr) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: arr) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}"); return ret.toString(); } private static <T> String ts(Iterable<T> iter) { StringBuilder ret = new StringBuilder(); ret.append("{"); boolean first = true; for(T t: iter) { if(!first) { ret.append(", "); } first = false; ret.append(ts(t)); } ret.append("}\n"); return ret.toString(); } public static void dbg(PrintStream ps,Object... o) throws Exception { if(LOCAL) { System.setErr(ps); System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [\n"); for(int i = 0; i<o.length; i++) { if(i!=0) { System.err.print(", "); } System.err.print(ts(o[i])); } System.err.println("]"); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
33b5dbe2da2dd6546988fea11a935db3
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner Sc=new Scanner(System.in); int T=Sc.nextInt(); for(int i=0;i<T;i++) { long n=Sc.nextLong(); long k=Sc.nextLong(); n--; long c=0;int flag=0; while(n>0) { long ans=(long)Math.pow(2,c++); if(ans<=k) n=n-ans; else { c--; break; } } if(n>0) { System.out.println(c+((n/k)+(n%k==0?0:1))); } else System.out.println(c); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
5fcd558bbbafcf68f53090a3c2beb45d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.math.BigInteger; import java.util.Scanner; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; public class cfContest1606 { public static void main(String args[]) throws IOException { Reader scan = new Reader(); int t = scan.nextInt(); StringBuilder sb = new StringBuilder(); while (t-- > 0) { long n = scan.nextLong() - 1; long k = scan.nextLong(); long p = 0; long res = 0; while (true) { long r = (long) Math.pow(2, p); if (r <= k && n > 0) { n -= r; ++res; } else { break; } ++p; } n = Math.max(n, 0); BigInteger f = new BigInteger(String.valueOf(n)); BigInteger r = new BigInteger(String.valueOf(k)); BigInteger b = f.remainder(r); BigInteger re = f.divide(r).add(new BigInteger(String.valueOf(res))); if (b.compareTo(new BigInteger("0")) != 0) { re = re.add(new BigInteger("1")); } sb.append(re + "\n"); } System.out.println(sb); } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) { return; } din.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
d072dc65128f87ad7fe835c1dba9899d
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; // System.out is a PrintStream import java.util.InputMismatchException; public class B { private static int MOD = (int)1e9 + 7, mod = 99_82_44_353; private static double PI = 3.14159265358979323846; public static void main(String[] args) throws IOException { FasterScanner scn = new FasterScanner(); PrintWriter out = new PrintWriter(System.out); for (int tc = scn.nextInt(); tc > 0; tc--) { long N = scn.nextLong(), K = scn.nextLong() , itr = 1, count = 0; for (itr = 1L; itr <= K && itr < N; count++) { itr <<= 1L; } if (itr < N) { count += (0L + N - itr + K - 1L) / K; } out.println(count); } out.close(); } /* ------------------- Sorting ------------------- */ private static void ruffleSort(int[] arr) { // int N = arr.length; // Random rand = new Random(); // for (int i = 0; i < N; i++) { // int oi = rand.nextInt(N), temp = arr[i]; // arr[i] = arr[oi]; // arr[oi] = temp; // } // Arrays.sort(arr); } /* ------------------- Sorting ------------------- */ private static boolean isPalindrome(String str) { for (int i = 0, j = str.length() - 1; i < j; i++, j--) { if (str.charAt(i) != str.charAt(j)) { return false; } } return true; } private static boolean isPalindrome(char[] str) { for (int i = 0, j = str.length - 1; i < j; i++, j--) { if (str[i] != str[j]) { return false; } } return true; } /* ------------------- Pair class ------------------- */ private static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o) { return this.x == o.x ? this.y - o.y : this.x - o.x; } } /* ------------------- HCF and LCM ------------------- */ private static int gcd(int num1, int num2) { int temp = 0; while (num2 != 0) { temp = num1; num1 = num2; num2 = temp % num2; } return num1; } private static int lcm(int num1, int num2) { return (int)((1L * num1 * num2) / gcd(num1, num2)); } /* ------------------- primes and prime factorization ------------------- */ private static boolean[] seive(int N) { // true means not prime, false means is a prime number :) boolean[] notPrimes = new boolean[N + 1]; notPrimes[0] = notPrimes[1] = true; for (int i = 2; i * i <= N; i++) { if (notPrimes[i]) continue; for (int j = i * i; j <= N; j += i) { notPrimes[j] = true; } } return notPrimes; } /* private static TreeMap<Integer, Integer> primeFactors(long N) { TreeMap<Integer, Integer> primeFact = new TreeMap<>(); for (int i = 2; i <= Math.sqrt(N); i++) { int count = 0; while (N % i == 0) { N /= i; count++; } if (count != 0) { primeFact.put(i, count); } } if (N != 1) { primeFact.put((int)N, 1); } return primeFact; } */ /* ------------------- Binary Search ------------------- */ private static long factorial(int N) { long ans = 1L; for (int i = 2; i <= N; i++) { ans *= i; } return ans; } private static long[] factorialDP(int N) { long[] factDP = new long[N + 1]; factDP[0] = factDP[1] = 1; for (int i = 2; i <= N; i++) { factDP[i] = factDP[i - 1] * i; } return factDP; } private static long factorialMod(int N, int mod) { long ans = 1L; for (int i = 2; i <= N; i++) { ans = ((ans % mod) * (i % mod)) % mod; } return ans; } /* ------------------- Binary Search ------------------- */ private static int floorSearch(int[] arr, int st, int ed, int tar) { int ans = -1; while (st <= ed) { int mid = ((ed - st) >> 1) + st; if (arr[mid] <= tar) { ans = mid; st = mid + 1; } else { ed = mid - 1; } } return ans; } private static int ceilingSearch(int[] arr, int st, int ed, int tar) { int ans = -1; while (st <= ed) { int mid = ((ed - st) >> 1) + st; if (arr[mid] < tar) { st = mid + 1; } else { ans = mid; ed = mid - 1; } } return ans; } /* ------------------- Power Function ------------------- */ public static long pow(long x, long y) { long res = 1; while (y > 0) { if ((y & 1) != 0) { res = (res * x); y--; } x = (x * x); y >>= 1; } return res; } public static long powMod(long x, long y, int mod) { long res = 1; while (y > 0) { if ((y & 1) != 0) { res = (res * x) % mod; y--; } x = (x * x) % mod; y >>= 1; } return res % mod; } /* ------------------- Disjoint Set(Union and Find) ------------------- */ private static class DSU { public int[] parent, rank; DSU(int N) { parent = new int[N]; rank = new int[N]; for (int i = 0; i < N; i++) { parent[i] = i; rank[i] = 1; } } public int find(int a) { if (parent[a] == a) { return a; } return parent[a] = find(parent[a]); } public boolean union(int a, int b) { int parA = find(a), parB = find(b); if (parA == parB) return false; if (rank[parA] > rank[parB]) { parent[parB] = parA; } else if (rank[parA] < rank[parB]) { parent[parA] = parB; } else { parent[parA] = parB; rank[parB]++; } return true; } } /* ------------------- Scanner class for input ------------------- */ private static class FasterScanner { private InputStream stream; private byte[] buffer = new byte[1024]; private int curChar, numChars; private SpaceCharFilter filter; public FasterScanner() { // default this.stream = System.in; } public FasterScanner(InputStream stream) { this.stream = stream; } private int readChar() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buffer); } catch (IOException e) { throw new InputMismatchException(e.getMessage()); } if (numChars <= 0) { return -1; } } return buffer[curChar++]; } private boolean isWhiteSpace(int c) { if (filter != null) { return filter.isWhiteSpace(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isNewLine(int ch) { if (filter != null) { return filter.isNewLine(ch); } return ch == '\r' || ch == '\n' || ch == -1; } public char nextChar() { int ch = readChar(); char res = '\0'; while (isWhiteSpace(ch)) { ch = readChar(); } do { res = (char)ch; ch = readChar(); } while (!isWhiteSpace(ch)); return res; } public String next() { int ch = readChar(); StringBuilder res = new StringBuilder(); while (isWhiteSpace(ch)) { ch = readChar(); } do { res.appendCodePoint(ch); ch = readChar(); } while (!isWhiteSpace(ch)); return res.toString(); } public String nextLine() { int ch = readChar(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(ch); ch = readChar(); } while (!isNewLine(ch)); return res.toString(); } public int nextInt() { int ch = -1, sgn = 1, res = 0; do { ch = readChar(); } while (isWhiteSpace(ch)); if (ch == '-') { sgn = -1; ch = readChar(); } do { if (ch < '0' || ch > '9') { throw new InputMismatchException("not a number"); } res = (res * 10) + (ch - '0'); ch = readChar(); } while (!isWhiteSpace(ch)); return res * sgn; } public long nextLong() { int ch = -1, sgn = 1; long res = 0L; do { ch = readChar(); } while (isWhiteSpace(ch)); if (ch == '-') { sgn = -1; ch = readChar(); } do { if (ch < '0' || ch > '9') { throw new InputMismatchException("not a number"); } res = (10L * res) + (ch - '0'); ch = readChar(); } while (!isWhiteSpace(ch)); return 1L * res * sgn; } public double nextDouble() { return Double.parseDouble(next()); } /* for custom delimiters */ public interface SpaceCharFilter { public boolean isWhiteSpace(int ch); public boolean isNewLine(int ch); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 8
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
2d69b8ea4311c9393871df688e7953b9
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class test { private static long solve(long n, long m) { long hrs = 0; long count = 1; while (count < n && count <= m) { count *= 2; hrs++; } if (count >= n) { return hrs; } // double d = n - count; // double m1 = m; // hrs += Math.ceil(d / m); hrs += (n - count + m - 1) / m; // something else return hrs; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0) { long n = sc.nextLong(); long m = sc.nextLong(); System.out.println(solve(n, m)); t--; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
4d5e966a91b9d487c135ce2cea7757ae
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class test { private static long solve(long n, long m) { long hrs = 0; long count = 1; while (count < n && count <= m) { count *= 2; hrs++; } if (count >= n) { return hrs; } // double d = n - count; // double m1 = m; // hrs += Math.ceil(d / m); hrs += (n - count + m - 1) / m; return hrs; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t > 0) { long n = sc.nextLong(); long m = sc.nextLong(); System.out.println(solve(n, m)); t--; } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
9a1665bb43c9771db3b6003db17a3e76
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*;; public class test { private static long solve(long n, long m) throws IOException { long hrs = 0; long count = 1; while (count < n && count <= m) { count *= 2; hrs++; } if (count >= n) { return hrs; } double d = n - count; double m1 = m; hrs += (n - count + m - 1) / m; // hrs += Math.ceil(d / m1); //999999999999999999 //1000000000000000000 return hrs; } public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); while (t > 0) { long n = in.nextLong(); long m = in.nextLong(); System.out.println(solve(n, m)); t--; } // for (int i = 0; i < t; i++) { // solve(); // } out.flush(); in.close(); out.close(); } private static int gcd(int a, int b) { if (a == 0 || b == 0) return 0; while (b != 0) { int tmp; tmp = a % b; a = b; b = tmp; } return a; } static final long mod = 1000000007; static long pow_mod(long a, long b) { long result = 1; while (b != 0) { if ((b & 1) != 0) result = (result * a) % mod; a = (a * a) % mod; b >>= 1; } return result; } private static long multiplied_mod(long... longs) { long ans = 1; for (long now : longs) { ans = (ans * now) % mod; } return ans; } @SuppressWarnings("FieldCanBeLocal") private static Reader in; private static PrintWriter out; private static int[] read_int_array(int len) throws IOException { int[] a = new int[len]; for (int i = 0; i < len; i++) { a[i] = in.nextInt(); } return a; } private static long[] read_long_array(int len) throws IOException { long[] a = new long[len]; for (int i = 0; i < len; i++) { a[i] = in.nextLong(); } return a; } private static void print_array(int[] array) { for (int now : array) { out.print(now); out.print(' '); } out.println(); } private static void print_array(long[] array) { for (long now : array) { out.print(now); out.print(' '); } out.println(); } static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() { din = new DataInputStream(System.in); 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); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
0c665888a3aec102ce9e201414574232
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
// Question -> https://codeforces.com/problemset/problem/1606/B import java.io.*; // import java.util.*; public class LiveQes3 { public static void solve() throws IOException { long computers = in.nextLong(); long cables = in.nextLong(); long ans = 0; long nthTermOfGP = 1; while (nthTermOfGP < computers && nthTermOfGP < cables) { nthTermOfGP *= 2; ans++; } if (nthTermOfGP < computers) { ans += (computers - nthTermOfGP + cables - 1) / cables; } System.out.println(ans); } public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int i = 0; i < t; i++) { solve(); } out.flush(); in.close(); out.close(); } private static int gcd(int a, int b) { if (a == 0 || b == 0) return 0; while (b != 0) { int tmp; tmp = a % b; a = b; b = tmp; } return a; } static final long mod = 1000000007; static long pow_mod(long a, long b) { long result = 1; while (b != 0) { if ((b & 1) != 0) result = (result * a) % mod; a = (a * a) % mod; b >>= 1; } return result; } private static long multiplied_mod(long... longs) { long ans = 1; for (long now : longs) { ans = (ans * now) % mod; } return ans; } @SuppressWarnings("FieldCanBeLocal") private static Reader in; private static PrintWriter out; private static int[] read_int_array(int len) throws IOException { int[] a = new int[len]; for (int i = 0; i < len; i++) { a[i] = in.nextInt(); } return a; } private static long[] read_long_array(int len) throws IOException { long[] a = new long[len]; for (int i = 0; i < len; i++) { a[i] = in.nextLong(); } return a; } private static void print_array(int[] array) { for (int now : array) { out.print(now); out.print(' '); } out.println(); } private static void print_array(long[] array) { for (long now : array) { out.print(now); out.print(' '); } out.println(); } static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() { din = new DataInputStream(System.in); 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); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
b0fb2295089f2eeebf51dc772800fb43
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.Scanner; public class Update_Files { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int t = sc.nextInt(); while(t>0){ long n= sc.nextLong(); long m = sc.nextLong(); System.out.println(solve(n,m)); t--; } } private static long solve(long n, long m) { long hrs=0; long count=1; if(m==1) return n-1; while(count<n && count<=m){ count*=2; hrs++; } if(count>=n){ return hrs; } double d = n-count; double m1=m; if((n-count)%m==0) hrs+=(n-count)/m; else { hrs+=(n-count)/m; hrs+=1; } return hrs; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
24638be98b9a57bb19d9b82e9d7e8547
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class A1{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st; static final long mod=1000000007; public static void Solve() throws IOException{ st=new StringTokenizer(br.readLine()); long n=Long.parseLong(st.nextToken()); long k=Long.parseLong(st.nextToken()); if(k==1){ bw.write(n-1+"\n");return ; } long c=1,ans=0; while(c<k){ c*=2;ans++; } if(c<n) ans+=((n-c+k-1)/k); bw.write(ans+"\n"); } /** Main Method**/ public static void main(String[] YDSV) throws IOException{ //int t=1; int t=Integer.parseInt(br.readLine()); while(t-->0) Solve(); bw.flush(); } /** Helpers**/ private static char[] getStr()throws IOException{ return br.readLine().toCharArray(); } private static int Gcd(int a,int b){ if(b==0) return a; return Gcd(b,a%b); } private static long Gcd(long a,long b){ if(b==0) return a; return Gcd(b,a%b); } private static int[] getArrIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); int[] ar=new int[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static Integer[] getArrInP(int n) throws IOException{ st=new StringTokenizer(br.readLine()); Integer[] ar=new Integer[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static long[] getArrLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); long[] ar=new long[n]; for(int i=0;i<n;i++) ar[i]=Long.parseLong(st.nextToken()); return ar; } private static List<Integer> getListIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Integer> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Integer.parseInt(st.nextToken())); return al; } private static List<Long> getListLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Long> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Long.parseLong(st.nextToken())); return al; } private static long pow_mod(long a,long b) { long result=1; while(b!=0){ if((b&1)!=0) result=(result*a)%mod; a=(a*a)%mod; b>>=1; } return result; } private static int lower_bound(int a[],int x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r+1; } private static long lower_bound(long a[],long x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r+1; } private static int upper_bound(int a[],int x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } private static long upper_bound(long a[],long x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } private static boolean Sqrt(int x){ int a=(int)Math.sqrt(x); return a*a==x; } private static boolean Sqrt(long x){ long a=(long)Math.sqrt(x); return a*a==x; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
e4189cdf4d2bcd6d3e2cbac40bf60d7e
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class Brocoders{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st; static final long mod=1000000007; public static void Solve() throws IOException{ st=new StringTokenizer(br.readLine()); long n=Long.parseLong(st.nextToken()); long k=Long.parseLong(st.nextToken()); if(k==1){ bw.write(n-1+"\n");return ; } long c=1,ans=0; while(c<k){ c*=2;ans++; } if(c<n) ans+=((n-c+k-1)/k); bw.write(ans+"\n"); } /** Main Method**/ public static void main(String[] YDSV) throws IOException{ //int t=1; int t=Integer.parseInt(br.readLine()); while(t-->0) Solve(); bw.flush(); } /** Helpers**/ private static char[] getStr()throws IOException{ return br.readLine().toCharArray(); } private static int Gcd(int a,int b){ if(b==0) return a; return Gcd(b,a%b); } private static long Gcd(long a,long b){ if(b==0) return a; return Gcd(b,a%b); } private static int[] getArrIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); int[] ar=new int[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static Integer[] getArrInP(int n) throws IOException{ st=new StringTokenizer(br.readLine()); Integer[] ar=new Integer[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static long[] getArrLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); long[] ar=new long[n]; for(int i=0;i<n;i++) ar[i]=Long.parseLong(st.nextToken()); return ar; } private static List<Integer> getListIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Integer> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Integer.parseInt(st.nextToken())); return al; } private static List<Long> getListLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Long> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Long.parseLong(st.nextToken())); return al; } private static long pow_mod(long a,long b) { long result=1; while(b!=0){ if((b&1)!=0) result=(result*a)%mod; a=(a*a)%mod; b>>=1; } return result; } private static int lower_bound(int a[],int x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r+1; } private static long lower_bound(long a[],long x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r+1; } private static int upper_bound(int a[],int x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } private static long upper_bound(long a[],long x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } private static boolean Sqrt(int x){ int a=(int)Math.sqrt(x); return a*a==x; } private static boolean Sqrt(long x){ long a=(long)Math.sqrt(x); return a*a==x; } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
95283658eb42c9ae2b4c12a3534341c4
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); for(int t = 0; t<test; ++t){ long n = sc.nextLong(); long k = sc.nextLong(); long ans = 0; long pc = 1; while(pc < n){ ans++; pc += Math.min(pc, k); if(pc >= k){ ans += (n - pc + (k-1))/k; pc = n; } } System.out.println(ans); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
39a98c6caae7ef7f6f7bf894d3d47afa
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
// package com.adhok; 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){ long computers = sc.nextLong(); long cables = sc.nextLong(); long computersDataTrans = 1; long hours=0; while(computersDataTrans<=cables && computersDataTrans<computers){ computersDataTrans = computersDataTrans * 2; hours++; } if(computersDataTrans >= computers){ System.out.println(hours); continue; } //AP long APhours = ((computers - computersDataTrans) + (cables-1)) / cables; System.out.println((hours+APhours)); // 4 3 20 // 20 - 4 = 16 // 16/3 = 5.3 ~ 5 + 1 = 6 hours // 1 2 3 + 6 = 9 hours } } public static long givesum(int k,HashSet<Integer> set,int n,int max){ int s = 1; int e = 2*n; long sum=0; while(k>0 && s<=e){ while(set.contains(s)){ s++; } while(set.contains(e)){ e--; } int d1= max - s; int d2= max - e; if(d1<0){ max=Math.max(max,e); d2=0; } if(d1>d2){ max=Math.max(max,s); set.add(s); sum+= d1; s++; } else{ max=Math.max(max,e); sum+=d2; set.add(e); e--; } k--; } return sum; } private static long f(int n, int m, int mod, int red, int green,Integer [][][][]dp,boolean redNow, boolean greenNow) { if(n == 0 && m==0){ // System.out.println( "red :" + red+ " green :"+ green); if(red == green){ return 1; } return 0; } if(n<0 || m<0){ return 0; } // if(dp[n][m][redNow ? 1:0][greenNow ? 1:0]!=null){ // return dp[n][m][redNow ? 1:0][greenNow ? 1:0]; // } long ti1 = f(n-1,m,mod,red+1,green,dp,true,false); long ti2 = f(n-1,m,mod,red,green+1,dp,false,true); long ti3 = f(n,m-1,mod,red+1,green,dp,true,false); long ti4 = f(n,m-1,mod,red,green+1,dp,false,true); return dp[n][m][redNow ? 1:0][greenNow ? 1:0] = (int)(ti1+ ti2+ ti3+ ti4) % mod; } public long binaryExponential(int a,int b,int mod){ long ans=1; while(b>0){ if((b&1)>0) ans = (ans * a)%mod; a = (a * a)%mod; b/=2; } return (ans%mod); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
1f58db8810a6a0399edcf04bd5e8f407
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.util.*; import java.util.function.*; import java.io.*; // you can compare with output.txt and expected out public class RoundEdu116B { MyPrintWriter out; MyScanner in; // final static long FIXED_RANDOM; // static { // FIXED_RANDOM = System.currentTimeMillis(); // } final static String IMPOSSIBLE = "IMPOSSIBLE"; final static String POSSIBLE = "POSSIBLE"; final static String YES = "YES"; final static String NO = "NO"; private void initIO(boolean isFileIO) { if (System.getProperty("ONLINE_JUDGE") == null && isFileIO) { try{ in = new MyScanner(new FileInputStream("input.txt")); out = new MyPrintWriter(new FileOutputStream("output.txt")); } catch(FileNotFoundException e){ e.printStackTrace(); } } else{ in = new MyScanner(System.in); out = new MyPrintWriter(new BufferedOutputStream(System.out)); } } public static void main(String[] args){ // Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); // the code for the deep recursion (more than 100k or 3~400k or so) // Thread t = new Thread(null, new RoundEdu130F(), "threadName", 1<<28); // t.start(); // t.join(); RoundEdu116B sol = new RoundEdu116B(); sol.run(); } private void run() { boolean isDebug = false; boolean isFileIO = true; boolean hasMultipleTests = true; initIO(isFileIO); int t = hasMultipleTests? in.nextInt() : 1; for (int i = 1; i <= t; ++i) { if(isDebug){ out.printf("Test %d\n", i); } getInput(); solve(); printOutput(); } in.close(); out.close(); } // use suitable one between matrix(2, n), matrix(n, 2), transposedMatrix(2, n) for graph edges, pairs, ... long n, k; void getInput() { n = in.nextLong(); k = in.nextLong(); } void printOutput() { out.printlnAns(ans); } long ans; void solve(){ ans = 0; n--; for(long m = 1; m <=k && n > 0; m *= 2) { n -= m; ans++; } if(n > 0) ans += (n+k-1)/k; } // Optional<T> solve() // return Optional.empty(); static class Pair implements Comparable<Pair>{ final static long FIXED_RANDOM = System.currentTimeMillis(); int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } @Override public int hashCode() { // http://xorshift.di.unimi.it/splitmix64.c long x = first; x <<= 32; x += second; x += FIXED_RANDOM; x += 0x9e3779b97f4a7c15l; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9l; x = (x ^ (x >> 27)) * 0x94d049bb133111ebl; return (int)(x ^ (x >> 31)); } @Override public boolean equals(Object obj) { // if (this == obj) // return true; // if (obj == null) // return false; // if (getClass() != obj.getClass()) // return false; Pair other = (Pair) obj; return first == other.first && second == other.second; } @Override public String toString() { return "[" + first + "," + second + "]"; } @Override public int compareTo(Pair o) { int cmp = Integer.compare(first, o.first); return cmp != 0? cmp: Integer.compare(second, o.second); } } public static class MyScanner { BufferedReader br; StringTokenizer st; // 32768? public MyScanner(InputStream is, int bufferSize) { br = new BufferedReader(new InputStreamReader(is), bufferSize); } public MyScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); // br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } public void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[][] nextMatrix(int n, int m) { return nextMatrix(n, m, 0); } int[][] nextMatrix(int n, int m, int offset) { int[][] mat = new int[n][m]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[i][j] = nextInt()+offset; } } return mat; } int[][] nextTransposedMatrix(int n, int m){ return nextTransposedMatrix(n, m, 0); } int[][] nextTransposedMatrix(int n, int m, int offset){ int[][] mat = new int[m][n]; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { mat[j][i] = nextInt()+offset; } } return mat; } int[] nextIntArray(int len) { return nextIntArray(len, 0); } int[] nextIntArray(int len, int offset){ int[] a = new int[len]; for(int j=0; j<len; j++) a[j] = nextInt()+offset; return a; } long[] nextLongArray(int len) { return nextLongArray(len, 0); } long[] nextLongArray(int len, int offset){ long[] a = new long[len]; for(int j=0; j<len; j++) a[j] = nextLong()+offset; return a; } String[] nextStringArray(int len) { String[] s = new String[len]; for(int i=0; i<len; i++) s[i] = next(); return s; } } public static class MyPrintWriter extends PrintWriter{ public MyPrintWriter(OutputStream os) { super(os); } // public <T> void printlnAns(Optional<T> ans) { // if(ans.isEmpty()) // println(-1); // else // printlnAns(ans.get()); // } public void printlnAns(OptionalInt ans) { println(ans.orElse(-1)); } public void printlnAns(long ans) { println(ans); } public void printlnAns(int ans) { println(ans); } public void printlnAns(boolean ans) { if(ans) println(YES); else println(NO); } public void printAns(long[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(long[] arr){ printAns(arr); println(); } public void printAns(int[] arr){ if(arr != null && arr.length > 0){ print(arr[0]); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]); } } } public void printlnAns(int[] arr){ printAns(arr); println(); } public <T> void printAns(ArrayList<T> arr){ if(arr != null && arr.size() > 0){ print(arr.get(0)); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)); } } } public <T> void printlnAns(ArrayList<T> arr){ printAns(arr); println(); } public void printAns(int[] arr, int add){ if(arr != null && arr.length > 0){ print(arr[0]+add); for(int i=1; i<arr.length; i++){ print(" "); print(arr[i]+add); } } } public void printlnAns(int[] arr, int add){ printAns(arr, add); println(); } public void printAns(ArrayList<Integer> arr, int add) { if(arr != null && arr.size() > 0){ print(arr.get(0)+add); for(int i=1; i<arr.size(); i++){ print(" "); print(arr.get(i)+add); } } } public void printlnAns(ArrayList<Integer> arr, int add){ printAns(arr, add); println(); } public void printlnAnsSplit(long[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public void printlnAnsSplit(int[] arr, int split){ if(arr != null){ for(int i=0; i<arr.length; i+=split){ print(arr[i]); for(int j=i+1; j<i+split; j++){ print(" "); print(arr[j]); } println(); } } } public <T> void printlnAnsSplit(ArrayList<T> arr, int split){ if(arr != null && !arr.isEmpty()){ for(int i=0; i<arr.size(); i+=split){ print(arr.get(i)); for(int j=i+1; j<i+split; j++){ print(" "); print(arr.get(j)); } println(); } } } } static private void permutateAndSort(long[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); long temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private void permutateAndSort(int[] a) { int n = a.length; Random R = new Random(System.currentTimeMillis()); for(int i=0; i<n; i++) { int t = R.nextInt(n-i); int temp = a[n-1-i]; a[n-1-i] = a[t]; a[t] = temp; } Arrays.sort(a); } static private int[][] constructChildren(int n, int[] parent, int parentRoot){ int[][] childrens = new int[n][]; int[] numChildren = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) numChildren[parent[i]]++; } for(int i=0; i<n; i++) { childrens[i] = new int[numChildren[i]]; } int[] idx = new int[n]; for(int i=0; i<parent.length; i++) { if(parent[i] != parentRoot) childrens[parent[i]][idx[parent[i]]++] = i; } return childrens; } static private int[][][] constructDirectedNeighborhood(int n, int[][] e){ int[] inDegree = new int[n]; int[] outDegree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outDegree[u]++; inDegree[v]++; } int[][] inNeighbors = new int[n][]; int[][] outNeighbors = new int[n][]; for(int i=0; i<n; i++) { inNeighbors[i] = new int[inDegree[i]]; outNeighbors[i] = new int[outDegree[i]]; } for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; outNeighbors[u][--outDegree[u]] = v; inNeighbors[v][--inDegree[v]] = u; } return new int[][][] {inNeighbors, outNeighbors}; } static private int[][] constructNeighborhood(int n, int[][] e) { int[] degree = new int[n]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; degree[u]++; degree[v]++; } int[][] neighbors = new int[n][]; for(int i=0; i<n; i++) neighbors[i] = new int[degree[i]]; for(int i=0; i<e.length; i++) { int u = e[i][0]; int v = e[i][1]; neighbors[u][--degree[u]] = v; neighbors[v][--degree[v]] = u; } return neighbors; } static private void drawGraph(int[][] e) { makeDotUndirected(e); try { final Process process = new ProcessBuilder("dot", "-Tpng", "graph.dot") .redirectOutput(new File("graph.png")) .start(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } static private void makeDotUndirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict graph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "--" + e[i][1] + ";"); } out2.println("}"); out2.close(); } static private void makeDotDirected(int[][] e) { MyPrintWriter out2 = null; try { out2 = new MyPrintWriter(new FileOutputStream("graph.dot")); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } out2.println("strict digraph {"); for(int i=0; i<e.length; i++){ out2.println(e[i][0] + "->" + e[i][1] + ";"); } out2.println("}"); out2.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 17
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
9e86938cfb7b400cf9124e760b01e1e2
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BUpdateFiles solver = new BUpdateFiles(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BUpdateFiles { public void solve(int testNumber, InputReader in, OutputWriter out) { long n = in.nextLong(), k = in.nextLong(); long h = 0; long val = 1; long i = 0; while (val < n && (1L << i) <= k) { val += 1L << i; i++; h++; } long x = Math.min(1L << i, k); n -= val; if (n <= 0) { out.println(h); return; } // out.println(x+" "+val+" "+n); // h+= (long)Math.ceil((double) (n)/(double) x); h += n / x + (n % x == 0 ? 0 : 1); out.println(h); } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
0355456c66a464b2b6801ec2e9b48a5f
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BUpdateFiles solver = new BUpdateFiles(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BUpdateFiles { public void solve(int testNumber, InputReader in, OutputWriter out) { long n = in.nextLong(), k = in.nextLong(); long h = 0; long val = 1; long i = 0; while (val < n && (1L << i) <= k) { val += 1L << i; i++; h++; } long x = Math.min(1L << i, k); n -= val; if (n <= 0) { out.println(h); return; } // out.println(x+" "+val+" "+n); h += n / x + (n % x == 0 ? 0 : 1); out.println(h); } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
92af213f016b3faa84ad343e0be75a11
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BUpdateFiles solver = new BUpdateFiles(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BUpdateFiles { public void solve(int testNumber, InputReader in, OutputWriter out) { long n = in.nextLong(), k = in.nextLong(); long h = 0; long val = 1; long i = 0; while (val < n && (1L << i) <= k) { val += 1L << i; i++; h++; if (val < 0) break; } if (val < 0) { out.println(h); return; } long x = Math.min(1L << i, k); n -= val; if (n <= 0) { out.println(h); return; } // out.println(x+" "+val+" "+n); h += n / x + (n % x == 0 ? 0 : 1); out.println(h); } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
aacd37506422b7b3c22794e0c4dc3425
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BUpdateFiles solver = new BUpdateFiles(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BUpdateFiles { public void solve(int testNumber, InputReader in, OutputWriter out) { long n = in.nextLong(), k = in.nextLong(); long h = 0; long val = 1; long i = 0; while (val < n && (1L << i) <= k) { val += 1L << i; i++; h++; if (val < 0) break; } if (val < 0) { out.println(h); return; } long x = k; n -= val; if (n <= 0) { out.println(h); return; } // out.println(x+" "+val+" "+n); h += n / x + (n % x == 0 ? 0 : 1); out.println(h); } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(long i) { writer.println(i); } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
8c9e74277324bc4d6bd31793d9a19e7b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Program { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = Integer.parseInt(in.readLine()); while (t --> 0) { StringTokenizer st = new StringTokenizer(in.readLine()); long computers = Long.parseLong(st.nextToken()); long cables = Long.parseLong(st.nextToken()); long numberOfTrues = 1; long ans = 0; while (numberOfTrues < computers) { if (numberOfTrues > cables) { ans += (computers - numberOfTrues + cables - 1) / cables; break; } else { numberOfTrues += Math.min(numberOfTrues, cables); ans++; } } out.println(ans); } out.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
8e82461514e3ec17214d26b68284d784
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Program { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = Integer.parseInt(in.readLine()); while (t-- > 0) { StringTokenizer st = new StringTokenizer(in.readLine()); long computers = Long.parseLong(st.nextToken()); long cables = Long.parseLong(st.nextToken()); long numberOfTrues = 1; long ans = 0; while (numberOfTrues < computers) { if (numberOfTrues > cables) { ans += (computers - numberOfTrues + cables - 1) / cables; break; } else { numberOfTrues += Math.min(numberOfTrues, cables); ans++; } } out.println(ans); } in.close(); out.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
22a7c8cbdb5c1247d032efea05b1a0dc
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { long computers = sc.nextLong(); long cables = sc.nextLong(); long numberOfTrues = 1; long ans = 0; while (numberOfTrues < computers) { if (numberOfTrues > cables) { ans += (computers - numberOfTrues + cables - 1) / cables; break; } else { numberOfTrues += Math.min(numberOfTrues, cables); ans++; } } out.println(ans); } sc.close(); out.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
43ca45ca843f17c1506f344f626925c9
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- > 0) { long computers = sc.nextLong(); long cables = sc.nextLong(); long numberOfTrues = 1; long ans = 0; while (numberOfTrues < computers) { if (numberOfTrues > cables) { ans += (computers - numberOfTrues + cables - 1) / cables; break; } else { numberOfTrues += Math.min(numberOfTrues, cables); ans++; } } out.println(ans); } out.close(); } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
b2af861aade2804d104872e2e754160b
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class Program { public static void main(String[] args) { try ( Scanner sc = new Scanner(new BufferedInputStream(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); ) { int t = sc.nextInt(); while (t-- > 0) { long computers = sc.nextLong(); long cables = sc.nextLong(); long numberOfTrues = 1; long ans = 0; while (numberOfTrues < computers) { if (numberOfTrues > cables) { ans += (computers - numberOfTrues + cables - 1) / cables; break; } else { numberOfTrues += Math.min(numberOfTrues, cables); ans++; } } out.println(ans); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output
PASSED
1e4251435f871168a016b24908949796
train_108.jsonl
1635518100
Berland State University has received a new update for the operating system. Initially it is installed only on the $$$1$$$-st computer.Update files should be copied to all $$$n$$$ computers. The computers are not connected to the internet, so the only way to transfer update files from one computer to another is to copy them using a patch cable (a cable connecting two computers directly). Only one patch cable can be connected to a computer at a time. Thus, from any computer where the update files are installed, they can be copied to some other computer in exactly one hour.Your task is to find the minimum number of hours required to copy the update files to all $$$n$$$ computers if there are only $$$k$$$ patch cables in Berland State University.
256 megabytes
import java.io.*; import java.util.*; public class AMain { public static void main(String[] args) { try (Scanner in = new Scanner(new BufferedInputStream(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));) { int t = in.nextInt(); while (t-- > 0) { long n, k; n = in.nextLong(); k = in.nextLong(); long res = 0; long cur = 1; while (cur <= k && cur < n) { res++; cur *= 2; } if (cur < n) res += (n - cur + k - 1) / k; out.println(res); } } } }
Java
["4\n8 3\n6 6\n7 1\n1 1"]
2 seconds
["4\n3\n6\n0"]
NoteLet's consider the test cases of the example: $$$n=8$$$, $$$k=3$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, from the computer $$$2$$$ to the computer $$$6$$$, and from the computer $$$3$$$ to the computer $$$7$$$; during the fourth hour, we copy the update files from the computer $$$2$$$ to the computer $$$8$$$. $$$n=6$$$, $$$k=6$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$, and from the computer $$$2$$$ to the computer $$$4$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$5$$$, and from the computer $$$2$$$ to the computer $$$6$$$. $$$n=7$$$, $$$k=1$$$: during the first hour, we copy the update files from the computer $$$1$$$ to the computer $$$2$$$; during the second hour, we copy the update files from the computer $$$1$$$ to the computer $$$3$$$; during the third hour, we copy the update files from the computer $$$1$$$ to the computer $$$4$$$; during the fourth hour, we copy the update files from the computer $$$4$$$ to the computer $$$5$$$; during the fifth hour, we copy the update files from the computer $$$4$$$ to the computer $$$6$$$; during the sixth hour, we copy the update files from the computer $$$3$$$ to the computer $$$7$$$.
Java 11
standard input
[ "greedy", "implementation", "math" ]
5df6eb50ead22b498bea69bb84341c06
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Each test case consists of a single line that contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^{18}$$$) — the number of computers and the number of patch cables.
1,100
For each test case print one integer — the minimum number of hours required to copy the update files to all $$$n$$$ computers.
standard output