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
acf7520b0ebae7ec633a054f6099928a
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 Program { 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 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++; } } 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 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
b6f70a09cb56c63e2ea33e82ce8ea544
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 Program { 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 numberOfTrues = 1; long ans = 0; while (numberOfTrues < computers) { if (numberOfTrues>cables) { if ((computers-numberOfTrues)%cables!=0) { ans += ((computers-numberOfTrues)/cables)+1; } else { ans += (computers-numberOfTrues)/cables; } break; } else { numberOfTrues += Math.min(numberOfTrues, cables); 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 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
537d5b111d0c9175c2932244031b16ff
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 { static long gcd(long n, long m) { if (m == 0) return n; return gcd(m, n % m); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder str = new StringBuilder(); int t = sc.nextInt(); for (int xx = 0; xx < t; xx++) { long n = sc.nextLong(); long k = sc.nextLong(); long power = 1; long c = 0; int flag = 0; for(long i=1;i<n;i++) { if(n==1) break; if(power*2>=k) { power += Math.min(k, power); c++; if(power>=n) { flag =1; break; } break; } else { power = power *2; c++; if(power>=n) { flag=1; break; } } } if(flag==1) str.append(c+"\n"); else str.append(c+((n-power)/k)+((n-power)%k==0?0:1)+"\n"); } System.out.println(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 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
3680257fad0573b7f289410053a3921b
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 div2 { static boolean a=false; 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(); long k=sc.nextLong(); if(k==1) { System.out.println(n-1); } else if(n==1) { System.out.println("0"); } else { long f=1; long ans=0; while(f<=n&&f<k) { f*=2; ans++; } if(f<n) ans+=(n-f+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 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
8e28ad26658e1d005fdc902f380807cd
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 div2 { static boolean a=false; 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(); long k=sc.nextLong(); if(k==1) { System.out.println(n-1); } else if(n==1) { System.out.println("0"); } else { long f=1; long ans=0; while(f<n&&f<=k) { f*=2; ans++; } if(f<n) ans+=(n-f+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 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
e407cd3b8ee054489b26749e2bcba2f7
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 first { 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; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int 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 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
475737e91d8a42ee7f013279c0f14ddc
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.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; import java.util.StringTokenizer; public class Solution4 { public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=fs.nextInt(); while(t-->0){ long n=fs.nextLong(); long k=fs.nextLong(); // int[] ans=fs.readArray(n); System.out.println(check(n,k)); } } public static long check(long n,long k){ long cur=1; long ans=0; while(cur < k){ cur *= 2; ++ans; } if(cur < n) ans += (n-cur+k-1)/k; return ans; } static final Random random=new Random(); static final int mod=1_000_000_007; // mod is a generally used in ques static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static long add(long a, long b) { // add two function without any modulo problem return (a+b)%mod; } static long sub(long a, long b) { // sub any numbers without modulo problem return ((a-b)%mod+mod)%mod; } static long mul(long a, long b) { // multiply any two number without modulo problem return (a*b)%mod; } static long exp(long base, long exp) { // fast exponentiation if (exp==0) return 1; long half=exp(base, exp/2); if (exp%2==0) return mul(half, half); return mul(half, mul(half, base)); } static long[] factorials=new long[2_000_001]; // large factorial storing array static long[] invFactorials=new long[2_000_001]; static void precompFacts() { factorials[0]=invFactorials[0]=1; for (int i=1; i<factorials.length; i++) factorials[i]=mul(factorials[i-1], i); invFactorials[factorials.length-1]=exp(factorials[factorials.length-1], mod-2); for (int i=invFactorials.length-2; i>=0; i--) invFactorials[i]=mul(invFactorials[i+1], i+1); } static long nCk(int n, int k) { return mul(factorials[n], mul(invFactorials[k], invFactorials[n-k])); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["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
42c22c74bb488ccf7ce1bf543d39b687
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 { static long mod = 1000000007; static long max ; static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); int t = sc.nextInt(); while( t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long i = 2; n-=2; long count = 0 ; if( n < 0) { out.println(0); } else if( n == 0) { out.println(1); } else { count = 1; while( n > 0 && i < k) { n-=Math.min(i, k); count++; i*=2; } if( n > 0) { if( n%k == 0) { count+=n/k; } else { count++; count+=n/k; } } out.println(count); } } out.flush(); } public static boolean ifpowof2(long n ) { return ((n&(n-1)) == 0); } public static int[] nextLargerElement(int[] arr, int n) { Stack<Integer> stack = new Stack<>(); int rtrn[] = new int[n]; rtrn[n-1] = -1; stack.push( n-1); for( int i = n-2 ;i >= 0 ; i--){ int temp = arr[i]; int lol = -1; while( !stack.isEmpty() && arr[stack.peek()] <= temp){ if(arr[stack.peek()] == temp ) { lol = stack.peek(); } stack.pop(); } if( stack.isEmpty()){ if( lol != -1) { rtrn[i] = lol; } else { rtrn[i] = -1; } } else{ rtrn[i] = stack.peek(); } stack.push( i); } return rtrn; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long rightmostsetbit(long n) { return n&-n; } static long leftmostsetbit(long n) { long k = (long)(Math.log(n) / Math.log(2)); return 1 << k; } static HashMap<Long,Long> primefactor( long n){ HashMap<Long ,Long> hm = new HashMap<>(); long temp = 0; while( n%2 == 0) { temp++; n/=2; } if( temp!= 0) { hm.put( 2L, temp); } long c = (long)Math.sqrt(n); for( long i = 3 ; i <= c ; i+=2) { temp = 0; while( n% i == 0) { temp++; n/=i; } if( temp!= 0) { hm.put( i, temp); } } if( n!= 1) { hm.put( n , 1L); } return hm; } @SuppressWarnings("unused") private static ArrayList<Integer> allfactors(int abs) { HashMap<Integer,Integer> hm = new HashMap<>(); ArrayList<Integer> rtrn = new ArrayList<>(); for( int i = 2 ;i*i <= abs; i++) { if( abs% i == 0) { hm.put( i , 0); hm.put(abs/i, 0); } } for( int x : hm.keySet()) { rtrn.add(x); } if( abs != 0) { rtrn.add(abs); } return rtrn; } 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 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
875740a1e6c3c45ff126a0c9a9ce1ef9
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.*; import java.io.*; public class B_Update_Files { public static void main (String[] args) { FastReader scan = new FastReader(); int t = scan.nextInt(); while (t-- > 0) { long n = scan.nextLong(), k = scan.nextLong(); if (k == 1) { System.out.println(n - 1); continue; } if (n == 1) { System.out.println(0); continue; } long ans = 0, done = 1; while (done < n) { if (done <= k) { done *= 2; ans++; } else { ans += (n - done) / k; if ((n - done) % k != 0) { ans++; } break; } } System.out.println(ans); } } static long nextPowerOf2(long n) { long count = 0; if (n > 0 && (n & (n - 1)) == 0) return n; while(n != 0) { n >>= 1; count += 1; } return 1 << count; } public static void inputArray (int[] arr, int n, FastReader scan) { for (int i=0; i<n; i++) { arr[i] = scan.nextInt(); } } public static void printArray (int[] arr) { for (int i=0; i<arr.length; i++) { System.out.print(arr[i] + " "); } System.out.println(); } 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; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static int gcd (int a, int b) { BigInteger a1 = BigInteger.valueOf(a); BigInteger b1 = BigInteger.valueOf(b); return a1.gcd(b1).intValue(); } public static int numberOfDigitsInNumber (int n) { return (int)Math.floor(Math.log10(n)) + 1; } public static boolean isPowerOfTwo (int x) { return x!=0 && ((x&(x-1)) == 0); } public static String toBinaryString (int n) { return Integer.toString(n, 2); // for other bases change 2 to other bases } 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; } } } // For IO using Files // public static void main throws IOException // BufferedReader br = new BufferedReader(new FileReader("input.txt")); // PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); // String st[]=br.readLine().split(" "); // int n=Integer.parseInt(st[0]); // int m=Integer.parseInt(st[1]); // at the end // br.close(); pw.close(); // for printing pw.println(), pw.print(), etc... // for arrays : int arr[] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
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
cf6fb87428fdb1f862788f5e1e1a612d
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 SolutionB{ public static void main(String[] args) throws Exception{ Fast sc=new Fast(); PrintWriter out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0){ long n=sc.nextLong(); long k= sc.nextLong(); long ans=0; n--; double nn=(long)Math.sqrt(4L*(k-1)*2+(long)1); nn--; nn=nn/2; long s=(long)nn; ans=(s*(s+1))/2; // out.println(s+" "+ans); if(n==0){ out.println(0); } else if(n==1){ out.println(1); } else if(k==1){ ans=n; out.println(ans); } else if(n==2){ out.println(2); } else{ long val=1; long cnt=0; while(val<k){ val=val*2; cnt++; } out.println(cnt+(n-val+k)/k); } } out.close(); } static void Sort(int[] ar){ ArrayList<Integer> al=new ArrayList<>(); for(int i=0;i<ar.length;i++){al.add(ar[i]);} Collections.sort(al); for(int i=0;i<al.size();i++)ar[i]=al.get(i); } static int gcd(int a,int b){ if(b==0) return a; else return gcd(b,a%b); } } class Pair{ int x, y; Pair(int x,int y){ this.x=x; this.y=y; } } class Fast{ BufferedReader br; StringTokenizer st; public Fast(){ 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 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
a6cc96acb261c4a3f1468763d47fb92c
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 B { 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) { // TODO Auto-generated method stub FastReader sc = new FastReader(); int t= sc.nextInt(); while(t--!=0) { long n =sc.nextLong(); long k = sc.nextLong(); long comp=1; long count=0; while(comp<=k && comp<n) { count++; comp*=2; } if(comp<n) { count+=(n-comp+k-1)/k; } System.out.println(count); } } static ArrayList<Integer> arr = new ArrayList<Integer>(); static int found=0; static int length; public static void dfs(ArrayList<ArrayList<Integer>> adj,boolean[] vis, int ind, int cnt ) { vis[ind]= true; cnt++; if(cnt==length) { arr.add(ind); found=1; return; } for(int it: adj.get(ind)) { if(vis[it]==false && found==0) { dfs(adj, vis, it, cnt); } if(found==1) { arr.add(ind); return; } } } }
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
75d8281a5e498cf41d1bab91c7dddf5d
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.*; import java.util.Scanner; import java.util.StringTokenizer; public class copy { public static boolean checker(long[] arr, long K, long diff) { long collect = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] > diff) collect += arr[i] - diff; } if (collect >= K) return true; else return false; } public static long search(long[] arr, long K, long R) { long l = 0; long r = R; while (l <= r) { long mid = (l + r) / 2; if (checker(arr, K, mid)) { if (checker(arr, K, mid + 1)) l = mid + 1; else return mid; } else r = mid - 1; } return -1; } static void sieveOfEratosthenes(int n, ArrayList<Integer> arr, ArrayList<Integer> arr1) { // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. 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] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers int x = 0; for (int i = 2; i <= n; i++) { if (prime[i] == true) { arr.add(i); } } System.out.println(arr.size()); } public static boolean check(String s, int K, char ch) { ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == ch) arr.add(i); } // if(K==1 && ch=='z') // System.out.println(arr); if (arr.size() == 0) return false; if (arr.get(0) >= K) return false; if (s.length() - 1 - arr.get(arr.size() - 1) >= K) return false; for (int i = 1; i < arr.size(); i++) { if (arr.get(i) - arr.get(i - 1) > K) return false; } return true; } public static int check(long N) { int sum = 0; while (N > 0) { sum += N % 10; N = N / 10; } return sum; } public static long call(long N) { long l = 1; long r = (long) Math.floor(Math.sqrt(N)); while (l <= r) { long mid = (l + r) / 2; double left = N / (double) (mid) - mid; int right = check(mid); System.out.println(mid + " " + left + " " + right); if (mid == 10) System.out.println(left + " " + right); if (left > right) l = mid + 1; else if (right > left) r = mid - 1; else return mid; } return -1; } public static int path(ArrayList<ArrayList<Integer>> arr, int X, int parent, int[] gold, PriorityQueue<Integer> pq) { int max = 0; ArrayList<Integer> ch = new ArrayList<>(); for (int i : arr.get(X)) { if (i != parent) { ch.add(path(arr, i, X, gold, pq)); } } Collections.sort(ch, Collections.reverseOrder()); for (int i = 1; i < ch.size(); i++) pq.add(ch.get(i)); if (ch.size() == 0) return gold[X]; else return ch.get(0) + gold[X]; } public static long fac(long N, long mod) { if (N == 0) return 1; if(N==1) return 1; return ((N % mod) * (fac(N - 1, mod) % mod)) % mod; } public static String form(char ch, int freq) { String s = ""; for (int i = 1; i <= freq; i++) s += ch; return s; } static long power(long x, long y, long p) { // Initialize result long res = 1; // Update x if it is more than or // equal to p x = x % 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^(-1) mod p static long modInverse(long n, long p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's // little theorem. static long nCrModPFermat(long n, long r, long p) { if (n < r) return 0; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r // System.out.println(modInverse(fac(r,p),p)); // System.out.println(modInverse(fac(n-r,p),p)); return ((fac(n, p) % p * (modInverse(fac(r, p), p) % p)) % p * (modInverse(fac(n - r, p), p) % p)) % p; } public static boolean check(long[] arr, long time, int M) { long sum = 0; int count = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i]; if (sum >= time) { ++count; sum = 0; } } if (sum >= time) ++count; return count >= M; } public static int check(ArrayList<Integer> arr, ArrayList<Integer> arr2) { int l = 0, r = 0, ans = 0; while (l < arr.size() && r < arr2.size()) { if (arr.get(l) < arr2.get(r)) ++l; else if (arr.get(l) > arr2.get(r)) ++r; else { ++ans; ++l; ++r; } } return ans; } public static int find(int[] parent, int x) { if (parent[x] == x) return x; return find(parent, parent[x]); } public static void merge(int[] parent, int[] rank, int x, int y) { int x1 = find(parent, x); int y1 = find(parent, y); if (rank[x1] > rank[y1]) { parent[y1] = x1; } else if (rank[y1] > rank[x1]) { parent[x1] = y1; } else { parent[y1] = x1; rank[x1]++; } } public static int check(ArrayList<ArrayList<Integer>> arr, int e1, int e2, int N) { boolean[] visited = new boolean[N]; visited[0] = true; int[] dist = new int[N]; Queue<Integer> queue = new LinkedList<>(); queue.add(0); Arrays.fill(dist, -1); dist[0] = 0; while (queue.size() > 0) { int x = queue.poll(); for (int i : arr.get(x)) { if (!visited[i] || (e1 == x && e2 == i)) { System.out.println(x + " " + dist[x]); dist[i] = dist[x] + 1; visited[i] = true; queue.add(i); } } } return dist[N - 1]; } static int N; static void rotate90Clockwise(String a[][]) { // Traverse each cycle for (int i = 0; i < N / 2; i++) { for (int j = i; j < N - i - 1; j++) { // Swap elements of each cycle // in clockwise direction String temp = a[i][j]; a[i][j] = a[N - 1 - j][i]; a[N - 1 - j][i] = a[N - 1 - i][N - 1 - j]; a[N - 1 - i][N - 1 - j] = a[j][N - 1 - i]; a[j][N - 1 - i] = temp; } } } public static void moves(String s, int i, int[] movx, int[] movy, int x, int y) { if (i >= s.length()) return; //System.out.println(x+" hello "+y); if (s.charAt(i) == 'L') { movy[i] = y; movx[i] = x - 1; moves(s, i + 1, movx, movy, x - 1, y); } else if (s.charAt(i) == 'R') { movy[i] = y; movx[i] = x + 1; moves(s, i + 1, movx, movy, x + 1, y); } else if (s.charAt(i) == 'U') { movy[i] = y + 1; movx[i] = x; moves(s, i + 1, movx, movy, x, y + 1); } else { movy[i] = y - 1; movx[i] = x; moves(s, i + 1, movx, movy, x, y - 1); } } public static boolean checker(String s1, String s2, int[] arr, int mid) { String s = ""; int N = s1.length(); boolean[] visited = new boolean[N]; for (int i = 0; i <= mid; i++) visited[arr[i] - 1] = true; for (int i = 0; i < N; i++) { if (!visited[i]) s += s1.charAt(i); } int l = 0, index = -1; while (l < s2.length()) { if (s.indexOf(s2.charAt(l), index + 1) == -1) return false; else { index = s.indexOf(s2.charAt(l), index + 1); ++l; } } return true; } public static int check(ArrayList<Integer> possible, int X, int start) { int l = start, r = possible.size() - 1; while (l <= r) { int mid = (l + r) / 2; if (possible.get(mid) > X) { if (mid - 1 >= start && possible.get(mid - 1) > X) r = mid - 1; else return mid; } else l = mid + 1; } return -1; } public static int binse(div[] arr, int X, int N) { int l = 0, r = N - 1; if(arr[N-1].x<=X) return N; if(arr[0].x>X) return 0; while (l <= r) { int mid = (l + r) / 2; // if(N==2) // { // System.out.println(arr[mid].x+" hello "+X); // } if(arr[mid].x<=X) { if(mid+1<N && arr[mid+1].x<=X) l=mid+1; else { //System.out.println(X+" "+mid); return mid+1; } } else r=mid-1; } return -1; } public static long dp(long[][] dp, int X, int[] arr, int index, long mod) { //System.out.println(index+" "+X); if (dp[index][X] != -1) return dp[index][X]; int index1 = index + 1; int plus = (X - arr[index1] + 10) % 10; long ans = dp(dp, plus, arr, index - 1, mod) % mod; for (int i = 0; i < 10; i++) { if ((arr[index1] * i) % 10 == X) ans = (ans % mod + dp(dp, i, arr, index - 1, mod) % mod) % mod; } dp[index][X] = ans; return ans; } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static int check(int x, ArrayList<ArrayList<Integer>> arr, int parent, int dist, long[] ans, int[] child) { ans[0] += dist; int c = 0; for (int i : arr.get(x)) { if (i != parent) c += check(i, arr, x, dist + 1, ans, child); } child[x] = c + 1; return c + 1; } public static void check(int x, int parent, ArrayList<ArrayList<Integer>> arr, int[] child, long[] ans) { ans[x] = ans[parent] - (child[x]) + (arr.size() - child[x]); for (int i : arr.get(x)) { if (i != parent) { check(i, x, arr, child, ans); } } } public static void leftRotatebyOne(int arr[], int n) { int i, temp; temp = arr[0]; for (i = 0; i < n - 1; i++) arr[i] = arr[i + 1]; arr[n - 1] = temp; } public static void tick(char[][] ch, int N, int M, int x, int y, int k, int[][] copy) { int c = 1, size = 0; //System.out.println(x+" "+y); while (x - c >= 0 && y - c >= 0 && y + c < M && ch[x - c][y - c] == '*' && ch[x - c][y + c] == '*') { ++size; ++c; } //System.out.println(size); c -= 1; while (c >= 0) { copy[x - c][y - c] = Math.max(copy[x - c][y - c], size); copy[x - c][y + c] = Math.max(copy[x - c][y + c], size); --c; } } public static long dp(ArrayList<Integer> arr,HashMap<Integer,Long> hp) { if(arr.size()==0) return 0; long[]dp=new long[arr.size()]; dp[0]=hp.get(arr.get(0))*arr.get(0); if(arr.size()==1) return dp[0]; dp[1]=Math.max(arr.get(1)*(hp.get(arr.get(1))),arr.get(0)*(hp.get(arr.get(0)))); for(int i=2;i<arr.size();i++) { int X=arr.get(i); dp[i]=Math.max(X*(hp.get(X))+dp[i-2],dp[i-1]); dp[i]=Math.max(dp[i],dp[i-2]+X*hp.get(X)); } // for(int i=0;i<arr.size();i++) // System.out.println(dp[i]); return dp[arr.size()-1]; } static int power(int x, int y, int p) { // Initialize result int res = 1; // Update x if it is more than or // equal to p x = x % 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^(-1) mod p static int modInverse(int n, int p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's // little theorem. static int nCrModPFermat(int n, int r, int p) { if (n<r) return 0; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r int[] fac = new int[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; } public static int check(int N,int[] dp) { if(N==0) return 0; if(dp[N]!=-1) return dp[N]; if(N<10) return 1; int max=Integer.MAX_VALUE; int X=N; while(X>0) { int digit=X%10; if(digit!=0) { if(dp[N-digit]==-1) max=Math.min(max,check(N-digit,dp)); else max=Math.min(max,dp[N-digit]); } X=X/10; } dp[N]=max+1; return max+1; } public static int check(int a,int b,int k,int[][] dp,int index,int N,int[] length) { if(index>=N) return 0; if(k==1) { if(N-index<a || N-index>b) { dp[index][k]=0; return 0; } else { dp[index][k]=1; length[index]=N-index; return 1; } } if(dp[index][k]!=-1) return dp[index][k]; int ans=0; for(int i=a;i<=b;i++) { if(check(a,b,k-1,dp,index+i,N,length)==1) { length[index]=i; ans=1; } } if(ans>=1) { dp[index][k]=1; return 1; } else { dp[index][k]=0; return 0; } } public static long[][] ncr(int n,int r) { long[][] dp=new long[n+1][r+1]; for(int i=0;i<=n;i++) dp[i][0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=r;j++) { if(j>i) continue; dp[i][j]=dp[i-1][j-1]+dp[i-1][j]; } } return dp; } public static String answer(String s1,String s2) { int index=0; boolean status=true; for(int i=0;i<s2.length();i++) { if(s1.indexOf(s2.charAt(i),index)==-1) { status=false; } else { index=s1.indexOf(s2.charAt(i),index)+1; } } if(status) return "automaton"; String arr1[]=s1.split(""); String arr2[]=s2.split(""); Arrays.sort(arr1); Arrays.sort(arr2); if(Arrays.equals(arr1,arr2)) return "array"; HashMap<Character,Integer> hp=new HashMap<>(); for(int i=0;i<s2.length();i++) { hp.put(s2.charAt(i),0); } for(int i=0;i<s2.length();i++) { if(s1.indexOf(s2.charAt(i),hp.get(s2.charAt(i)))==-1) { return "need tree"; } else { hp.put(s2.charAt(i),s1.indexOf(s2.charAt(i),hp.get(s2.charAt(i)))+1); } } return "both"; } static boolean status=false; static int x1=-1,y1=-1; public static int dfs(ArrayList<ArrayList<Integer>> arr,int X,int[] ans,int value,int parent) { int xor=ans[X]; for(int i:arr.get(X)) { if(i!=parent) { int x=dfs(arr,i,ans,value,X); if(x==-1) return -1; if(x==value) { x1=X; y1=i; return -1; } xor=xor^x; } } return xor; } public static boolean prime(long N) { int c=0; for(int i=2;i*i<=N;i++) { if(N%i==0) ++c; } return c==0; } static int[] c; static boolean sta=true; public static int dfs(ArrayList<ArrayList<Integer>> arr,int N,int j,int[] status,boolean[] visited) { Queue<Integer> queue=new LinkedList<>(); queue.add(j); status[j]=1; visited[j]=true; int[] color=new int[2]; while(queue.size()>0) { int temp=queue.poll(); if(temp<N) color[status[temp]]++; for(int i:arr.get(temp)) { if(visited[i]) { if(status[i]==status[temp]) return -1; } else { queue.add(i); status[i]=1-status[temp]; visited[i]=true; } } } return Math.max(color[0],color[1]); } public static boolean check(String s,int N,long D,long C,long M) { int index=s.lastIndexOf('D'); for(int i=0;i<=index;i++) { if(s.charAt(i)=='D' && D>0) { D-=1; C+=M; } else if(s.charAt(i)=='C' && C>0) { C-=1; } else return false; } return true; } public static boolean checkbounds(int x,int y,int N,int M) { return x>=0 && x<N && y>=0 && y<M; } public static void dfs(int x,int y,char[][] grid,boolean[][] visited,int N,int M) { visited[x][y]=true; if(checkbounds(x+1,y,N,M) && !visited[x+1][y] && grid[x+1][y]=='.') dfs(x+1,y,grid,visited,N,M); if(checkbounds(x-1,y,N,M) && !visited[x-1][y] && grid[x-1][y]=='.') dfs(x-1,y,grid,visited,N,M); if(checkbounds(x,y+1,N,M) && !visited[x][y+1] && grid[x][y+1]=='.') dfs(x,y+1,grid,visited,N,M); if(checkbounds(x,y-1,N,M) && !visited[x][y-1] && grid[x][y-1]=='.') dfs(x,y-1,grid,visited,N,M); } public static int bin(ArrayList<Integer> arr,int search) { int l=0,r=arr.size()-1; if(search<arr.get(0)) return -1; if(search>arr.get(r-1)) return r+1; while(l<=r) { int mid=(l+r)/2; if(arr.get(mid)>search) { if(mid-1>=0 && arr.get(mid-1)>search) r=mid-1; else return mid; } else l=mid+1; } return -1; } public static int mcbc(ArrayList<Long> arr,long search,int N,int lower) { if(search>=arr.get(N)) return N; if(search<=arr.get(lower)) return lower; int l=lower; int r=N; while(l<=r) { int mid=(l+r)/2; if(arr.get(mid)==search) { return mid; } if(arr.get(mid)>search) { if(mid-1>=lower && arr.get(mid-1)>=search) r=mid-1; else { if(mid-1>=lower) { if (Math.abs(search - arr.get(mid)) < Math.abs(search - arr.get(mid - 1))) return mid; else return mid - 1; } else return mid; } } else if(arr.get(mid)<search) { if(mid+1<=N && arr.get(mid+1)<=search) l=mid+1; else { if(mid+1<=N) { if (Math.abs(search - arr.get(mid)) < Math.abs(search - arr.get(mid + 1))) return mid; else return mid + 1; } else return mid; } } } return -1; } public static int check(String s,char ch) { int l=0,r=s.length()-1; int c=0; while(l<r) { if(s.charAt(l)!=s.charAt(r)) { if(s.charAt(l)==ch) { ++c; ++l; } else if(s.charAt(r)==ch) { ++c; --r; } else { return -1; } } else { ++l; --r; } } return c; } public static boolean getbounds(int x,int y,int N,int M) { return x>=0 && x<N && y>=0 && y<M; } static boolean cycle=false; public static void check(int x1,int y1,String[][] s,boolean[][] visited,int N,int M,int[] xdiff,int[] ydiff,div[][] ans,int index) { Queue<div> queue1=new LinkedList<>(); Queue<div> queue2=new LinkedList<>(); visited[x1][y1]=true; queue1.add(new div(x1,y1)); queue2.add(new div(x1,y1)); int c=0; while(queue1.size()>0) { div temp=queue1.poll(); //System.out.println("hello"); int x=temp.x; int y=temp.y; ++c; for(int i=0;i<4;i++) { if(getbounds(x+xdiff[i],y+ydiff[i],N,M)) { if(!visited[x+xdiff[i]][y+ydiff[i]] && s[x+xdiff[i]][y+ydiff[i]].equals(".")) { queue1.add(new div(x+xdiff[i],y+ydiff[i])); queue2.add(new div(x+xdiff[i],y+ydiff[i])); visited[x+xdiff[i]][y+ydiff[i]]=true; } } } } div com=new div(index,c); while(queue2.size()>0) { div temp=queue2.poll(); int x=temp.x; int y=temp.y; ans[x][y]=com; } } static int connected=0; public static int edges(ArrayList<ArrayList<Integer>> arr,int x,boolean[] visited) { ++connected; int sum=arr.get(x).size(); visited[x]=true; for(int i:arr.get(x)) { if(!visited[i]) sum+=edges(arr,i,visited); } return sum; } public static TreeNode build(TreeNode A,TreeNode B) { if(A==null && B==null) return null; if(A!=null && B==null) return A; if(B!=null && A==null) return B; TreeNode left=build(A.left,B.left); TreeNode right=build(A.right,B.right); B.left=left; B.right=right; return B; } public static TreeNode check(TreeNode root1,TreeNode root2) { return build(root1,root2); } public static int check(String str1,String str2) { if(str1.length()!=str2.length()) return -1; int[] count1=new int[26]; int[] count2=new int[26]; for(int i=0;i<str1.length();i++) { count1[str1.charAt(i)-97]++; count2[str2.charAt(i)-97]++; } for(int i=0;i<26;i++) { if(count1[i]!=count2[i]) return -1; } int i = str1.length() - 1; int j = str2.length() - 1; int ans=0; while(i >= 0) { if(str1.charAt(i) != str2.charAt(j)) ans++; else j--; i--; } return ans; } public static void main(String[] args) throws IOException { Reader.init(System.in); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); int T=Reader.nextInt(); A:for(int m=1;m<=T;m++) { long N=Reader.nextLong(); long K=Reader.nextLong(); long ans=0,cur=1; while(cur<K) { cur*=2; ++ans; } if(cur<N) ans+=(N-cur+K-1)/K; output.write(ans+"\n"); } output.flush(); } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer( reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } } class sortat implements Comparator<Long> { public int compare(Long o1,Long o2) { if(Math.abs(o1)<Math.abs(o2)) return -1; else if(Math.abs(o1)>Math.abs(o2)) return 1; else return 0; } } class div { int x, y; div(int x1,int z1) { x = x1; y=z1; } } class TreeNode { int data; TreeNode left; TreeNode right; TreeNode(int data) { left=null; right=null; this.data=data; } }
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
8d099ef80676b7fa278d80d271a4e06a
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 java.math.*; import static java.lang.Long.parseLong; //Make it Divisible by 25 //-00 //-25 //-50 //-75 public class Main{ public static void main(String[] args) throws IOException, NumberFormatException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { String s[]=br.readLine().split(" "); long n = Long.parseLong(s[0]); long k = Long.parseLong(s[1]); if(n==1){ System.out.println(0); }else if(k==1) { System.out.println(n-1); }else { long tm = 0; long ans = 1; while(ans*2<=n && ans<=k) { ans = ans * 2; tm++; } n = n - ans; if(n>0){ if(n%k==0){ tm += n/k; }else{ tm += n/k + 1; }} System.out.println(tm); } } } // ------------------------------------------swap---------------------------------------------------------------------- static void swap(int arr[],int i,int j) { int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } //-------------------------------------------seiveOfEratosthenes---------------------------------------------------- static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. 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] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers // for (int i = 2; i <= n; i++) // { // if (prime[i] == true) // System.out.print(i + " "); // } } // ---------------------------------------- power------------------------------------------------------------------ public static long power(int a , int b) { if (b == 0) { return 1; } else if (b == 1) { return a; } else { long R = power(a, b / 2); if (b % 2 != 0) { return (((power(a, b / 2))) * a * ((power(a, b / 2)))); } else { return ((power(a, b / 2))) * ((power(a, b / 2))); } } } //--------------------------------------lower bound---------------------------------------------------------- static int LowerBound(int a[], int x) { // x is the target value or key 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; } //-------------------------------------------------------------------------------------------------------------- }
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
f7dfd6577eaac4f1375a133c87a76227
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
// Working program with FastReader import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.lang.*; public class B_Update_Files { 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(); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long curr=1; long ans=0; while(curr<k){ ++ans; curr*=2; } if(curr<n){ // long temp=(long)Math.ceil(((n-curr)*1.0)/k); // long req=(long)Math.ceil(temp); ans+=((n-curr+k-1)/k); } System.out.println(ans); // long y=sc.nextLong(); // long t=sc.nextLong(); // long a=1; // long cnt=0; // while(a<=t&&a<y) { // a*=2; // cnt++; // } // if(a<y) // cnt+=(y-a+t-1)/t; // 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 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
98f2f80551cbc6e2c14053ac0d355501
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 { public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = fr.nextInt(); for(int test = 0;test < t;test++) { long n = fr.nextLong(); long k = fr.nextLong(); long ans = 0; long num_c = 1; long inc = 1; while(num_c < k && num_c < n) { num_c += inc; inc = num_c; ans++; } if(num_c < n) { if((n - num_c) % k == 0) ans += (n - num_c)/k; else ans += ((n - num_c)/k) + 1; } out.println(ans); } fr.close(); 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; } void close() throws IOException { br.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
506425381f52dc6046599c37c7bce661
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; /** * * @author Dell */ public class AA { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.nextLine()); while (t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); if (n == 1) { System.out.println("0"); continue; } long total = 1; long h = 0; while (total < k) { h++; total *= 2; if (total >= n) { break; } } if (total >= n) { System.out.println( h); continue; } n -= total; if(n % k == 0){ h += (long) n/k; } else{ h += (long) (n / k) + 1; } 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 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
f3b1e0fad50972628b31b244bd911bb9
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.util.StringTokenizer; /** * * @author eslam */ public class UpdateFiles { 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 IOException { long a[] = new long[64]; for (int i = 0; i < 64; i++) { a[i] = (long) Math.pow(2, i); } BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader input = new FastReader(); int t = input.nextInt(); for (int i = 0; i < t; i++) { long n = input.nextLong(); long k = input.nextLong(); long ans =0; int index = 0; for (int j = 0; j < 64; j++) { if(k<a[j]){ break; } index = j; ans++; } n-=a[index+1]; long s = (n/k); if(n%k!=0&&n>0){ s++; } ans+=s; log.write(ans+"\n"); } 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 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
9c35907f3322e3c503cd443323b71f7b
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 BUpdateFiles { public static void main(String args[]) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int t=Integer.parseInt(in.readLine()); StringTokenizer st; long n=0;long k=0;long j=0; long sum=1; for(int i=0;i<t;i++) { sum=1; st = new StringTokenizer(in.readLine()); n=Long.parseLong(st.nextToken()); k=Long.parseLong(st.nextToken()); for(j=0;sum<n;j++) { sum+=Math.min(sum, k); if(sum>=k) { j+=(n-sum+k-1)/k; sum=n; } } out.println(j); } 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
fccf21217216749b0d4816ab9bd1d08f
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 java.math.BigInteger; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.abs; public class CodeForces { static int mod=1000000000+7; static FastScanner in=new FastScanner(); static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { int T=in.nextInt(); //int T=1; for (int tt=0; tt<T; tt++) { //begin long N = in.nextLong(); long K = in.nextLong(); long now = 1; long time = 0; while (now < N) { if (now >= K) { time += (N - now + K - 1) / K; now = N; } else { now *= 2; time++; } } out.println(time); //end } out.close(); } static class Pair implements Comparable<Pair>{ int first;int second; Pair(int first,int second){ this.first=first; this.second=second; } public int compareTo(Pair o) { return o.second-this.second; } } static boolean isPrime(long n) { if(n < 2) return false; if(n == 2 || n == 3) return true; if(n%2 == 0 || n%3 == 0) return false; long sqrtN = (long)Math.sqrt(n)+1; for(long i = 6L; i <= sqrtN; i += 6) { if(n%(i-1) == 0 || n%(i+1) == 0) return false; } return true; } static long gcd(long a, long b) { if(a > b) a = (a+b)-(b=a); if(a == 0L) return b; return gcd(b%a, a); } static Pair[] pair(Map<Integer,Integer> map) { Pair pair[]=new Pair[map.size()];int i=0; for(int ele:map.keySet()) { pair[i]=new Pair(ele,map.get(ele));i++;} Arrays.sort(pair); return pair; } static Map map(int[] ar) { Map<Integer,Integer> map=new HashMap<>(); for(int i=0;i<ar.length;i++) { if(map.containsKey(ar[i])) map.put(ar[i], map.get(ar[i])+1); else map.put(ar[i], 1); } return map; } static void p(int arr[]) { for(int i=0;i<arr.length;i++) out.print(arr[i]+" "); out.println(); } static<T> void p(T abcd) { out.println(abcd); } static void py() { out.println("YES"); } static void pn() { out.println("NO"); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sortd(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l,Comparator.reverseOrder()); 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(); } String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } String[] readStringArray(int n) { String[] a=new String[n]; for (int i=0; i<n; i++) a[i]=next(); 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 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
b2e30ba3d23ebcf45db7256ac80d6d08
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.company; import java.io.*; import java.util.*; public class Main{ static boolean[] primecheck = new boolean[1000002]; static ArrayList<Integer> adj[]; static int[] vis; static long cnt = 0; static long mod = (long)1e9 + 7; public static void main(String[] args) { OutputStream outputStream = System.out; FastReader in = new FastReader(); PrintWriter out = new PrintWriter(outputStream); PROBLEM solver = new PROBLEM(); int t = 1; t = in.nextInt(); for (int i = 0; i < t; i++) { solver.solve(in, out); } out.close(); } static class PROBLEM { public void solve(FastReader in, PrintWriter out) { long n = in.nextLong(), k = in.nextLong(); long cur = 1; n--; long h = 0; while(n>0){ if(cur == k) break; h++; n-= cur; cur = Math.min(2*cur, k); } h += (n+k-1)/k; out.println(h); } } static long sigmaK(long k){ return (k*(k+1))/2; } static void swap(int[] a, int l, int r) { int temp = a[l]; a[l] = a[r]; a[r] = temp; } static void dfs(int i){ vis[i] = 1; cnt++; for(int j: adj[i]){ if(vis[j] == 0) dfs(j); } } static HashMap<Integer, Integer> initializeMap(int n){ HashMap<Integer,Integer> hm = new HashMap<>(); for (int i = 0; i <= n; i++) { hm.put(i, 0); } return hm; } static boolean isRegular(char[] c){ Stack<Character> s = new Stack<>(); for (char value : c) { if (s.isEmpty() && value == ')') return false; if (value == '(') s.push(value); else s.pop(); } return s.isEmpty(); } static ArrayList<ArrayList<Integer>> createAdj(int n, int e){ FastReader in = new FastReader(); ArrayList<ArrayList<Integer>> adj = new ArrayList<>(); for (int i = 0; i < n + 1; i++) { adj.add(new ArrayList<>()); } for (int i = 0; i < e; i++) { int a = in.nextInt(), b = in.nextInt(); System.out.println(a); adj.get(a).add(b); adj.get(b).add(a); } return adj; } static int binarySearch(int[] a, int l, int r, int x){ if(r>=l){ int mid = l + (r-l)/2; if(a[mid] == x) return mid; if(a[mid] > x) return binarySearch(a, l, mid-1, x); else return binarySearch(a,mid+1, r, x); } return -1; } static boolean isPalindromeI(int n){ int d = 0; int y = n; while(y>0){ d++; y/=10; } int[] a = new int[d]; for (int i = 0; i < d; i++) { a[i] = n%10; n/=10; } for (int i = 0; i < d / 2; i++) { if(a[i] != a[d-i-1]) return false; } return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static boolean isSquare(double a) { boolean isSq = false; double b = Math.sqrt(a); double c = Math.sqrt(a) - Math.floor(b); if (c == 0) isSq = true; return isSq; } static long fast_pow(long a, long b) { //Jeel bhai OP if(b == 0) return 1L; long val = fast_pow(a, b / 2); if(b % 2 == 0) return val * val % mod; else return val * val % mod * a % mod; } static int exponentMod(int A, int B, int C) { // Base cases if (A == 0) return 0; if (B == 0) return 1; // If B is even long y; if (B % 2 == 0) { y = exponentMod(A, B / 2, C); y = (y * y) % C; } // If B is odd else { y = A % C; y = (y * exponentMod(A, B - 1, C) % C) % C; } return (int) ((y + C) % C); } static class Pair implements Comparable<Pair>{ int x; int y; Pair(int x, int y){ this.x = x; this.y = y; } public int compareTo(Pair o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } static class Tuple implements Comparable<Tuple>{ int x, y, id; Tuple(int x, int y, int id){ this.x = x; this.y = y; this.id = id; } public int compareTo(Tuple o){ int ans = Integer.compare(x, o.x); if(o.x == x) ans = Integer.compare(y, o.y); return ans; } } // public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> { // public U x; // public V y; // // public Pair(U x, V y) { // this.x = x; // this.y = y; // } // // public int hashCode() { // return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); // } // // public boolean equals(Object o) { // if (this == o) // return true; // if (o == null || getClass() != o.getClass()) // return false; // Pair<U, V> p = (Pair<U, V>) o; // return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); // } // // public int compareTo(Pair<U, V> b) { // int cmpU = x.compareTo(b.x); // return cmpU != 0 ? cmpU : y.compareTo(b.y); // } // // public int compareToY(Pair<U, V> b) { // int cmpU = y.compareTo(b.y); // return cmpU != 0 ? cmpU : x.compareTo(b.x); // } // // public String toString() { // return String.format("(%s, %s)", x.toString(), y.toString()); // } // // } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return next().charAt(0); } boolean nextBoolean() { return !(nextInt() == 0); } // boolean nextBoolean(){return Boolean.parseBoolean(next());} String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] readArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } } private static int[] mergeSort(int[] array) { //array.length replaced with ctr int ctr = array.length; if (ctr <= 1) { return array; } int midpoint = ctr / 2; int[] left = new int[midpoint]; int[] right; if (ctr % 2 == 0) { right = new int[midpoint]; } else { right = new int[midpoint + 1]; } for (int i = 0; i < left.length; i++) { left[i] = array[i]; } for (int i = 0; i < right.length; i++) { right[i] = array[i + midpoint]; } left = mergeSort(left); right = mergeSort(right); int[] result = merge(left, right); return result; } private static int[] merge(int[] left, int[] right) { int[] result = new int[left.length + right.length]; int leftPointer = 0, rightPointer = 0, resultPointer = 0; while (leftPointer < left.length || rightPointer < right.length) { if (leftPointer < left.length && rightPointer < right.length) { if (left[leftPointer] < right[rightPointer]) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } else if (leftPointer < left.length) { result[resultPointer++] = left[leftPointer++]; } else { result[resultPointer++] = right[rightPointer++]; } } return result; } public static void Sieve(int n) { Arrays.fill(primecheck, true); primecheck[0] = false; primecheck[1] = false; for (int i = 2; i * i < n + 1; i++) { if (primecheck[i]) { for (int j = i * 2; j < n + 1; j += i) { primecheck[j] = false; } } } } }
Java
["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
f8ee33de33ae433fc5cb510eb38b261b
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 { static int mod = 1000000007; static void read(int arr[], int start, int end, FastReader in) { for (int i = start; i < end; i++) { arr[i] = in.nextInt(); } } static int sumArr(int arr[]) { int sum = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i]; } return sum; } static final int MAX = 10000000; // prefix[i] is going to store count // of primes till i (including i). static int prefix[] = new int[MAX + 1]; static void buildPrefix() { // Create a boolean array "prime[0..n]". A // value in prime[i] will finally be false // if i is Not a prime, else true. boolean prime[] = new boolean[MAX + 1]; Arrays.fill(prime, true); for (int p = 2; p * p <= MAX; p++) { // If prime[p] is not changed, then // it is a prime if (prime[p] == true) { // Update all multiples of p for (int i = p * 2; i <= MAX; i += p) { prime[i] = false; } } } // Build prefix array prefix[0] = prefix[1] = 0; for (int p = 2; p <= MAX; p++) { prefix[p] = prefix[p - 1]; if (prime[p]) { prefix[p]++; } } } static int query(int L, int R) { return prefix[R] - prefix[L - 1]; } static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } static int min(int arr[]) { int min = Integer.MAX_VALUE; for (int i = 0; i < arr.length; i++) { min = Math.min(min, arr[i]); } return min; } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) { ls.add(x); } Collections.sort(ls); for (int i = 0; i < arr.length; i++) { arr[i] = ls.get(i); } } static int max(int arr[]) { int max = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) { max = Math.max(max, arr[i]); } return max; } static int max(int a, int b) { return Math.max(a, b); } static int min(int a, int b) { return Math.min(a, b); } public static boolean isPrime(long n) { if (n < 2) { return false; } if (n == 2 || n == 3) { return true; } if (n % 2 == 0 || n % 3 == 0) { return false; } long sqrtN = (long) Math.sqrt(n) + 1; for (long i = 6L; i <= sqrtN; i += 6) { if (n % (i - 1) == 0 || n % (i + 1) == 0) { return false; } } return true; } static class Pair { String first; int second; Pair(String f, int s) { first = f; second = s; } @Override public String toString() { return "first: " + first + " second: " + second; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } void read(int arr[]) { for (int i = 0; i < arr.length; i++) { arr[i] = nextInt(); } } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void print(Object object) throws IOException { bw.append("" + object); } public void close() throws IOException { bw.close(); } } public int[] prevSmaller(int[] A){ // Stack<Integer> stk=new Stack<>(); int ans[]=new int[A.length]; int min=Integer.MAX_VALUE; for(int k=0;k<A.length;k++){ int i=A[k]; if(i<=min){ min=i; ans[k]=-1; } else if(i>min) ans[k]=min; } return ans; } public static int count(String s, char c){ int count=0; for(int i=0;i<s.length();i++) if(s.charAt(i)==c) count++; return count; } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); int tc=in.nextInt(); while(tc-- !=0){ long n=in.nextLong(); long k=in.nextLong(); long count=0; long a=1; long c=1; while(a < k && c<n){ c+=a; // out.println(c+":"+a); a*=2; count++; } // out.println(c/k); out.println(count+((n-c ==0)?0:((n-c+k-1)/k))); } out.close(); }catch (Exception e) { e.printStackTrace(); } } }
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
9f9e1aa8f23e8cd9198bd3f3ec0f82a0
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.math.BigInteger; import java.io.*; public class Main implements Runnable { public static void main(String[] args) { new Thread(null, new Main(), "whatever", 1 << 26).start(); } private FastScanner sc; private PrintWriter pw; public void run() { try { // pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); // sc = new FastScanner(new BufferedReader(new FileReader("input.txt"))); pw = new PrintWriter(System.out); sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); } catch (Exception e) { throw new RuntimeException(); } int t = sc.nextInt(); // int t = 1; while (t-- > 0) { // sc.nextLine(); solve(); } pw.close(); } public long mod = 1_000_000_007; public void solve() { long n = sc.nextLong(), k = sc.nextLong(); if (k == 1) { n--; pw.println(n); return; } long time = 0, i; for (i = 1; i < n;) { if (k >= i) { i *= 2; time++; } else break; } if (i >= n) { pw.println(time); return; } long temp = n; temp -= i; if (temp % k == 0) { temp /= k; } else { temp /= k; temp++; } time += temp; pw.println(time); // if (n > k) { // long time = (long)Math.ceil((double)Math.log(k) / Math.log(2)); // // long time = 0, i; // // for (i = 1; i < n;) { // // if (k >= i) { // // i *= 2; // // time++; // // } else break; // // } // // if (i >= n) { // // pw.println(time); // // return; // // } // // pw.println("Upto now time=" + time); // time += (long)Math.ceil((double)(n - fastPow(2, time)) / k); // pw.println(time); // } else { // long time = (long)Math.ceil((double)Math.log(n) / Math.log(2)); // pw.println(time); // } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(BufferedReader bf) { reader = bf; tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public float nextFloat() { return Float.parseFloat(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String[] nextStringArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) { a[i] = next(); } return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } } public long fastPow(long x, long y, long mod) { if (y == 0) return 1; if (y == 1) return x % mod; long temp = fastPow(x, y / 2, mod); long ans = (temp * temp) % mod; return (y % 2 == 1) ? (ans * (x % mod)) % mod : ans; } public long fastPow(long x, long y) { if (y == 0) return 1; if (y == 1) return x; long temp = fastPow(x, y / 2); long ans = (temp * temp); return (y % 2 == 1) ? (ans * x) : 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
bed741277f518f341cc3c948e7ad9a62
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.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class UpdateFiles { static FastScanner in; static PrintWriter out; public static void main(String[] args) { in = new FastScanner(); out = new PrintWriter(System.out); int t = in.nextInt(); while(t-- > 0) { solve(); } out.println(); out.close(); } static void solve() { long n = in.nextLong(); long cabels = in.nextLong(); long count = 0, cur = 1; while(cur < cabels) { cur*=2; count++; } long temp = Math.max(0, n-cur); count += temp/cabels; if(temp%cabels !=0) { count++; } out.println(count); } static void Sort(int[] a) { ArrayList<Integer> ar = new ArrayList<>(); for(Integer i : a)ar.add(i); Collections.sort(ar); for(int i = 0; i < ar.size();i++ ) a[i] = ar.get(i); } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while(!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); }catch(IOException e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
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
83229dd23db85eaf25cb901e9af8f859
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 Solution { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int g=1;g<=t;g++) { long n=sc.nextLong(); long k=sc.nextLong(); long time=0; long start=1; while(start<=k && start<n) { start=start*2; time++; } if(start<n) { time+=(n-start+k-1)/k; } 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 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
ee272de0070820a56f2ea2a9fea31d3e
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 whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long ans=0; long avl=1; while(avl<=k && avl<n) { avl*=2; ans++; } long left=n-avl; if(left>0) { if(left%k==0) { ans+=(left/k); } else { ans+=(left/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 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
5986d92aa4180cdc9af7796e5acab2f6
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 whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long ans=0; long avl=1; while(avl<=k && avl<n) { avl*=2; ans++; } if(avl<n) { ans = ans + (n-avl+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 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
48e2a9ef222b6bff5b8b7755d3dc8dab
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 whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner In=new Scanner(System.in); int x=In.nextInt(); while(x-->0) { long y=In.nextLong(); long t=In.nextLong(); long a=1; long cnt=0; while(a<=t&&a<y) { a*=2; cnt++; } if(a<y) cnt+=(y-a+t-1)/t; 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 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
7541b8604df450103a834e9c30198e00
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.*; import java.io.*; import java.util.*; public class Main { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringBuilder str = new StringBuilder(); public static void main(String[] args) throws NumberFormatException, IOException { int t = Integer.parseInt(reader.readLine()); while (t-- > 0) { solve(); } printRes(); } public static void printRes() { System.out.println(str); } public static void solve() throws IOException { String[] s = reader.readLine().split(" "); long x = Long.parseLong(s[0]), k = Long.parseLong(s[1]); --x; long cnt = 0; long temp = 1; while (x > 0 && temp < k) { x -= temp; temp *= 2; cnt++; } cnt += (x + k - 1) / k; str.append(cnt + "\n"); } }
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
b697e7569c523bfd3f77bd1c74455925
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; import java.io.*; import java.util.*; public class cp_2 { static int mod=(int)1e9+7; // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); static int[] sp; static int size=(int)1e6; public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // primeSet=new HashSet<>(); // sieveOfEratosthenes((int)1e5); while(tc-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long cnt=0; long num=1; // out.println(num); if (n==1) { out.println(0); continue; } while(num<=k && num<n) { num*=2; cnt++; } // if(num>=n) // { // out.println(cnt); // continue; // } // out.println(num); if(num<n) cnt+=(n-num+k-1)/k; // long rem=n-num; // rem=(long)Math.ceil((double)rem/(double)k); // cnt+=rem; out.println(cnt); } out.flush(); out.close(); System.gc(); } /* ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE... */ static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList<Integer> ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList<Integer> temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static HashSet<Integer> factors(int x) { HashSet<Integer> a=new HashSet<Integer>(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet<Node> adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet<Node>(); } @Override public String toString() { return vertex+" "; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap<Integer,Integer> findFactors(int n) { HashMap<Integer,Integer> ans=new HashMap<>(); if(n%2==0) { ans.put(2, 0); while((n&1)==0) { n=n>>1; ans.put(2, ans.get(2)+1); } } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.put(i, 0); while(n%i==0) { n=n/i; ans.put(i, ans.get(i)+1); } } } if(n!=1) ans.put(n, ans.getOrDefault(n, 0)+1); return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i<n;i++) out.print(getSum(i)+" "); out.println(); } } //Function to find number of set bits static int setBitNumber(long n) { if (n == 0) return 0; int msb = 0; n = n / 2; while (n != 0) { n = n / 2; msb++; } return msb; } static int getFirstSetBitPos(long n) { return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1; } static ArrayList<Integer> primes; static HashSet<Integer> primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? "YES" : "NO"); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print_int(ArrayList<Integer> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void print_long(ArrayList<Long> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void printYesNo(boolean condition) { if (condition) { out.println("Yes"); } else { out.println("No"); } } static int LowerBound(int a[], int x) { // x is the target value or key 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; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i<n;i++) { if(parent[i]==i) cnt++; } return cnt; } } static class Graph { int v; ArrayList<Integer> list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList<Integer>(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static class GraphMap{ // Map<String,ArrayList<String>> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap<String,ArrayList<String>>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet<String> vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } static double sum[]; static long cnt; static void DFS(Graph g, boolean[] visited, int u) { visited[u]=true; for(int i=0;i<g.list[u].size();i++) { int v=g.list[u].get(i); if(!visited[v]) { cnt=cnt*2; DFS(g, visited, v); } } } static class Pair implements Comparable<Pair> { int x,y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static long sum_array(long a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse_array(int a[]) { int n=a.length; int i,t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static void reverse_array(long a[]) { int n=a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static long power(long x, long y) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static 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(); } 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; } } 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(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; }
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
66140ddfb07df5d5487fe5c3b1074e66
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; import java.io.*; import java.util.*; public class cp_2 { static int mod=(int)1e9+7; // static Reader sc=new Reader(); static FastReader sc=new FastReader(System.in); static int[] sp; static int size=(int)1e6; public static void main(String[] args) throws IOException { long tc=sc.nextLong(); // Scanner sc=new Scanner(System.in); // int tc=1; // primeSet=new HashSet<>(); // sieveOfEratosthenes((int)1e5); while(tc-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long cnt=0; long num=1; // out.println(num); if (n==1) { out.println(0); continue; } while(num<=k && num<n) { num*=2; cnt++; } // if(num>=n) // { // out.println(cnt); // continue; // } // out.println(num); if(num<n) cnt+=(n-num+k-1)/k; // long rem=n-num; // rem=(long)Math.ceil((double)rem/(double)k); // cnt+=rem; out.println(cnt); } out.flush(); out.close(); System.gc(); } /* ...SOLUTION ENDS HERE...........SOLUTION ENDS HERE... */ static String tr(String s) { int now = 0; while (now + 1 < s.length() && s.charAt(now)== '0') ++now; return s.substring(now); } static ArrayList<Integer> ans; static void dfs(int node,Graph gg,int cnt,int k,ArrayList<Integer> temp) { if(cnt==k) return; for(Integer each:gg.list[node]) { if(each==0) { temp.add(each); ans=new ArrayList<>(temp); temp.remove(temp.size()-1); continue; } temp.add(each); dfs(each,gg,cnt+1,k,temp); temp.remove(temp.size()-1); } return; } static HashSet<Integer> factors(int x) { HashSet<Integer> a=new HashSet<Integer>(); for(int i=2;i*i<=x;i++) { if(x%i==0) { a.add(i); a.add(x/i); } } return a; } static class Node { int vertex; HashSet<Node> adj; boolean rem; Node(int ver) { vertex=ver; rem=false; adj=new HashSet<Node>(); } @Override public String toString() { return vertex+" "; } } static class Tuple{ int a; int b; int c; public Tuple(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } } //function to find prime factors of n static HashMap<Integer,Integer> findFactors(int n) { HashMap<Integer,Integer> ans=new HashMap<>(); if(n%2==0) { ans.put(2, 0); while((n&1)==0) { n=n>>1; ans.put(2, ans.get(2)+1); } } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.put(i, 0); while(n%i==0) { n=n/i; ans.put(i, ans.get(i)+1); } } } if(n!=1) ans.put(n, ans.getOrDefault(n, 0)+1); return ans; } //fenwick tree implementaion static class fwt { int n; long BITree[]; fwt(int n) { this.n=n; BITree=new long[n+1]; } fwt(int arr[], int n) { this.n=n; BITree=new long[n+1]; for(int i = 0; i < n; i++) updateBIT(n, i, arr[i]); } long getSum(int index) { long sum = 0; index = index + 1; while(index>0) { sum += BITree[index]; index -= index & (-index); } return sum; } void updateBIT(int n, int index,int val) { index = index + 1; while(index <= n) { BITree[index] += val; index += index & (-index); } } void print() { for(int i=0;i<n;i++) out.print(getSum(i)+" "); out.println(); } } //Function to find number of set bits static int setBitNumber(long n) { if (n == 0) return 0; int msb = 0; n = n / 2; while (n != 0) { n = n / 2; msb++; } return msb; } static int getFirstSetBitPos(long n) { return (int)((Math.log10(n & -n)) / Math.log10(2)) + 1; } static ArrayList<Integer> primes; static HashSet<Integer> primeSet; static boolean prime[]; static void sieveOfEratosthenes(int n) { // Create a boolean array // "prime[0..n]" and // initialize all entries // it as true. A value in // prime[i] will finally be // false if i is Not a // prime, else true. prime= new boolean[n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) primeSet.add(i); } } static long mod(long a, long b) { long c = a % b; return (c < 0) ? c + b : c; } static void swap(long arr[],int i,int j) { long temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } static boolean util(int a,int b,int c) { if(b>a)util(b, a, c); while(c>=a) { c-=a; if(c%b==0) return true; } return (c%b==0); } static void flag(boolean flag) { out.println(flag ? "YES" : "NO"); out.flush(); } static void print(int a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print(long a[]) { int n=a.length; for(int i=0;i<n;i++) { out.print(a[i]+" "); } out.println(); out.flush(); } static void print_int(ArrayList<Integer> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void print_long(ArrayList<Long> al) { int si=al.size(); for(int i=0;i<si;i++) { out.print(al.get(i)+" "); } out.println(); out.flush(); } static void printYesNo(boolean condition) { if (condition) { out.println("Yes"); } else { out.println("No"); } } static int LowerBound(int a[], int x) { // x is the target value or key 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; } static int lowerIndex(int arr[], int n, int x) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] >= x) h = mid - 1; else l = mid + 1; } return l; } // function to find last index <= y static int upperIndex(int arr[], int n, int y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int upperIndex(long arr[], int n, long y) { int l = 0, h = n - 1; while (l <= h) { int mid = (l + h) / 2; if (arr[mid] <= y) l = mid + 1; else h = mid - 1; } return h; } static int UpperBound(int a[], int x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int UpperBound(long a[], long x) {// x is the key or target value int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static class DisjointUnionSets { int[] rank, parent; int n; // Constructor public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } // Creates n sets with single item in each void makeSet() { for (int i = 0; i < n; i++) parent[i] = i; } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } // Unites the set that includes x and the set // that includes x void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else // if ranks are the same { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } // if(xRoot!=yRoot) // parent[y]=x; } int connectedComponents() { int cnt=0; for(int i=0;i<n;i++) { if(parent[i]==i) cnt++; } return cnt; } } static class Graph { int v; ArrayList<Integer> list[]; Graph(int v) { this.v=v; list=new ArrayList[v+1]; for(int i=1;i<=v;i++) list[i]=new ArrayList<Integer>(); } void addEdge(int a, int b) { this.list[a].add(b); } } // static class GraphMap{ // Map<String,ArrayList<String>> graph; // GraphMap() { // // TODO Auto-generated constructor stub // graph=new HashMap<String,ArrayList<String>>(); // // } // void addEdge(String a,String b) // { // if(graph.containsKey(a)) // this.graph.get(a).add(b); // else { // this.graph.put(a, new ArrayList<>()); // this.graph.get(a).add(b); // } // } // } // static void dfsMap(GraphMap g,HashSet<String> vis,String src,int ok) // { // vis.add(src); // // if(g.graph.get(src)!=null) // { // for(String each:g.graph.get(src)) // { // if(!vis.contains(each)) // { // dfsMap(g, vis, each, ok+1); // } // } // } // // cnt=Math.max(cnt, ok); // } static double sum[]; static long cnt; static void DFS(Graph g, boolean[] visited, int u) { visited[u]=true; for(int i=0;i<g.list[u].size();i++) { int v=g.list[u].get(i); if(!visited[v]) { cnt=cnt*2; DFS(g, visited, v); } } } static class Pair implements Comparable<Pair> { int x,y; Pair(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return this.x-o.x; } } static long sum_array(int a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static long sum_array(long a[]) { int n=a.length; long sum=0; for(int i=0;i<n;i++) sum+=a[i]; return sum; } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void reverse_array(int a[]) { int n=a.length; int i,t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } static void reverse_array(long a[]) { int n=a.length; int i; long t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } } // static long modInverse(long a, long m) // { // long g = gcd(a, m); // // return power(a, m - 2, m); // // } static long power(long x, long y) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long gcd(long a, long b) { if (a == 0) return b; //cnt+=a/b; return gcd(b%a,a); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b%a, a); } static 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(); } 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; } } 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(); } } static PrintWriter out=new PrintWriter(System.out); static int int_max=Integer.MAX_VALUE; static int int_min=Integer.MIN_VALUE; static long long_max=Long.MAX_VALUE; static long long_min=Long.MIN_VALUE; }
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
e589bb6195fcef5ebdba6cf1a40fc7fd
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; while(count<n && count<=m){ count*=2; hrs++; } if(count>=n){ return hrs; } hrs += (n - count + m - 1) / m; 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 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
7f6c951981d12746a1c44f5390d7c140
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 HelloWorld{ public static void main(String []args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ String str=sc.next(); long n=Long.parseLong(str); String str1=sc.next(); long k=Long.parseLong(str1); long ans=0; long reusecomp=1; long compleft=n-1; if(k==1){ ans=n-1; System.out.println(ans); continue; } while(true){ if(k>reusecomp){ compleft=compleft-reusecomp; reusecomp+=reusecomp; }else{ long rem = (compleft + k - 1) / k; ans+=rem; break; } 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 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
f732057735c0697e3e5a01f938fb830c
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.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author saikat021 */ 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); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int T = in.nextInt(); while (T-- > 0) { long n = in.nextLong(); long k = in.nextLong(); n -= 1L; long nCables = 1L, n_hour = 0L;//this loop is ok log n mapping while (n > 0 && nCables < k) { n -= nCables; nCables *= 2; n_hour++; } if (n > 0) n_hour += (n + k - 1) / k; out.println(n_hour); // // long numHours=(long)Math.ceil(Math.log(k)/Math.log(2)); // long sum=(long)Math.pow(2,numHours)-1; // if(sum<n){ // out.println((long)numHours+(long)Math.ceil((double)(n-sum-1)/(double)k)); // // } else { // long hours2N=(long)Math.ceil(Math.log(n-1)/Math.log(2)); // out.println((long)hours2N); // // } } } } 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); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["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
5926b188e124b49a75d3988f17011c09
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 Codeforces { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int test=sc.nextInt(); long mod=1000000007; while(test!=0){ long n=sc.nextLong(); long k=sc.nextLong(); n=n-1; long i=1; long ans=0; while(n>0 && i<=k){ n=n-i; i=i*2; ans++; } ans+=(long)((n+k-1)/k); System.out.println(ans); test--; } } }
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
a1a920a7c48facf1248e1105832db76f
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.Arrays; public class B { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); for (int i = 0; i < t; i++) { long[] compToCables = Arrays.stream(reader.readLine().split(" ")) .mapToLong(Long::parseLong) .toArray(); long computers = compToCables[0]; long cables = compToCables[1]; if (computers == 1) { System.out.println(0); continue; } long computersWithUpdate = 1; long minHours = 0; while (computersWithUpdate < cables) { computersWithUpdate *= 2; minHours++; } computers = Math.max(0, computers - computersWithUpdate); minHours += (computers / cables) + (computers % cables != 0 ? 1 : 0); System.out.println(minHours); } } }
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
c0238a6991aa17c92ec532d7da10ad9f
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 Main { static long mod = (int)1e9+7; public static void main (String[] args) throws java.lang.Exception { FastReader sc =new FastReader(); int t=sc.nextInt(); // int t=1; while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long count=0; long c=1,cr=n-1; while(c<=k&&cr>0) { cr-=c; c+=c; count++; } if(cr>0) { count+=(cr+k-1)/k; } System.out.println(count); } } static int findfrequencies(int a[],int n) { int count=0; for(int i=0;i<a.length;i++) { if(a[i]==n) { count++; } } return 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) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readArrayLong(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for(int v : a) { c0[(v&0xff)+1]++; c1[(v>>>8&0xff)+1]++; c2[(v>>>16&0xff)+1]++; c3[(v>>>24^0x80)+1]++; } for(int i = 0;i < 0xff;i++) { c0[i+1] += c0[i]; c1[i+1] += c1[i]; c2[i+1] += c2[i]; c3[i+1] += c3[i]; } int[] t = new int[n]; for(int v : a)t[c0[v&0xff]++] = v; for(int v : t)a[c1[v>>>8&0xff]++] = v; for(int v : a)t[c2[v>>>16&0xff]++] = v; for(int v : t)a[c3[v>>>24^0x80]++] = v; return a; } static int[] EvenOddArragement(int a[]) { ArrayList<Integer> list=new ArrayList<>(); for(int i=0;i<a.length;i++) { if(a[i]%2==0) { list.add(a[i]); } } for(int i=0;i<a.length;i++) { if(a[i]%2!=0) { list.add(a[i]); } } for(int i=0;i<a.length;i++) { a[i]=list.get(i); } return a; } static int gcd(int a, int b) { while (b != 0) { int t = a; a = b; b = t % b; } return a; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static int DigitSum(int n) { int r=0,sum=0; while(n>=0) { r=n%10; sum=sum+r; n=n/10; } return 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 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
a57d11053b8b3416890dfea426768cbf
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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Test{ static FastReader scan; static void solve(){ long n=scan.nextLong(); long c=scan.nextLong(); long rem=n-1; long total=1; long ans=0; while(rem>0&&total<=c){ ans++; rem=rem-total; total+=total; } if(rem>0){ ans+=rem/c+(rem%c==0?0:1); } System.out.println(ans); } public static void main (String[] args) throws java.lang.Exception{ scan=new FastReader(); int t=scan.nextInt(); while(t-->0){ solve(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair implements Comparable<Pair>{ int e; int wt; Pair(int x,int y){ this.e=x; this.wt=y; } @Override public int compareTo(Pair x){ return (int)(x.wt-this.wt); } } static void printLong(long []arr){ for(long x:arr)System.out.print(x+" "); } static void printInt(int []arr){ for(int x:arr)System.out.print(x+" "); } static void scanInt(int []arr){ for(int i=0;i<arr.length;i++){ arr[i]=scan.nextInt(); } } static void scanLong(long []arr){ for(int i=0;i<arr.length;i++){ arr[i]=scan.nextLong(); } } static long gcd(long a, long b){ if (b == 0) return a; return gcd(b, a % b); } static long power(long x, long y, long mod){ long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0){ if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static long add(long a,long b,long mod){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod; } static long sub(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod; } static long mul(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod; } static long mminvprime(long a, long b,long mod) { return power(a, b - 2,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 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
d2c4e51ce6b55a2c9f9a7e3dfde77d32
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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Test{ static FastReader scan; static void solve(){ long n=scan.nextLong(); long c=scan.nextLong(); long rem=n-1; long total=1; long ans=0; while(rem>0&&total<=c){ ans++; rem=rem-total; total+=total; } if(rem>0){ ans+=(rem+c-1)/c; } System.out.println(ans); } public static void main (String[] args) throws java.lang.Exception{ scan=new FastReader(); int t=scan.nextInt(); while(t-->0){ solve(); } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair implements Comparable<Pair>{ int e; int wt; Pair(int x,int y){ this.e=x; this.wt=y; } @Override public int compareTo(Pair x){ return (int)(x.wt-this.wt); } } static void printLong(long []arr){ for(long x:arr)System.out.print(x+" "); } static void printInt(int []arr){ for(int x:arr)System.out.print(x+" "); } static void scanInt(int []arr){ for(int i=0;i<arr.length;i++){ arr[i]=scan.nextInt(); } } static void scanLong(long []arr){ for(int i=0;i<arr.length;i++){ arr[i]=scan.nextLong(); } } static long gcd(long a, long b){ if (b == 0) return a; return gcd(b, a % b); } static long power(long x, long y, long mod){ long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0){ if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static long add(long a,long b,long mod){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod; } static long sub(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod; } static long mul(long a, long b,long mod){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod; } static long mminvprime(long a, long b,long mod) { return power(a, b - 2,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 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
a36bc5d2046870226eddcfff6f1da1c6
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 Faily_obnovlenie { public static void main(String[] args) { Scanner go=new Scanner(System.in); long t=go.nextInt(); for(int j=0;j<t;j++) { long n = go.nextLong(); long k = go.nextLong(); long hour = result(n,k); System.out.println(hour); } } public static long result(long n, long k) { long hour = 0; long start = 1; long connect = 1; while (n > start && connect < k) { start = start + connect; connect = connect * 2; hour++; } if(n > start){ hour = hour + (long)((n - start+k-1)/k); } return hour; } }
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
0dd9dffdfc2ca581fba07d74d2cc564f
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.BigDecimal; import java.math.RoundingMode; public class Main implements Runnable { static FastReader sc; static PrintWriter out; static int mod = 1000000007, inf = (int) 1e9, minf = -(int) 1e9; static long infL = (long) 1e18, minfL = -(long) 1e18; static final Random random = new Random(); public static void main(String[] args) { new Thread(null, new Main(), "coderrohan14", 1 << 26).start(); } @Override public void run() { try { ioSetup(); } catch (IOException e) { return; } } public static void ioSetup() throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { File f1 = new File("input.txt"); File f2 = new File("output.txt"); Reader r = new FileReader(f1); sc = new FastReader(r); out = new PrintWriter(f2); double prev = System.currentTimeMillis(); solve(); out.println("\n\nExecuted in : " + ((System.currentTimeMillis() - prev) / 1e3) + " sec"); } else { sc = new FastReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); } out.flush(); out.close(); } static void solve() { int t = sc.nextInt(); StringBuilder ans = new StringBuilder(""); while (t-- > 0) { long n = sc.nextLong(),k=sc.nextLong(); long steps=0,used=1; while(used<=k&&used<n){ used = used<<1L; steps++; } if(used<n) steps+=(n-used+k-1)/k; ans.append(steps+"\n"); } out.println(ans); } /****************************************************************************************************************************************************************************************/ public static long log2(long N) { long result = (long) (Math.log(N) / Math.log(2)); return result; } static double setPrecision(double num,int precision){ return BigDecimal.valueOf(num).setScale(precision,RoundingMode.HALF_UP).doubleValue(); } static long modInverse(long a, int mod) { long g = gcd(a, mod); if (g != 1) return -1; else { return modPower(a, mod - 2L, mod); } } static long modPower(long x, long y, int mod) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } static int gcd(int a, int b) { int tmp = 0; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; } static long gcd(long a, long b) { long tmp = 0; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; } static boolean isPrime(long n) { if (n == 2 || n == 3) return true; if (n % 2 == 0) return false; for (long i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return n != 1; } static void sort(long[] a) { int n = a.length;// shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n); long temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static void sort(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 boolean isPerfectSquare(long x) { long sqrt = (long) Math.sqrt(x); return (sqrt * sqrt) == x; } static int digitsCount(long x) { return (int) Math.floor(Math.log10(x)) + 1; } static boolean isPowerTwo(long n) { return (n & n - 1) == 0; } static void sieve(boolean[] prime, int n) { // Sieve Of Eratosthenes for (int i = 1; i <= n; i++) { prime[i] = true; } for (int i = 2; i * i <= n; i++) { if (prime[i]) { for (int j = 2; i * j <= n; j++) { prime[i * j] = false; } } } } static long nCr(long n, long r) { // Combinations if (n < r) return 0; if (r > n - r) { // because nCr(n, r) == nCr(n, n - r) r = n - r; } long ans = 1L; for (long i = 0; i < r; i++) { ans *= (n - i); ans /= (i + 1); } return ans; } static int floor(int[] a, int v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (v < a[mid]) h = mid; else { if (mid + 1 < h && a[mid + 1] < v) l = mid + 1; else return mid; } } return a[l] <= v ? l : -1; } static int floor(long[] a, long v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (v < a[mid]) h = mid; else { if (mid + 1 < h && a[mid + 1] < v) l = mid + 1; else return mid; } } return a[l] <= v ? l : -1; } static int ceil(int[] a, int v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (a[mid] < v) l = mid + 1; else h = mid; } return a[h] >= v ? h : -1; } static int ceil(long[] a, long v) { int l = 0, h = a.length - 1; while (l < h) { int mid = (l + h) / 2; if (a[mid] == v) return mid; if (a[mid] < v) l = mid + 1; else h = mid; } return a[h] >= v ? h : -1; } static long catalan(int n) { // n-th Catalan Number long c = nCr(2 * n, n); return c / (n + 1); } static class Pair implements Comparable<Pair> { // Pair Class int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Pair)) { return false; } Pair pair = (Pair) o; if (x != pair.x) { return false; } if (y != pair.y) { return false; } return true; } @Override public int hashCode() { long result = x; result = 31 * result + y; return (int) result; } @Override public int compareTo(Pair o) { return (int) (this.x - o.x); } } static class Trip { // Triplet Class long x; long y; long z; Trip(long x, long y, long z) { this.x = x; this.y = y; this.z = z; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Trip)) { return false; } Trip trip = (Trip) o; if (x != trip.x) { return false; } if (y != trip.y) { return false; } if (z != trip.z) { return false; } return true; } @Override public int hashCode() { long result = 62 * x + 31 * y + z; return (int) result; } } /**************************************************************************************************************************************************************************************/ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(Reader r) { br = new BufferedReader(r); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArrayI(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } return arr; } long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextLong(); } return arr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (st != null && st.hasMoreTokens()) { return true; } String tmp; try { br.mark(1000); tmp = br.readLine(); if (tmp == null) { return false; } br.reset(); } catch (IOException e) { return false; } return true; } } /* * ASCII Range--->(A-Z)--->[65,90]<<::>>(a-z)--->[97,122] */ /******************************************************************************************************************/ static void printArray(int[] arr) { out.print("["); for (int i = 0; i < arr.length; i++) { if (i < arr.length - 1) out.print(arr[i] + ","); else out.print(arr[i]); } out.print("]"); out.println(); } static void printArray(long[] arr) { out.print("["); for (int i = 0; i < arr.length; i++) { if (i < arr.length - 1) out.print(arr[i] + ","); else out.print(arr[i]); } out.print("]"); out.println(); } static void printArray(double[] arr) { out.print("["); for (int i = 0; i < arr.length; i++) { if (i < arr.length - 1) out.print(arr[i] + ","); else out.print(arr[i]); } out.print("]"); out.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 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
7e0c01b976159dc5d14387aff7d16f49
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
/* _oo0oo_ o8888888o 88" . "88 (| -_- |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' */ import java.util.*; import java.math.*; import java.io.*; import java.lang.Math.*; public class KickStart2020 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static class Pair implements Comparable<Pair> { public int index; public int value; public Pair(int index,int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { // multiplied to -1 as the author need descending sort order if(other.index < this.index) return 1; else return -1; } @Override public String toString() { return this.index + " " + this.value; } } static boolean isPrime(long d) { if (d == 1) return false; for (int i = 2; i <= (long) Math.sqrt(d); i++) { if (d % i == 0) return false; } return true; } static void decimalTob(int n, int k, Stack<Integer> ss) { int x = n % k; int y = n / k; ss.push(x); if(y > 0) { decimalTob(y, k, ss); } } static long powermod(long x, long y, long mod) { long ans = 1; x = x % mod; if (x == 0) return 0; int i = 1; while (y > 0) { if ((y & 1) != 0) ans = (ans * x) % mod; y = y >> 1; x = (x * x) % mod; } return ans; } static long power(long x, long y) { long res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = res * x; // y must be even now y = y >> 1; // y = y/2 x = x * x; // Change x to x^2 } return res; } public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); outerloop: while(t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long cnt = 1; long sec = 0; if(n == 1) { out.println(0); continue; } while(cnt <= k) { sec++; cnt *= 2; if(cnt >= n) break; } if(cnt < n) sec += (n - cnt + k - 1) / k; out.println(sec); } 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
a3904f21666608dd933ae9681b24660e
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 CP { static Scanner s = new Scanner(System.in); static class pair{ long key; int count; pair(long key , int count){ this.count = count; this.key = key; } } static class sort implements Comparator<Integer>{ @Override public int compare(Integer o1, Integer o2) { if(Math.abs(o1) > Math.abs(o2)){ return 1; }else if(Math.abs(o1) < Math.abs(o2))return -1; return 0; } } public static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String s) throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(new FileInputStream(s))); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } static private long gcd(long a , long b){ if(b == 0)return a; return gcd(b , a % b); } static private void printArrayList(ArrayList<Object> al){ String st = ""; for(Object i : al){ st += i + " "; } System.out.println(st); } static private long digitSum(long n){ long sum = 0; while(n != 0){ sum += n%10; n = n/10; } return sum; } static boolean checkPrime(int x){ for(int i = 2; i <= Math.sqrt(x);i++){ if(x % i == 0){ return false; } } return true; } static boolean checkPallindrome(String st){ int i = 0, j = st.length() - 1; while (i <= j){ if(st.charAt(i) != st.charAt(j))return false; i++; j--; } return true; } static boolean checkPowerOfTwo(int n){ final double v = Math.log(n) / Math.log(2); return (int)(Math.ceil(v)) == (int)(Math.floor(v)); } static ArrayList<Long> insert(long n) throws IOException { ArrayList<Long> al = new ArrayList<>(); for(long i =0 ; i < n; i++){ al.add(s.nextLong()); } return al; } static int debugger = 1; static void debug(){ System.out.println("Reached " + debugger++); } static String reverse(String st){ String ans = ""; for(int i = st.length() - 1; i >= 0; i--)ans += st.charAt(i); return ans; } static void dfs(int root , Map<Integer , ArrayList<Integer>> children){ if(children.size() == 0)return; for(int i = 0; i < children.size(); i++){ // do operations } } /* ArrayList<Integer> al = new ArrayList<>(); Map<Integer , ArrayList<Integer>> children = new HashMap<>(); for(int i = 0; i < n; i++){ al.add(s.nextInt()); children.put(i + 1 , new ArrayList<>()); } for(int i = 0; i < m; i++){ int x = s.nextInt(); int y = s.nextInt(); ArrayList<Integer> temp = children.get(x); temp.add(y); children.put(x , temp); } */ //funtions that you have ramakant // a sort (comparator) // gcd // digitSum // checkPrime (sqrt method) // checkPallindrome (two pointer) // checkPowerOfTwo (log method) // reverse a string // dfs of graph / tree // insert in arrayList // print ArrayList public static void main(String[] args) { try { StringBuffer sb = new StringBuffer(); int t = s.nextInt(); while (t-- > 0){ long n =s.nextLong(); long k = s.nextLong(); if(n == 1){ sb.append("0\n"); continue; } if(k == 1){ sb.append(n - 1).append("\n"); continue; } long count = 0; long pow = 1; while(pow < k) { count++; pow = pow * 2; } n -= pow; if(n > 0)count += (n + k - 1) / k; sb.append(count+"\n"); // System.out.println(k); } System.out.println(sb); }catch (Exception e){ e.printStackTrace(); } } }
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
c0de1cdcf7502d74002796c2ef246549
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.Math; import java.lang.reflect.Array; import java.util.*; import javax.swing.text.DefaultStyledDocument.ElementSpec; public final class Solution { static BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); static BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(System.out) ); static StringTokenizer st; /*write your constructor and global variables here*/ static class sortCond implements Comparator<Pair<Integer, Integer>> { @Override public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) { if (p1.a <= p2.a) { return -1; } else { return 1; } } } static class Rec { int a; int b; long c; Rec(int a, int b, long c) { this.a = a; this.b = b; this.c = c; } } static class Pair<f, s> { f a; s b; Pair(f a, s b) { this.a = a; this.b = b; } } interface modOperations { int mod(int a, int b, int mod); } static int findBinaryExponentian(int a, int pow, int mod) { if (pow == 1) { return a; } else if (pow == 0) { return 1; } else { int retVal = findBinaryExponentian(a, (int) pow / 2, mod); int val = (pow % 2 == 0) ? 1 : a; return modMul.mod(modMul.mod(retVal, retVal, mod), val, mod); } } static int findPow(int a, int b, int mod) { if (b == 1) { return a % mod; } else if (b == 0) { return 1; } else { int res = findPow(a, (int) b / 2, mod); return modMul.mod(res, modMul.mod(res, (b % 2 == 1 ? a : 1), mod), mod); } } static int bleft(long ele, ArrayList<Long> sortedArr) { int l = 0; int h = sortedArr.size() - 1; int ans = -1; while (l <= h) { int mid = l + (int) (h - l) / 2; if (sortedArr.get(mid) < ele) { l = mid + 1; } else if (sortedArr.get(mid) >= ele) { ans = mid; h = mid - 1; } } return ans; } static long gcd(long a, long b) { long div = b; long rem = a % b; while (rem != 0) { long temp = rem; rem = div % rem; div = temp; } return div; } static long[] log(long no, long n) { long i = 1l; long cnt = 0l; while (i < no) { i *= 2l; cnt++; } long arr[] = new long[2]; arr[0] = cnt; arr[1] = i; return arr; } static int log1(int no) { int i = 0; while ((1 << i) < no) { i++; } return (1 << i) == no ? (1 << i) : (1 << (i - 1)); } static modOperations modAdd = (int a, int b, int mod) -> { return (a % mod + b % mod) % mod; }; static modOperations modSub = (int a, int b, int mod) -> { return (int) ((1l * a % mod - 1l * b % mod + 1l * mod) % mod); }; static modOperations modMul = (int a, int b, int mod) -> { return (int) ((1l * (a % mod) * 1l * (b % mod)) % (1l * mod)); }; static modOperations modDiv = (int a, int b, int mod) -> { return modMul.mod(a, findBinaryExponentian(b, mod - 1, mod), mod); }; static HashSet<Integer> primeList(int MAXI) { int[] prime = new int[MAXI + 1]; HashSet<Integer> obj = new HashSet<>(); for (int i = 2; i <= (int) Math.sqrt(MAXI) + 1; i++) { if (prime[i] == 0) { obj.add(i); for (int j = i * i; j <= MAXI; j += i) { prime[j] = 1; } } } for (int i = (int) Math.sqrt(MAXI) + 1; i <= MAXI; i++) { if (prime[i] == 0) { obj.add(i); } } return obj; } static int[] factorialList(int MAXI, int mod) { int[] factorial = new int[MAXI + 1]; factorial[2] = 1; for (int i = 3; i < MAXI + 1; i++) { factorial[i] = modMul.mod(factorial[i - 1], i, mod); } return factorial; } static void put(HashMap<Integer, Integer> cnt, int key) { if (cnt.containsKey(key)) { cnt.replace(key, cnt.get(key) + 1); } else { cnt.put(key, 1); } } static long arrSum(ArrayList<Long> arr) { long tot = 0; for (int i = 0; i < arr.size(); i++) { tot += arr.get(i); } return tot; } static int ord(char b) { return (int) b - (int) 'a'; } static int optimSearch(int[] cnt, int lower_bound, int pow, int n) { int l = lower_bound + 1; int h = n; int ans = 0; while (l <= h) { int mid = l + (h - l) / 2; if (cnt[mid] - cnt[lower_bound] == pow) { return mid; } else if (cnt[mid] - cnt[lower_bound] < pow) { ans = mid; l = mid + 1; } else { h = mid - 1; } } return ans; } static Pair<Long, Integer> ret_ans(ArrayList<Integer> ans) { int size = ans.size(); int mini = 1000000000 + 1; long tit = 0l; for (int i = 0; i < size; i++) { tit += 1l * ans.get(i); mini = Math.min(mini, ans.get(i)); } return new Pair<>(tit - mini, mini); } static int factorList( HashMap<Integer, Integer> maps, int no, int maxK, int req ) { int i = 1; while (i * i <= no) { if (no % i == 0) { if (i != no / i) { put(maps, no / i); } put(maps, i); if (maps.get(i) == req) { maxK = Math.max(maxK, i); } if (maps.get(no / i) == req) { maxK = Math.max(maxK, no / i); } } i++; } return maxK; } static ArrayList<Integer> getKeys(HashMap<Integer, Integer> maps) { ArrayList<Integer> vals = new ArrayList<>(); for (Map.Entry<Integer, Integer> map : maps.entrySet()) { vals.add(map.getKey()); } return vals; } static ArrayList<Integer> getValues(HashMap<Integer, Integer> maps) { ArrayList<Integer> vals = new ArrayList<>(); for (Map.Entry<Integer, Integer> map : maps.entrySet()) { vals.add(map.getValue()); } return vals; } /*write your methods here*/ static int getMax(ArrayList<Integer> arr) { int max = arr.get(0); for (int i = 1; i < arr.size(); i++) { if (arr.get(i) > max) { max = arr.get(i); } } return max; } static int getMin(ArrayList<Integer> arr) { int max = arr.get(0); for (int i = 1; i < arr.size(); i++) { if (arr.get(i) < max) { max = arr.get(i); } } return max; } public static void main(String[] args) throws IOException { int cases = Integer.parseInt(br.readLine()); long n, k; while (cases-- != 0) { st = new StringTokenizer(br.readLine()); n = Long.parseLong(st.nextToken()); k = Long.parseLong(st.nextToken()); if (n == 1l) { bw.write("0\n"); continue; } long arr[] = log(k, n); long tot = arr[0]; long rem = Math.min(1l * n, arr[1]); //System.out.println(rem + " " + tot); tot += (n - rem + k - 1) / k; bw.write(Long.toString(tot) + "\n"); } bw.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 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
1451e99c72503be69d3a248f5dc59cc5
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.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.StringTokenizer; public class UpdateFiles { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); // Start writing your solution here. ------------------------------------- int T = sc.nextInt(); // read input as integer for(int i=0;i<T;i++) { long n = sc.nextLong(); long k = sc.nextLong(); long res = calculate(n, k); out.println(res); } out.close(); } private static int getLog2Ceiling(long k) { long a = 1; for(int i=0;;i++){ if(a >= k) return i; a*=2; } } private static long get2Exponential(int e) { long a = 1; for(int i=0;i<e;i++){ a*=2; } return a; } private static long divideCeiling(long a, long b) { BigDecimal b1 = new BigDecimal(a); BigDecimal b2 = new BigDecimal(b); BigDecimal quotient = b1 .divide(b2, 0, RoundingMode.UP); return quotient.longValue(); } private static long calculate(long n, long k) { if(k>n) k=n; int i = getLog2Ceiling(k); long remainder = n - get2Exponential(i); if(remainder <= 0) return i; long quotient = divideCeiling(remainder, k); return i + quotient; } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { FileInputStream fis; // try { // fis = new FileInputStream("src/p1606B/input.txt"); // br = new BufferedReader(new InputStreamReader(fis)); // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } 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 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
fb0813a7686dbdce930edadfcf89edf4
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.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.StringTokenizer; public class UpdateFiles { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); // Start writing your solution here. ------------------------------------- int T = sc.nextInt(); // read input as integer for(int i=0;i<T;i++) { long n = sc.nextLong(); long k = sc.nextLong(); long res = calculate(n, k); out.println(res); } out.close(); } private static int getLog2Ceiling(long k) { long a = 1; for(int i=0;;i++){ if(a >= k) return i; a*=2; } } private static long get2Exponential(int e) { long a = 1; for(int i=0;i<e;i++){ a*=2; } return a; } private static long calculate(long n, long k) { if(k>n) k=n; int i = getLog2Ceiling(k); long remainder = n - get2Exponential(i); if(remainder <= 0) return i; BigDecimal b1 = new BigDecimal(remainder); BigDecimal b2 = new BigDecimal(k); BigDecimal quotient = b1 .divide(b2, 0, RoundingMode.UP); return i + quotient.longValue(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { FileInputStream fis; // try { // fis = new FileInputStream("src/p1606B/input.txt"); // br = new BufferedReader(new InputStreamReader(fis)); // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } 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 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
9d3a62d6eef61db68e2b82b31f57fc0f
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.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.StringTokenizer; public class UpdateFiles { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); // Start writing your solution here. ------------------------------------- int T = sc.nextInt(); // read input as integer for(int i=0;i<T;i++) { long n = sc.nextLong(); long k = sc.nextLong(); long res = calculate(n, k); out.println(res); } out.close(); } static int getExponent(long k) { long a = 1; for(int i=0;;i++){ if(a >= k) return i; a*=2; } } private static long calculate(long n, long k) { if(k>n) k=n; int i = getExponent(k); long remainder = n - (long) Math.pow(2, i); if(remainder <= 0) return i; BigDecimal b1 = new BigDecimal(remainder); BigDecimal b2 = new BigDecimal(k); BigDecimal quotient = b1 .divide(b2, 0, RoundingMode.UP); return i + quotient.longValue(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { FileInputStream fis; // try { // fis = new FileInputStream("src/p1606B/input.txt"); // br = new BufferedReader(new InputStreamReader(fis)); // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } 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 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
e8076477e600ad3223ab88865ac02ffe
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
/** * @author -- Sourav Joshi */ import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.*; import static java.lang.Math.*; public class Solution { /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static FastScanner s = new FastScanner(); static FastWriter out = new FastWriter(); final static int mod = (int)1e9 + 7; final static int INT_MAX = Integer.MAX_VALUE; final static int INT_MIN = Integer.MIN_VALUE; final static long LONG_MAX = Long.MAX_VALUE; final static long LONG_MIN = Long.MIN_VALUE; final static double DOUBLE_MAX = Double.MAX_VALUE; final static double DOUBLE_MIN = Double.MIN_VALUE; final static float FLOAT_MAX = Float.MAX_VALUE; final static float FLOAT_MIN = Float.MIN_VALUE; /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static class FastScanner{BufferedReader br;StringTokenizer st; public FastScanner() {br = new BufferedReader(new InputStreamReader(System.in));} String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();} int nextInt(){return Integer.parseInt(next());} long nextLong(){return Long.parseLong(next());} double nextDouble(){return Double.parseDouble(next());} List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;} List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;} int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;} long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;} String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}} static class FastWriter{private final BufferedWriter bw;public FastWriter() {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));} public void print(Object object) throws IOException{bw.append(""+ object);} public void println(Object object) throws IOException{print(object);bw.append("\n");} public void debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void close() throws IOException{bw.close();}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(int i = 2; i <= n; i++) {if(arr[i] == 1) {continue;}else {list.add(i);for(int j = i*i; j <= n; j = j + i) {arr[j] = 1;}}}return list;} public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);} public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];} public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;} public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;} public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;} public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;} public static long modInv(long a, long b){ return expo(a, b-2)%b;} public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));} public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Pair class public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{ X first; Y second; public Pair(X first, Y second){ this.first = first; this.second = second; } public String toString(){ return "( " + first+" , "+second+" )"; } @Override public int compareTo(Pair<X, Y> o) { int t = first.compareTo(o.first); if(t == 0) return -1*second.compareTo(o.second); return t; } } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Code begins public static void solve() throws IOException { long n = s.nextLong(); long c = s.nextLong(); long ans = 0; long curr = 1; while(curr < c){ curr *= 2l; ans++; } if(curr < n) ans += (n-curr+c-1)/c; out.println(ans); } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static void main(String[] args) throws IOException { int test = s.nextInt(); for(int tt = 1; tt <= test; tt++) { solve(); } 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
26e2fd448cffb206ce252eaeb521b74f
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
/** * @author -- Sourav Joshi */ import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.*; import static java.lang.Math.*; public class Solution { /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static FastScanner s = new FastScanner(); static FastWriter out = new FastWriter(); final static int mod = (int)1e9 + 7; final static int INT_MAX = Integer.MAX_VALUE; final static int INT_MIN = Integer.MIN_VALUE; final static long LONG_MAX = Long.MAX_VALUE; final static long LONG_MIN = Long.MIN_VALUE; final static double DOUBLE_MAX = Double.MAX_VALUE; final static double DOUBLE_MIN = Double.MIN_VALUE; final static float FLOAT_MAX = Float.MAX_VALUE; final static float FLOAT_MIN = Float.MIN_VALUE; /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static class FastScanner{BufferedReader br;StringTokenizer st; public FastScanner() {br = new BufferedReader(new InputStreamReader(System.in));} String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();} int nextInt(){return Integer.parseInt(next());} long nextLong(){return Long.parseLong(next());} double nextDouble(){return Double.parseDouble(next());} List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;} List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;} int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;} long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;} String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}} static class FastWriter{private final BufferedWriter bw;public FastWriter() {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));} public void print(Object object) throws IOException{bw.append(""+ object);} public void println(Object object) throws IOException{print(object);bw.append("\n");} public void debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void close() throws IOException{bw.close();}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(int i = 2; i <= n; i++) {if(arr[i] == 1) {continue;}else {list.add(i);for(int j = i*i; j <= n; j = j + i) {arr[j] = 1;}}}return list;} public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);} public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];} public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;} public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;} public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;} public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;} public static long modInv(long a, long b){ return expo(a, b-2)%b;} public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));} public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Pair class public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{ X first; Y second; public Pair(X first, Y second){ this.first = first; this.second = second; } public String toString(){ return "( " + first+" , "+second+" )"; } @Override public int compareTo(Pair<X, Y> o) { int t = first.compareTo(o.first); if(t == 0) return -1*second.compareTo(o.second); return t; } } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Code begins public static void solve() throws IOException { long n = s.nextLong(); long c = s.nextLong(); long ans = 0; long curr = 1; while(curr < c){ curr *= 2l; ans++; } if(curr < n) ans += (n-curr+c-1)/c; System.out.println(ans); } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static void main(String[] args) throws IOException { int test = s.nextInt(); for(int tt = 1; tt <= test; tt++) { solve(); } 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
5342b5b50d4331652a154387016cf9b6
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; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; public class k { //public static int mod=1000000007; public static long printDivisors(long n, int k) { // Note that this loop runs till square root long x=(long) Math.sqrt(n); // int p=0; long sum=0; for (long i=1; i<=x; i++) { if (n%i == 0) { // If divisors are equal, print only one if (n/i == i) sum=sum+(long)(i); else // Otherwise print both sum=sum+(long)(i)+(long)(n/i); } if(sum>k)return -1; } return sum; } public static ArrayList<Long> Factors(long n) { ArrayList<Long> arr=new ArrayList<Long>(); int k=0; while (n%2==0) { k++; n /=2; arr.add((long)2); } int p=(int) Math.sqrt(n); for (int i = 3; i <=p; i+= 2) { if(n==1)break; while (n%i == 0) { k++; arr.add((long)i); n /= i; } } if (n > 2) { arr.add(n); } return arr; } 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 long gcd(long x, long p) { if (x == 0) return p; return gcd(p%x, x); } // method to return LCM of two numbers static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >(hm.entrySet()); // Sort the list Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() { public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } static int sieve = 1000000 ; static boolean[] prime = new boolean[sieve + 1] ; static ArrayList<Integer> pr=new ArrayList<Integer>(); public static void sieveOfEratosthenes() { // FALSE == prime and 1 // TRUE == COMPOSITE // time complexity = 0(NlogLogN)== o(N) // gives prime nos bw 1 to N // size - 1e7(at max) for(int i = 4; i<= sieve ; i++) { prime[i] = true ; i++ ; } for(int p = 3; p*p <= sieve; p++) { if(prime[p] == false) { pr.add(p); for(int i = p*p; i <= sieve; i += p) prime[i] = true; } p++ ; } } public static void arrInpInt(int [] arr, int n) throws IOException { Reader reader = new Reader(); for(int i=0;i<n;i++) { arr[i]=reader.nextInt(); } } public static void arrInpLong(long [] arr, int n) throws IOException { Reader reader = new Reader(); for(int i=0;i<n;i++) { arr[i]=reader.nextLong(); } } public static void printArr(int[] arr) { for(int i=0;i<arr.length;i++) { System.out.print(arr[i]+" "); } System.out.println(); } public static int[] decSort(int[] arr) { int[] arr1 = Arrays.stream(arr).boxed().sorted(Collections.reverseOrder()).mapToInt(Integer::intValue).toArray(); return arr1; } //if present - return the first occurrence of the no //not present- return the index of next greater value //if greater than all the values return N(taking high=N-1) //if smaller than all the values return 0(taking low =0) static int lower_bound(int arr[], int low,int high, int X) { if (low > high) { return low; } int mid = low + (high - low) / 2; if (arr[mid] >= X) { return lower_bound(arr, low, mid - 1, X); } return lower_bound(arr, mid + 1, high, X); } //if present - return the index of next greater value //not present- return the index of next greater value //if greater than all the values return N(taking high=N-1) //if smaller than all the values return 0(taking low =0)\ static int upper_bound(int arr[], int low, int high, int X) { if (low > high) return low; int mid = low + (high - low) / 2; if (arr[mid] <= X) { return upper_bound(arr, mid + 1, high, X); } return upper_bound(arr, low, mid - 1, X); } public static class Pair {// comparator with class int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sortbyColumn(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else if (entry1[col] < entry2[col]) return -1; else return 0; } }); } public static void sortbyColumn1(int arr[][], int col) // send 2d array and col no { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else if (entry1[col] < entry2[col]) return -1; else if(entry1[col] == entry2[col]) { if(entry1[col-1]>entry2[col-1]) return -1; else if(entry1[col-1]<entry2[col-1]) return 1; else return 0; } else return 0; } }); } public static void print2D(int mat[][]) { // Loop through all rows for (int i = 0; i < mat.length; i++) { // Loop through all elements of current row { for (int j = 0; j < mat[i].length; j++) System.out.print(mat[i][j] + " "); } System.out.println(); } } public static int biggestFactor(int num) { int result = 1; for(int i=2; i*i <=num; i++){ if(num%i==0){ result = num/i; break; } } return result; } public static int knapsack(int[] weights,int[] price, int totW) { int[] dp1=new int[totW+1]; int[] dp2=new int[totW+1]; int N=totW; int ans=0; for(int i=0;i<price.length;i++) { for(int j=0;j<=N;j++) { if(weights[i]>j) { if(i%2==0) { dp1[j]=dp2[j]; } else { dp2[j]=dp1[j]; } } else { if(i%2==0) { dp1[j]=Math.max(dp2[j],dp2[j-weights[i]]+price[i]); } else { dp2[j]=Math.max(dp1[j], dp1[j-weights[i]]+price[i]); } } } if(i%2==0)ans=dp1[N]; else ans=dp2[N]; } return ans; } public static class p { int no; int h; public p(int no, long h) { this.no=no; this.h=(int) h; } } static class com implements Comparator<p>{ public int compare(p s1, p s2) { if (s1.h > s2.h) return -1; else if (s1.h < s2.h) return 1; else if(s1.h==s2.h) { if(s1.no>s2.no)return -1; else return 1; } return 0; } } static long hcf(long a,long b) { while (b > 0) { long temp = b; b = a % b; a = temp; } return a; } static int lower_bound_arr(ArrayList<Integer> arr, int low, int high, int X) { if (low > high) { return low; } int mid = low + (high - low) / 2; if (arr.get(mid) >= X) { return lower_bound_arr(arr, low, mid - 1, X); } return lower_bound_arr(arr, mid + 1, high, X); } public static int func2(int m,int[] arr,int k,int[] arr1) { for(int i=0;i<arr.length;i++) { int p=arr[i]; int q=arr[i]+m; int in=(q<=arr.length?arr1[q]:arr.length)-arr1[p-1]; if((in)-(arr.length-in)>=k)return arr[i]; } return 0; } public static boolean func(int m,int[] arr,int k,int[] arr1) { for(int i=0;i<arr.length;i++) { int p=arr[i]; int q=arr[i]+m; int in=(q<=arr.length?arr1[q]:arr.length)-arr1[p-1]; if((in)-(arr.length-in)>=k)return true; } return false; } public static int binarySearch(int min, int max, int[] arr,int k,int[] arr1) { int l = min, r = max; while (l <= r) { int m = l + (r - l) / 2; boolean x11=func(m,arr,k,arr1); boolean x1=func(m-1,arr,k,arr1); if(x11 && !x1)return m; //Check if x is present at mid // if (arr[m] == x) // return m; // If x greater, ignore left half if (!x1 && !x11) l = m + 1; // If x is smaller, ignore right half else r = m - 1; } return max; } // public static long func(Integer[] arr, int k) // { // // } // public static HashMap<String,Integer> map1=new HashMap<String,Integer>(); // public static int function1(int[][] arr1,Integer[] arr, int start, int end) // { //// System.out.println("1"); // // int p=0; // int n=0; // p=arr1[end][0]-arr1[start-1][0]; // n=arr1[end][1]-arr1[start-1][1]; //// return Math.abs(n-p); // if(n==p)return 0; // if(map1.containsKey(start+" "+end))return map1.get(start+" "+end); // else // { // int min=Integer.MAX_VALUE; // int n1=0; // int p1=0; // for(int i=end-1;i>=start-1;i--) // { //// System.out.println("pp"); //// int P=p-(arr[i]==1?1:0)-p1+n1; //// int N=n-(arr[i]==-1?1:0)-n1+p1; // int P=(arr[i]==1?1:0)-p1+n1; // int N=(arr[i]==-1?1:0)-n1+p1; // if(arr[i]==-1)n1++; // else p1++; // // p=arr1[end][0]-arr1[i+1][0]; // n=arr1[end][1]-arr1[i+1][1]; // //// min=Math.min(Math.abs(P-N), min); //// map1.put((i+1)+" "+end,min+1); // } // // // // return min; // } // } public static void main(String args[]) throws NumberFormatException, IOException ,java.lang.Exception { Reader reader = new Reader(); // power(); long[] pow2 =new long[64]; pow2[0]=1l; for(int i=1;i<64;i++) { // pow2[i]=(int) Math.pow(2, i); pow2[i]=(long)(2)*pow2[i-1]; // System.out.println(pow2[i]); } //Scanner reader=new Scanner(System.in); // PrintWriter out = new PrintWriter(System.out); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // int cases=Integer.parseInt(br.readLine()); // int cases=1; int cases=reader.nextInt(); while (cases-->0){ long N=reader.nextLong(); long M=reader.nextLong(); // long H1=reader.nextLong(); // long D1=reader.nextLong(); // long H2=reader.nextLong(); // long D2=reader.nextLong(); // // long C=reader.nextLong(); // long W=reader.nextLong(); // long A=reader.nextLong(); // int N=reader.nextInt(); // int M=reader.nextInt(); // int K=reader.nextInt(); // long M=reader.nextLong(); // // long X=reader.nextLong(); // String p=""; // while(p.equals(""))p=br.readLine(); //// // String[] first1=br.readLine().split(" "); // int N=Integer.parseInt(first1[0]); // int M=Integer.parseInt(first1[1]); // long K=Long.parseLong(first1[0]); // long X=Long.parseLong(first1[1]); // String s2=br.readLine(); // String s3=br.readLine(); // char[] s11=s2.toCharArray(); // char[] s12=new char[s11.length]; int max=Integer.MIN_VALUE; // int max1=Integer.MIN_VALUE; int min=Integer.MAX_VALUE; int min1=Integer.MAX_VALUE; // int min2=Integer.MAX_VALUE; long mod=1000000007; // HashMap<Integer, Integer> map=new HashMap<Integer,Integer>(); // PriorityQueue<Integer> q = new PriorityQueue<Integer>(Collections.reverseOrder()); // PriorityQueue<Long> q = new PriorityQueue<Long>(Collections.reverseOrder()); // HashMap<Integer,TreeSet<Integer>> map=new HashMap<Integer,TreeSet<Integer>>(); // HashMap<Long,Long> map=new HashMap<Long,Long>(); // HashMap<String,String> map1=new HashMap<String,String>(); //HashMap<Character,Integer> path=new HashMap<Character,Integer>(); // List<TreeMap<Integer,Integer>> map = new ArrayList<TreeMap<Integer,Integer>>(); // HashSet<String> set =new HashSet<String>(); // HashSet<String> set1 =new HashSet<String>(); // HashSet<Integer> map =new HashSet<Integer>(); // TreeSet<Integer> a =new TreeSet<Integer>(); //TreeSet<Long> b =new TreeSet<Long>(); // TreeSet<Integer> map=new TreeSet<Integer>(); // int[] arr=new int[N]; // int[] arr1=new int[N]; // int[] arr3=new int[N]; // int[] arr4=new int[N]; // // int[] arr1=new int[N]; // int[] arr2=new int[26];// i00nt[] odd=new int[100001]; // int[] arr=new int[5]; // int[] arr2=new int[5]; // Integer[] arr=new Integer[N]; // Integer[] arr1=new Integer[N]; // long[] arr=new long[N]; // Long[] arr=new Long[N]; // int[][] arr=new int[N][P]; // ArrayList<Long> list=new ArrayList<Long>(); // ArrayList<Long> list3=new ArrayList<Long>(); // ArrayList<Long> list1=new ArrayList<Long>(); // ArrayList<Long> bees=new ArrayList<Long>(); // boolean[]arr1=new boolean[N]; // // boolean first=true; // output.append((ind+1)+" "+(N));output.newLine(); // in(ans2, ans3))); // int[][] arr=new int[N][M]; // System.out.println(N+" "+M); long upper= (long)(Math.log(M)/Math.log(2)); // System.out.println(upper); if(upper>0 && pow2[(int) (upper)]>M)upper--; // System.out.println(upper); long x=pow2[(int) (upper+1)]; // System.out.println(pow2[63]); if(x<0) {System.out.println(1/0);} if(N==x)System.out.println(upper+1); else if(N<x) { if((N&(N-1))!=0) { long po=(long)(Math.log(N)/Math.log(2)); if(pow2[(int) po]>=N)System.out.println(po); else System.out.println(po+1); // System.out.println((long)(Math.log(N)/Math.log(2))); } else { System.out.println((long)(Math.log(N)/Math.log(2))); } // }System.out.println(((N&(N-1))!=0)?(long)(Math.log(N)/Math.log(2))+1:(long)(Math.log(N)/Math.log(2)); } else { long rem=N-x; long p=rem/M; // if(p<0) {System.out.println(1/0);} // if(rem<0) {System.out.println(1/0);} if((rem%M)!=0)p++; System.out.println(p+upper+1); } // output.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 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
f1be3a915954adb93cd4184801b5d8c3
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.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t!=0){ t--; long n= sc.nextLong(), k = sc.nextLong(); long cnt =0, cur=1; while(cur<k){ cnt++; cur*=2; } if(cur<n){ cnt+=(n-cur+k-1)/k; } 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 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
5b6c51cabdbe806cab56375a6f6acaa3
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 { Kattio io = new Kattio(); int t = io.nextInt(); for (int ii=0; ii<t; ii++) { long n = io.nextLong(); long k = io.nextLong(); long time = 0; long total = 1; long pow = 1; while (total < n) { time++; total += Math.min(pow, k); pow *= 2; if (pow > k) { break; } } if (total >= n) { System.out.println(time); continue; } if ((n-total)%k == 0) { time += (n-total)/k; } else { time += ((n-total)/k + 1); } System.out.println(time); } } static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(new FileWriter(problemName + ".out")); r = new BufferedReader(new FileReader(problemName + ".in")); } // returns null if no more input public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) { } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
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
bcfcf9f6357c679404906abc174f11f6
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 UpdateFiles { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long a=sc.nextLong(); long b=sc.nextLong(); long count=0; if(a==0) { System.out.println(0); continue; } if(a==1) { System.out.println(0); continue; } long k=1; for(int i=1;;i++) { if(k>=b) { break; } k=k*2; count++; } if(k>=a) { System.out.println(count); } else { a-=k; if(a%b==0) { System.out.println((a/b)+count); } else { System.out.println((a/b)+count+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 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
7319112ca16fe7af0d4b5915f349c588
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 Test{ //Global declarations final static FastReader in = new FastReader(); final static PrintWriter out = new PrintWriter(System.out); public static void helperFunction(String s) { //Long range is -10^18 to 10^18 and is 64 bit (8 bytes) //Integer range is ~~ -2 * 10^9(-2^31) to 2 * 10^9(2^31 - 1) and is 32 bit (4 bytes) } public static void main(String ... args) throws IOException { // << --> multiply // >> --> divide //variable_name <<= 1 --> (variable)multiply by 2 //variable_name >>= 1 --> (variable)divide by 2 //2<<3 --> (multiply)2 * 2^3 --> 16; //6>>1 --> (divide)6 / 2^1 --> 3; /** int n = in.nextInt(),a,b; in.nextLine(); while(n-->0){ a = in.nextInt(); b = in.nextInt(); out.println(a+b); if(n>0) in.nextLine(); } out.close(); int tt = in.nextInt(); while(tt-->0){ out.println(helperFunction()); } //out.println(helperFunction()); **/ //it returns the remaining length (+ve) so bigger so swap //System.out.println("h".compareTo("ha")); /* Problem 13 - Large sum String s = "37107287533902102798797998220837590246510135740250463769376774900097126481248969700780504170182605387432498619952474105947423330951305812372661730962991942213363574161572522430563301811072406154908250230675882075393461711719803104210475137780632466768926167069662363382013637841838368417873436172675728112879812849979408065481931592621691275889832738442742289174325203219235894228767964876702721893184745144573600130643909116721685684458871160315327670386486105843025439939619828917593665686757934951621764571418565606295021572231965867550793241933316490635246274190492910143244581382266334794475817892575867718337217661963751590579239728245598838407582035653253593990084026335689488301894586282278288018119938482628201427819413994056758715117009439035398664372827112653829987240784473053190104293586865155060062958648615320752733719591914205172558297169388870771546649911559348760353292171497005693854370070576826684624621495650076471787294438377604532826541087568284431911906346940378552177792951453612327252500029607107508256381565671088525835072145876576172410976447339110607218265236877223636045174237069058518606604482076212098132878607339694128114266041808683061932846081119106155694051268969251934325451728388641918047049293215058642563049483624672216484350762017279180399446930047329563406911573244438690812579451408905770622942919710792820955037687525678773091862540744969844508330393682126183363848253301546861961243487676812975343759465158038628759287849020152168555482871720121925776695478182833757993103614740356856449095527097864797581167263201004368978425535399209318374414978068609844840309812907779179908821879532736447567559084803087086987551392711854517078544161852424320693150332599594068957565367821070749269665376763262354472106979395067965269474259770973916669376304263398708541052684708299085211399427365734116182760315001271653786073615010808570091499395125570281987460043753582903531743471732693212357815498262974255273730794953759765105305946966067683156574377167401875275889028025717332296191766687138199318110487701902712526768027607800301367868099252546340106163286652636270218540497705585629946580636237993140746255962240744869082311749777923654662572469233228109171419143028819710328859780666976089293863828502533340334413065578016127815921815005561868836468420090470230530811728164304876237919698424872550366387845831148769693215490281042402013833512446218144177347063783299490636259666498587618221225225512486764533677201869716985443124195724099139590089523100588229554825530026352078153229679624948164195386821877476085327132285723110424803456124867697064507995236377742425354112916842768655389262050249103265729672370191327572567528565324825826546309220705859652229798860272258331913126375147341994889534765745501184957014548792889848568277260777137214037988797153829820378303147352772158034814451349137322665138134829543829199918180278916522431027392251122869539409579530664052326325380441000596549391598795936352974615218550237130764225512118369380358038858490341698116222072977186158236678424689157993532961922624679571944012690438771072750481023908955235974572318970677254791506150550495392297953090112996751986188088225875314529584099251203829009407770775672113067397083047244838165338735023408456470580773088295917476714036319800818712901187549131054712658197623331044818386269515456334926366572897563400500428462801835170705278318394258821455212272512503275512160354698120058176216521282765275169129689778932238195734329339946437501907836945765883352399886755061649651847751807381688378610915273579297013376217784275219262340194239963916804498399317331273132924185707147349566916674687634660915035914677504995186714302352196288948901024233251169136196266227326746080059154747183079839286853520694694454072476841822524674417161514036427982273348055556214818971426179103425986472045168939894221798260880768528778364618279934631376775430780936333301898264209010848802521674670883215120185883543223812876952786713296124747824645386369930090493103636197638780396218407357239979422340623539380833965132740801111666627891981488087797941876876144230030984490851411606618262936828367647447792391803351109890697907148578694408955299065364044742557608365997664579509666024396409905389607120198219976047599490197230297649139826800329731560371200413779037855660850892521673093931987275027546890690370753941304265231501194809377245048795150954100921645863754710598436791786391670211874924319957006419179697775990283006991536871371193661495281130587638027841075444973307840789923115535562561142322423255033685442488917353448899115014406480203690680639606723221932041495354150312888033953605329934036800697771065056663195481234880673210146739058568557934581403627822703280826165707739483275922328459417065250945123252306082291880205877731971983945018088807242966198081119777158542502016545090413245809786882778948721859617721078384350691861554356628840622574736922845095162084960398013400172393067166682355524525280460972253503534226472524250874054075591789781264330331690"; StringBuilder st = new StringBuilder(""); int i,ct=0,p=0; BigInteger res = BigInteger.valueOf(0); String a[] = new String[100]; for(i=0;i<5000;++i){ st.append(s.charAt(i)); ++ct; if(ct == 50){ a[p] = st.toString(); ct=0; ++p; st.setLength(0); } } //out.println(Arrays.toString(a)); for(String val: a){ res = res.add(new BigInteger(val)); } out.println(res.toString());*/ //out.println(helperFunction()); //String airports[] = {"AAA", "AAAA"}; //int i,n=airports.length; /* Maximum number of unique values in the array after performing given operations int a[] = {1,2,4,4}; int i,n = a.length,res=0; int mp[] = new int[n+2]; Arrays.sort(a); for(i=0;i<n;++i){ if(mp[a[i]] == 0) ++mp[a[i]]; else if(mp[a[i]+1] == 0) ++mp[a[i]+1]; else if(mp[a[i]-1] == 0) ++mp[a[i]-1]; } for(int val: mp){ if(val > 0) ++res; } out.println(res);*/ int tt = in.nextInt(); while(tt-->0){ long n = in.nextLong(); long k = in.nextLong(); long res=0,temp=1; while(n-temp>0 && temp<=k){ temp = temp*2; ++res; } //out.println(res+" "+temp); if(res>0){ /*The standard idiom for integer rounding up is: int a = (59 + (4 - 1)) / 4; You add the divisor(4) minus one to the dividend(59) */ res = res + (n-temp+k-1)/k; out.println(res); } else out.println(res); } 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 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
61fbb0ae1ead670b6960b4181fb7dd63
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 Test{ //Global declarations final static FastReader in = new FastReader(); final static PrintWriter out = new PrintWriter(System.out); public static void helperFunction(String s) { //Long range is -10^18 to 10^18 and is 64 bit (8 bytes) //Integer range is ~~ -2 * 10^9(-2^31) to 2 * 10^9(2^31 - 1) and is 32 bit (4 bytes) } public static void main(String ... args) throws IOException { // << --> multiply // >> --> divide //variable_name <<= 1 --> (variable)multiply by 2 //variable_name >>= 1 --> (variable)divide by 2 //2<<3 --> (multiply)2 * 2^3 --> 16; //6>>1 --> (divide)6 / 2^1 --> 3; /** int n = in.nextInt(),a,b; in.nextLine(); while(n-->0){ a = in.nextInt(); b = in.nextInt(); out.println(a+b); if(n>0) in.nextLine(); } out.close(); int tt = in.nextInt(); while(tt-->0){ out.println(helperFunction()); } //out.println(helperFunction()); **/ //it returns the remaining length (+ve) so bigger so swap //System.out.println("h".compareTo("ha")); /* Problem 13 - Large sum String s = "37107287533902102798797998220837590246510135740250463769376774900097126481248969700780504170182605387432498619952474105947423330951305812372661730962991942213363574161572522430563301811072406154908250230675882075393461711719803104210475137780632466768926167069662363382013637841838368417873436172675728112879812849979408065481931592621691275889832738442742289174325203219235894228767964876702721893184745144573600130643909116721685684458871160315327670386486105843025439939619828917593665686757934951621764571418565606295021572231965867550793241933316490635246274190492910143244581382266334794475817892575867718337217661963751590579239728245598838407582035653253593990084026335689488301894586282278288018119938482628201427819413994056758715117009439035398664372827112653829987240784473053190104293586865155060062958648615320752733719591914205172558297169388870771546649911559348760353292171497005693854370070576826684624621495650076471787294438377604532826541087568284431911906346940378552177792951453612327252500029607107508256381565671088525835072145876576172410976447339110607218265236877223636045174237069058518606604482076212098132878607339694128114266041808683061932846081119106155694051268969251934325451728388641918047049293215058642563049483624672216484350762017279180399446930047329563406911573244438690812579451408905770622942919710792820955037687525678773091862540744969844508330393682126183363848253301546861961243487676812975343759465158038628759287849020152168555482871720121925776695478182833757993103614740356856449095527097864797581167263201004368978425535399209318374414978068609844840309812907779179908821879532736447567559084803087086987551392711854517078544161852424320693150332599594068957565367821070749269665376763262354472106979395067965269474259770973916669376304263398708541052684708299085211399427365734116182760315001271653786073615010808570091499395125570281987460043753582903531743471732693212357815498262974255273730794953759765105305946966067683156574377167401875275889028025717332296191766687138199318110487701902712526768027607800301367868099252546340106163286652636270218540497705585629946580636237993140746255962240744869082311749777923654662572469233228109171419143028819710328859780666976089293863828502533340334413065578016127815921815005561868836468420090470230530811728164304876237919698424872550366387845831148769693215490281042402013833512446218144177347063783299490636259666498587618221225225512486764533677201869716985443124195724099139590089523100588229554825530026352078153229679624948164195386821877476085327132285723110424803456124867697064507995236377742425354112916842768655389262050249103265729672370191327572567528565324825826546309220705859652229798860272258331913126375147341994889534765745501184957014548792889848568277260777137214037988797153829820378303147352772158034814451349137322665138134829543829199918180278916522431027392251122869539409579530664052326325380441000596549391598795936352974615218550237130764225512118369380358038858490341698116222072977186158236678424689157993532961922624679571944012690438771072750481023908955235974572318970677254791506150550495392297953090112996751986188088225875314529584099251203829009407770775672113067397083047244838165338735023408456470580773088295917476714036319800818712901187549131054712658197623331044818386269515456334926366572897563400500428462801835170705278318394258821455212272512503275512160354698120058176216521282765275169129689778932238195734329339946437501907836945765883352399886755061649651847751807381688378610915273579297013376217784275219262340194239963916804498399317331273132924185707147349566916674687634660915035914677504995186714302352196288948901024233251169136196266227326746080059154747183079839286853520694694454072476841822524674417161514036427982273348055556214818971426179103425986472045168939894221798260880768528778364618279934631376775430780936333301898264209010848802521674670883215120185883543223812876952786713296124747824645386369930090493103636197638780396218407357239979422340623539380833965132740801111666627891981488087797941876876144230030984490851411606618262936828367647447792391803351109890697907148578694408955299065364044742557608365997664579509666024396409905389607120198219976047599490197230297649139826800329731560371200413779037855660850892521673093931987275027546890690370753941304265231501194809377245048795150954100921645863754710598436791786391670211874924319957006419179697775990283006991536871371193661495281130587638027841075444973307840789923115535562561142322423255033685442488917353448899115014406480203690680639606723221932041495354150312888033953605329934036800697771065056663195481234880673210146739058568557934581403627822703280826165707739483275922328459417065250945123252306082291880205877731971983945018088807242966198081119777158542502016545090413245809786882778948721859617721078384350691861554356628840622574736922845095162084960398013400172393067166682355524525280460972253503534226472524250874054075591789781264330331690"; StringBuilder st = new StringBuilder(""); int i,ct=0,p=0; BigInteger res = BigInteger.valueOf(0); String a[] = new String[100]; for(i=0;i<5000;++i){ st.append(s.charAt(i)); ++ct; if(ct == 50){ a[p] = st.toString(); ct=0; ++p; st.setLength(0); } } //out.println(Arrays.toString(a)); for(String val: a){ res = res.add(new BigInteger(val)); } out.println(res.toString());*/ //out.println(helperFunction()); //String airports[] = {"AAA", "AAAA"}; //int i,n=airports.length; /* Maximum number of unique values in the array after performing given operations int a[] = {1,2,4,4}; int i,n = a.length,res=0; int mp[] = new int[n+2]; Arrays.sort(a); for(i=0;i<n;++i){ if(mp[a[i]] == 0) ++mp[a[i]]; else if(mp[a[i]+1] == 0) ++mp[a[i]+1]; else if(mp[a[i]-1] == 0) ++mp[a[i]-1]; } for(int val: mp){ if(val > 0) ++res; } out.println(res);*/ int tt = in.nextInt(); while(tt-->0){ long n = in.nextLong(); long k = in.nextLong(); long res=0,temp=1; while(n-temp>0 && temp<=k){ temp = temp*2; ++res; } if(res>0){ res = res + ((n-temp+(k-1))/k); out.println(res); } else out.println(res); } 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 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
561669810763b7b6fe657ae035a75875
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 Substitute{ //Global declarations final static FastReader in = new FastReader(); final static PrintWriter out = new PrintWriter(System.out); public static void helperFunction() { //Long range is -10^18 to 10^18 and is 64 bit (8 bytes) //Integer range is ~~ -2 * 10^9(-2^31) to 2 * 10^9(2^31 - 1) and is 32 bit (4 bytes) } public static void main(String ... args) throws IOException { /* //to measure the execution time of the program we use the below line of code long start = System.nanoTime(); //p --> prime number array, there are total 78498 primes below one million int p[] = new int[78498]; //n is below one million, we are generating all the prime numbers below one million int n = 999999,i=0,j,ct=0,sum=0,temp=0,res=0,p1=0,p2=0; boolean prime_array [] = new boolean [n+1]; while(i<=n) { prime_array[i]=true; i++; } prime_array[0]=false; prime_array[1]=false; i=2; while(i*i<=n) { if(prime_array[i]==true) { for(j=2;i*j<=n;j++) prime_array[i*j]=false; } i++; } for(i=0;i<=n;i++) { if(prime_array[i]==true) p[ct++] = i; } //out.println(Arrays.toString(p)); j=0; for(i=0;i<78498;++i){ sum = p[i]; for(j=i+1;j<78498;++j){ sum +=p[j]; if(sum>=1000000) break; if(temp<j-i+1 && BigInteger.valueOf(sum).isProbablePrime(1)){ temp = j-i+1; p1 = i; p2 = j; res = sum; } } } out.println(res); //range between 3rd prime to 545th prime out.println(p1 + " " + p2); //in the end we also measure the time long end = System.nanoTime(); out.println(end-start);*/ //out.println(helperFunction()); /* int n = in.nextInt(); int i; int a[] = new int[n]; int b[] = new int[n]; for(i=0;i<n;++i){ a[i] = in.nextInt(); b[i] = in.nextInt(); } */ int tt = in.nextInt(); while(tt-->0){ long n = in.nextLong(); long k = in.nextLong(); long temp=1,res=0; if(k == 1){ out.println(n-1); continue; } while(temp<n && temp<=k){ temp = temp*2; ++res; } out.println(res + (n-temp+(k-1))/k); } 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 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
9998a4109f14c3dcc7ca2e4043844a3a
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 t; long n,k,i,ans; t=sc.nextInt(); while (t>0) { n=sc.nextLong(); k=sc.nextLong(); i=1; ans=0; if (k==1){System.out.println(n-1);} else { while (i<=k && i<n) { i*=2; ans++; } if (i<n) { n-=i; if (n<=k){ans++;} else {ans+=n/k; if (n%k!=0){ans++;}} } System.out.println(ans); } 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 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
7f66cbc2cc2b08a063b00d797131c830
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 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int mod = (int) (1e9 + 7); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long count = 0; long used = 1; while (used <= k && used < n) { count++; used *= 2; } if (used < n) { count += (n - used + k - 1) / k; } System.out.println(count); } sc.close(); return; } }
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
3076a56ab3c9731a24322e7db73ddeb6
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.StringTokenizer; public class updateFiles { public static void main(String[] args) { MyScanner sc= new MyScanner(); int input =sc.nextInt(); for(int i = 0 ; i < input; i++){ String[] series = sc.nextLine().split( " "); // System.out.println(number.length); System.out.println(minimum(series)); } } public static long minimum(String[] nums){ long hours = 1; long prev = 1; long k = Long.parseLong(nums[1]); long n = Long.parseLong(nums[0]); long left = n - 1; if(n == 1) return 0; for(int i = 1; i < n; i++){ if(prev <= k){ left -= prev; prev += prev; } // System.out.println("before "+prev + " "+left +" "+i); if (prev > k || left == 0){ hours = i; break; } // System.out.println(prev + " "+left +" "+i); } if (left <= 0) return hours; if(left % k == 0) hours += left /k; else hours += (left /k ) + 1; return hours ; } } 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 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 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
aac5b8ba9c043fb4e6154fae7edd9dec
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.util.StringTokenizer; public class B { public static void main(String[] args) { FastScanner sc=new FastScanner(); int t=sc.nextInt(); PrintWriter pw=new PrintWriter(System.out); while(t-->0) { long n=sc.nextLong(); long k=sc.nextLong(); long done=1; long ans=0; while(done<=k && done*2<n){ done*=2; ans++; } if((n-done)%k==0){ ans=ans+(n-done)/k; } else { ans=ans+1+(n-done)/k; } pw.println(ans); } pw.flush(); } 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 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
07a2283e7c73f1e8e68719cb7755ee99
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 static java.lang.Math.*; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; /* -> Give your 100%, that's it! -> Rules To Solve Any Problem: 1. Read the problem. 2. Think About It. 3. Solve it! */ public class Template { static int mod = 1000000007; public static void main(String[] args){ FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int yo = sc.nextInt(); ot: while (yo-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); if(n == 1){ out.println(0); continue; } long comp = 1; long time = 0; while(true){ if(comp > k) break; comp += comp; time++; if(comp >= n){ out.println(time); continue ot; } } time = time + ceilDiv(n-comp,k); out.println(time); } out.close(); } static long ceilDiv(long a, long b){ return a%b == 0 ? a/b : a/b+1; } /* Source: hu_tao Random stuff to try when stuck: - use bruteforcer - always check for n = 1, n = 2, so on -if it's 2C then it's dp -for combo/probability problems, expand the given form we're interested in -make everything the same then build an answer (constructive, make everything 0 then do something) -something appears in parts of 2 --> model as graph -assume a greedy then try to show why it works -find way to simplify into one variable if multiple exist -treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them) -find lower and upper bounds on answer -figure out what ur trying to find and isolate it -see what observations you have and come up with more continuations -work backwards (in constructive, go from the goal to the start) -turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements) -instead of solving for answer, try solving for complement (ex, find n-(min) instead of max) -draw something -simulate a process -dont implement something unless if ur fairly confident its correct -after 3 bad submissions move on to next problem if applicable -do something instead of nothing and stay organized -write stuff down Random stuff to check when wa: -if code is way too long/cancer then reassess -switched N/M -int overflow -switched variables -wrong MOD -hardcoded edge case incorrectly Random stuff to check when tle: -continue instead of break -condition in for/while loop bad Random stuff to check when rte: -switched N/M -long to int/int overflow -division by 0 -edge case for empty list/data structure/N=1 */ public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int N) { boolean[] sieve = new boolean[N + 1]; for (int i = 2; i <= N; i++) sieve[i] = true; for (int i = 2; i <= N; i++) { if (sieve[i]) { for (int j = 2 * i; j <= N; j += i) { sieve[j] = false; } } } return sieve; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } public static void print(int[] arr, PrintWriter out) { //for debugging only for (int x : arr) out.print(x + " "); out.println(); } public static int log2(int a){ return (int)(Math.log(a)/Math.log(2)); } static class FastScanner { 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[] readInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readLongs(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[] readDoubles(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; } } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream("input.txt"); // FileOutputStream out = new FileOutputStream("output.txt"); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }
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
bbb775e76a3d0cd965aefea6c3453d8f
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 static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; /* -> Give your 100%, that's it! -> Rules To Solve Any Problem: 1. Read the problem. 2. Think About It. 3. Solve it! */ public class Template { static int mod = 1000000007; public static void main(String[] args){ FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int yo = sc.nextInt(); ot: while (yo-- > 0) { long n = sc.nextLong(); long k = sc.nextLong(); long comp = 1; long rem = n-1; long ans = 0; while(rem > 0 && comp <= k){ rem -= comp; comp += comp; ans++; } if(rem > 0){ ans += (rem + k -1l)/k; } out.println(ans); } out.close(); } /* Source: hu_tao Random stuff to try when stuck: - use bruteforcer - always check for n = 1, n = 2, so on -if it's 2C then it's dp -for combo/probability problems, expand the given form we're interested in -make everything the same then build an answer (constructive, make everything 0 then do something) -something appears in parts of 2 --> model as graph -assume a greedy then try to show why it works -find way to simplify into one variable if multiple exist -treat it like fmc (note any passing thoughts/algo that could be used so you can revisit them) -find lower and upper bounds on answer -figure out what ur trying to find and isolate it -see what observations you have and come up with more continuations -work backwards (in constructive, go from the goal to the start) -turn into prefix/suffix sum argument (often works if problem revolves around adjacent array elements) -instead of solving for answer, try solving for complement (ex, find n-(min) instead of max) -draw something -simulate a process -dont implement something unless if ur fairly confident its correct -after 3 bad submissions move on to next problem if applicable -do something instead of nothing and stay organized -write stuff down Random stuff to check when wa: -if code is way too long/cancer then reassess -switched N/M -int overflow -switched variables -wrong MOD -hardcoded edge case incorrectly Random stuff to check when tle: -continue instead of break -condition in for/while loop bad Random stuff to check when rte: -switched N/M -long to int/int overflow -division by 0 -edge case for empty list/data structure/N=1 */ public static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void sort(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); for (int i = 0; i < arr.length; i++) arr[i] = ls.get(i); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int N) { boolean[] sieve = new boolean[N + 1]; for (int i = 2; i <= N; i++) sieve[i] = true; for (int i = 2; i <= N; i++) { if (sieve[i]) { for (int j = 2 * i; j <= N; j += i) { sieve[j] = false; } } } return sieve; } public static long power(long x, long y, long p) { long res = 1L; x = x % p; while (y > 0) { if ((y & 1) == 1) res = (res * x) % p; y >>= 1; x = (x * x) % p; } return res; } public static void print(int[] arr, PrintWriter out) { //for debugging only for (int x : arr) out.print(x + " "); out.println(); } public static int log2(int a){ return (int)(Math.log(a)/Math.log(2)); } static class FastScanner { 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[] readInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readLongs(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[] readDoubles(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; } } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream("input.txt"); // FileOutputStream out = new FileOutputStream("output.txt"); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }
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
640c5855cd22c67f190d7fec142254f1
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 whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static BufferedReader br; public static void main (String[] args) throws java.lang.Exception { br = new BufferedReader(new InputStreamReader(System.in)); int t= Integer.parseInt(br.readLine()); for(int i = 0 ; i < t ; i++){ StringTokenizer stk = new StringTokenizer(br.readLine()); long n= Long.parseLong(stk.nextToken())-1; long k= Long.parseLong(stk.nextToken()); long count = 1; long step = 0; while(n > 0){ n -= count; step++; if(n <= 0){ break; } if(2*count < k){ count = 2*count; } else{ count = k; n -= count; step++; break; } } //System.out.println(step+" "+n); if(n<0){ System.out.println(step); continue; } step += n/count; if(n%count != 0){ step++; } System.out.println(step); } } }
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
9c495a63775f0431574c755806251af3
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 cp { 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(); } } /* Iterative Function to calculate (x^y) in O(log y) */ static long power(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static int power(int x,int y) { if(y == 0) { return 1; } if(y % 2 == 0) { int temp = power(x,y/2)%1000000007; return temp*temp%1000000007; }else { return ((x%1000000007)*power(x,y-1))%1000000007; } } static long getPairsCount(int n, long sum,long arr[]) { HashMap<Long, Integer> hm = new HashMap<>(); // Store counts of all elements in map hm for (int i = 0; i < n; i++) { // initializing value to 0, if key not found if (!hm.containsKey(arr[i])) hm.put(arr[i], 0); hm.put(arr[i], hm.get(arr[i]) + 1); } long twice_count = 0; // iterate through each element and increment the // count (Notice that every pair is counted twice) for (int i = 0; i < n; i++) { if (hm.get(sum - arr[i]) != null) twice_count += hm.get(sum - arr[i]); // if (arr[i], arr[i]) pair satisfies the // condition, then we need to ensure that the // count is decreased by one such that the // (arr[i], arr[i]) pair is not considered if (sum - arr[i] == arr[i]) twice_count--; } // return the half of twice_count return twice_count / 2; } public static long check(int index,String str) { long count = 0; for(int i = 1;i <= 9 && index + i < str.length();i++) { if( Math.abs(str.charAt(index + i) - str.charAt(index)) == i) { count++; } } return count; } public static long[] primeFactors(long n) { // Print the number of 2s that divide n // Vector<Integer> v = new Vector<>(); long countEve = 0; long countOdd = 0; while (n%2==0) { // v.add(2); countEve++; n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { countOdd++; n /= i; } } // This condition is to handle the case when // n is a prime number greater than 2 if (n > 2) countOdd++; long ans[] = {countEve,countOdd}; return ans; } public static HashMap<Integer, Integer> sortByValue(HashMap<Integer, Integer> hm) { // Create a list from elements of HashMap List<Map.Entry<Integer, Integer> > list = new LinkedList<Map.Entry<Integer, Integer> >( hm.entrySet()); // Sort the list using lambda expression Collections.sort( list, (i1, i2) -> i1.getValue().compareTo(i2.getValue())); // put data from sorted list to hashmap HashMap<Integer, Integer> temp = new LinkedHashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> aa : list) { temp.put(aa.getKey(), aa.getValue()); } return temp; } public static void main(String[] args) throws IOException { try{ //Your Solve Reader s = new Reader(); // Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int p = 0;p < t;p++) { // // String str = s.next(); // int parts = 1; // int currLen = 1; // int currLenMin = Integer.MAX_VALUE; // int index = 0; // if(str.length() == 1) { // System.out.println(str); // }else { // for(int i = 0;i < str.length()-1;i++) { // if(str.charAt(i) != str.charAt(i+1)) { // if(currLen < currLenMin) { // currLenMin = currLen; // index = i; // } // parts++; // currLen = 1; // }else { // currLen++; // } // } // if(currLen < currLenMin) { // currLenMin = currLen; // index = str.length()-1; // } // if(str.charAt(str.length()-2) != str.charAt(str.length()-1)) { // index = str.length()-1; // currLenMin = 1; // } // //// System.out.println(parts); //// System.out.println(currLenMin); // if(parts%2 == 1) { // System.out.println(str); // }else { // int startIndex = index-currLenMin+1; // String mid = ""; // for(int i = 0;i < currLenMin;i++) { // if(index+1 < str.length()) { // mid += str.charAt(index+1); // }else { // mid += str.charAt(startIndex-1); // } // } // System.out.println(str.substring(0, startIndex) + mid + str.substring(index+1)); // // } // } long n = s.nextLong(); long k = s.nextLong(); long hour = 0; long sumHour = 1; while(sumHour < k && sumHour < n) { sumHour += Math.min(k, sumHour); hour++; } if(sumHour >= n) { System.out.println(hour); }else { System.out.println(hour + (n-sumHour+k-1)/k); } } }catch(Exception e){ return; } } }
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
e1d9eb33cf58483984b2a8b945b05f08
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 Code { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { long n=sc.nextLong(), k=sc.nextLong(); long hour=0, copied=1; while(copied < k) { copied *= 2; hour++; } if(copied < n) { long add = (n-copied+k-1)/k; hour += add; } System.out.println(hour); } 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 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
269bcfd81f3af39cfd3bad2f9a59f0cf
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; import java.util.function.Function; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()," "); Function<String,Integer> stoi = Integer::parseInt; Function<String,Long> stol = Long::parseLong; int testCnt = stoi.apply(st.nextToken()); for(int t = 0 ; t < testCnt ; t++){ st = new StringTokenizer(br.readLine()," "); long n = stol.apply(st.nextToken()) - 1; long k = stol.apply(st.nextToken()); long result = 0; for(long i = 1 ; i <= k ; i *= 2){ if(n <= 0) { break; } n -= i; result++; } // System.out.println(n+" "+result); if(n > 0){ result += n/k + ((n % k != 0)? 1 : 0); } System.out.println(result); } } }
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
46807e96442c1f2d10a87151438707dd
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.*; /** __ __ ( _) ( _) / / \\ / /\_\_ / / \\ / / | \ \ / / \\ / / |\ \ \ / / , \ , / / /| \ \ / / |\_ /| / / / \ \_\ / / |\/ _ '_| \ / / / \ \\ | / |/ 0 \0\ / | | \ \\ | |\| \_\_ / / | \ \\ | | |/ \.\ o\o) / \ | \\ \ | /\\`v-v / | | \\ | \/ /_| \\_| / | | \ \\ | | /__/_ `-` / _____ | | \ \\ \| [__] \_/ |_________ \ | \ () / [___] ( \ \ |\ | | // | [___] |\| \| / |/ /| [____] \ |/\ / / || ( \ [____ / ) _\ \ \ \| | || \ \ [_____| / / __/ \ / / // | \ [_____/ / / \ | \/ // | / '----| /=\____ _/ | / // __ / / | / ___/ _/\ \ | || (/-(/-\) / \ (/\/\)/ | / | / (/\/\) / / // _________/ / / \____________/ ( */ 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 hour=0; long no=1; while(no<k) { no=no*2; hour++; } long a=n-no; long b=k; if(no>n) { } else if(a%b==0) { hour+=a/b; } else { hour+=(a/b)+1; } System.out.println(hour); } } }
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
a68a18c067a950a6757be0a59b57295e
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.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main1606B { public static void main(String[] args) { final FastScanner in = new FastScanner(System.in); final PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for (int i = 0; i < t; i++) { long n = in.nextLong(); long k = in.nextLong(); out.println(solution(n, k)); } out.flush(); out.close(); in.close(); } private static long solution(long n, long k) { long computer = 1; long remaining = n - 1; long time = 0; while (remaining > 0 && computer <= k) { time++; remaining -= computer; computer *= 2; } if (remaining > 0) { time += remaining / k; if (remaining % k != 0) time++; } return time; } private static long max(long a, long b) { return a > b ? a : b; } private static long min(long a, long b) { return a < b ? a : b; } private static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readIntArr(int n) { int[] result = new int[n]; for (int i = 0; i < n; i++) { result[i] = Integer.parseInt(next()); } return result; } long[] readLongArr(int n) { long[] result = new long[n]; for (int i = 0; i < n; i++) { result[i] = Long.parseLong(next()); } return result; } void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } 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 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
4fdd64778dc053aace22c682666e59a9
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 codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class codeforces{ public static void main(String[] args){ FastScanner s=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int t=s.nextInt(); for(int tt=0;tt<t;tt++) { long n=s.nextLong(),k=s.nextLong(); long d=1; long ans=0,rem=1; while(d<k && rem<n){ rem+=(d); d*=2; ans++; } if(rem<n) { ans+=(n-rem+k-1)/k; } out.println(ans); } out.close(); } static int isPrime(long n){ HashSet<Long> set=new HashSet<>(); if (n <= 1) return 1; for (long i = 2; i <= Math.sqrt(n); i ++){ if (n % i == 0) { set.add(i); //System.out.println(i+" "+n/i); set.add(n/i); } } return set.size()+1; } public static void printb(boolean ans) { if(ans) { System.out.println("Yes"); }else { System.out.println("No"); } } static void sort(long [] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(int [] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b); } static void sortcol(int a[][],int c) { Arrays.sort(a, (x, y) -> { if(x[c]>y[c]) { return 1; }else { return -1; } }); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } double nextDouble() { return Double.parseDouble(next()); } int nextInt() { return Integer.parseInt(next()); } boolean nextBoolean() { return Boolean.parseBoolean(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[] readLongArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } } } class Pair implements Comparable<Pair>{ int a,b ; Pair(int a,int b){ this.a=a; this.b=b; } public int compareTo(Pair o) { return a-o.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 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
7c293e4d6a9b2785ee7ac80d63723da1
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 { //----------- StringBuilder for faster output------------------------------ static StringBuilder out = new StringBuilder(); public static void main(String[] args) { FastScanner fs=new FastScanner(); /****** CODE STARTS HERE *****/ int t = fs.nextInt(); while(t-->0) { long n=fs.nextLong(), k=fs.nextLong(); if(n==1) { out.append("0\n"); continue; } long cnt = 0; long N = 1; while(N <= k && N < n) {N*=2; cnt++;} n -= N; if(n<0)n=0; long x = n / k + ((n % k == 0) ? 0 : 1); cnt += x; out.append(cnt+"\n"); } System.out.print(out); } 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); } //----------- FastScanner class for faster input--------------------------- 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 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
38ee4ebad057e611a91182671210b561
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 codeforces; import java.util.Scanner; public class UpdateFiles { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { long n = in.nextLong(); long k = in.nextLong(); long connected = 1, time = 0L; while (connected <= k) { connected <<= 1; time++; } long disconnected = n - connected; time += disconnected / k; System.out.println(disconnected % k > 0 ? time + 1 : 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 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
989160e3d00c4e1f7bdbc72e9fdb2a22
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.*; import java.util.*; public class Template { static InputReader inputReader=new InputReader(System.in); static void solve() { long n=inputReader.nextLong(); long k=inputReader.nextLong(); long ini=1; long time=0; while (ini<=k&&ini<n) { ini=ini*2; time++; } if (ini<n) { time += (n - ini) / k; if ((n - ini) % k != 0) { time++; } } out.println(time); } int power(long val) { int low=0; int high=62; int res=-1; while (low<=high) { int mid=low+(high-low)/2; if (Math.pow(2,mid)>=val) { res=mid; high=mid-1; } else { low=mid+1; } } return res; } static PrintWriter out=new PrintWriter((System.out)); public static void main(String args[])throws IOException { int t=inputReader.nextInt(); while(t-->0) { solve(); } out.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(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 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
5f03ed9d271416148444c3eaa073f271
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 Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); for (int i = 0; i < t; i++) { long n = sc.nextLong(); long k = sc.nextLong(); long pow = logg(k); long half = power(2,pow); long remain = n - half; if (remain <=0 ) { System.out.println(pow); } else { remain = (remain + k - 1) / k; System.out.println(remain + pow); } } } static long logg(long k) { long ans = 0; long kk = 1 ; while (kk < k) { kk= kk*2; ans++; } return ans; } static long power(long x, long y) { long res = 1; if (x == 0) return 0; while (y > 0) { if (y % 2 == 1) { res = (res * x); } y = y /2; // y = y/2 x = (x * x) ; } return 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
PASSED
36de80bed4e6beac0a02f5b208ed813f
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 Solution{ static FastScanner sc = new FastScanner(); public static void solve() { long n=sc.nextLong(); long k=sc.nextLong(); long tmp=1l,res=0l; while(tmp<=k && tmp<n){ tmp*=2;res++; } if(tmp<n){ res=res+(n-tmp+k-1)/k; } System.out.println(res); } public static void main(String[] args) { int t = sc.nextInt(); // int t=1; outer: for (int tt = 0; tt < t; tt++) { solve(); } } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } public static int[] LPS(String s){ int[] lps=new int[s.length()]; int i=0,j=1; while (j<s.length()) { if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; j++; continue; }else{ if (i==0) { j++; continue; } i=lps[i-1]; while(s.charAt(i)!=s.charAt(j) && i!=0) { i=lps[i-1]; } if(s.charAt(i)==s.charAt(j)){ lps[j]=i+1; i++; } j++; } } return lps; } static long getPairsCount(int n, double sum,int[] arr) { HashMap<Double, Integer> hm = new HashMap<>(); for (int i = 0; i < n; i++) { if (!hm.containsKey((double)arr[i])) hm.put((double)arr[i], 0); hm.put((double)arr[i], hm.get((double)arr[i]) + 1); } long twice_count = 0; for (int i = 0; i < n; i++) { if (hm.get(sum - arr[i]) != null) twice_count += hm.get(sum - arr[i]); if (sum - (double)arr[i] == (double)arr[i]) twice_count--; } return twice_count / 2l; } static boolean[] sieveOfEratosthenes(int n) { boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } return prime; } static long power(long x, long y, long p) { long res = 1l; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y>>=1; x = (x * x) % p; } return res; } public static int log2(int N) { int result = (int)(Math.log(N) / Math.log(2)); return result; } //////////////////////////////////////////////////////////////////////////////////// ////////////////////DO NOT READ AFTER THIS LINE ////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// static long modFact(int n, int p) { if (n >= p) return 0; long result = 1l; for (int i = 3; i <= n; i++) result = (result * i) % p; return result; } static boolean isPalindrom(char[] arr, int i, int j) { boolean ok = true; while (i <= j) { if (arr[i] != arr[j]) { ok = false; break; } i++; j--; } return ok; } static int max(int a, int b) { return Math.max(a, b); } static int min(int a, int b) { return Math.min(a, b); } static long max(long a, long b) { return Math.max(a, b); } static long min(long a, long b) { return Math.min(a, b); } static int abs(int a) { return Math.abs(a); } static long abs(long a) { return Math.abs(a); } static void swap(long arr[], int i, int j) { long temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static void swap(int arr[], int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static int maxArr(int arr[]) { int maxi = Integer.MIN_VALUE; for (int x : arr) maxi = max(maxi, x); return maxi; } static int minArr(int arr[]) { int mini = Integer.MAX_VALUE; for (int x : arr) mini = min(mini, x); return mini; } static long maxArr(long arr[]) { long maxi = Long.MIN_VALUE; for (long x : arr) maxi = max(maxi, x); return maxi; } static long minArr(long arr[]) { long mini = Long.MAX_VALUE; for (long x : arr) mini = min(mini, x); return mini; } static int lcm(int a,int b){ return (int)(((long)a*b)/(long)gcd(a,b)); } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n); int temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } public static int binarySearch(int a[], int target) { int left = 0; int right = a.length - 1; int mid = (left + right) / 2; int i = 0; while (left <= right) { if (a[mid] <= target) { i = mid + 1; left = mid + 1; } else { right = mid - 1; } mid = (left + right) / 2; } return i-1; } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] read2dArray(int n, int m) { int arr[][] = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr[i][j] = nextInt(); } } return arr; } ArrayList<Integer> readArrayList(int n) { ArrayList<Integer> arr = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { int a = nextInt(); arr.add(a); } return arr; } long nextLong() { return Long.parseLong(next()); } } static class Pair { int l, r; Pair(int fr, int sc) { this.l = fr; this.r = sc; } } }
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
0a6b2e640dd75b907fd176fc5bad74be
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.StringTokenizer; 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()); long[] comp = new long[t]; long[] cable = new long[t]; StringTokenizer st; for (int i = 0; i < t; i++) { st = new StringTokenizer(br.readLine()); comp[i] = Long.parseLong(st.nextToken()); cable[i] = Long.parseLong(st.nextToken()); } long c; long j; for (int i = 0; i < t; i++) { c = 0; j = 1; for (j = 1; j < cable[i] && j < Long.MAX_VALUE/2; j*=2) c++; if(j > Long.MAX_VALUE && j < cable[i]) c++; if(j < comp[i] && j < Long.MAX_VALUE/2) { c += (comp[i] - j)/cable[i]; if((comp[i] - j)%cable[i] != 0) c++; } 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 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
e044a1cc186986200ffa4202ac12ba4a
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 B { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = Integer.parseInt(scanner.nextLine()); for (int x = 0; x < t; x++) { long n = scanner.nextLong(); long k = scanner.nextLong(); long result = 1L, time = 0L; while (n > 1 && result < n) { if (result < k) result *= 2; else { n -= result; long mod = n % k; time += n / k; if (mod > 0L) time++; break; } 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 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
45bb759408ac0d41af60ae11bb4bf4dd
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.nio.file.FileStore; import java.util.*; public class zia { static boolean prime[] = new boolean[25001]; static void BFS(ArrayList<ArrayList<Integer>> adj,int s, boolean[] visited) { Queue<Integer> q=new LinkedList<>(); visited[s] = true; q.add(s); while(q.isEmpty()==false) { int u = q.poll(); for(int v:adj.get(u)){ if(visited[v]==false){ visited[v]=true; q.add(v); } } } } static void addEdge(ArrayList<ArrayList<Integer>> adj, int u, int v) { adj.get(u).add(v); adj.get(v).add(u); } static void ruffleSort(int[] a) { int n=a.length; Random random = new Random(); 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); } public static int Lcm(int a,int b) { int max=Math.max(a,b); for(int i=1;;i++) { if((max*i)%a==0&&(max*i)%b==0) return (max*i); } } static void sieve(int n,boolean prime[]) { // 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 =i+ p) prime[i] = false; } } } // public static String run(int ar[],int n) // { // } public static int upperbound(int s,int e, long ar[],long x) { int res=-1; while(s<=e) { int mid=((s-e)/2)+e; if(ar[mid]>x) {e=mid-1;res=mid;} else if(ar[mid]<x) {s=mid+1;} else {e=mid-1;res=mid; if(mid>0&&ar[mid]==ar[mid-1]) e=mid-1; else break; } } return res; } public static long lowerbound(int s,int e, long ar[],long x) { long res=-1; while(s<=e) { int mid=((s-e)/2)+e; if(ar[mid]>x) {e=mid-1;} else if(ar[mid]<x) {s=mid+1;res=mid;} else {res=mid; if(mid+1<ar.length&&ar[mid]==ar[mid+1]) s=mid+1; else break;} } return res; } static long modulo=1000000007; public static long power(long a, long b) { if(b==0) return 1; long temp=power(a,b/2)%modulo; if((b&1)==0) return (temp*temp)%modulo; else return (((temp*temp)%modulo)*a)%modulo; } public static long powerwithoutmod(long a, long b) { if(b==0) return 1; long temp=power(a,b/2); if((b&1)==0) return (temp*temp); else return ((temp*temp)*a); } public static double log2(long a) { double d=Math.log(a)/Math.log(2); return d; } public static int log10(long a) { double d=Math.log(a)/Math.log(10); return (int)d; } public static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } public static void tree(int s,int e,int ar[],int c) { if(s<=e) { int max=s; for(int i=s;i<=e;i++) if(ar[i]>ar[max]) max=i; ar[max]=c++; tree(s,max-1,ar,c); tree(max+1,e,ar,c); } } public static void main(String[] args) throws Exception { FastIO sc = new FastIO(); //sc.println(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CODE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx int test=sc.nextInt(); // // double c=Math.log(10); // boolean prime[]=new boolean[233334]; // sieve(233334, prime); // HashMap<Character,Integer> hm=new HashMap<>(9); // char c='1'; // for(int i=1;i<=9;i++) // hm.put(c++,i); while(test-->0) { long n=sc.nextLong(); long k=sc.nextLong(); if(n==1) sc.println("0"); else if(n<=2*k) { long exp=0; long TwoPower=1; while(TwoPower<n) { TwoPower=TwoPower<<1; exp++; } sc.println(exp); } else { long exp=0; long TwoPower=1; while(TwoPower<2*k) { TwoPower=TwoPower<<1; if(TwoPower>2*k) {TwoPower=TwoPower>>1;break;} exp++; } // sc.println(exp); long res=exp; n=n-TwoPower; if(n%k==0) res=res+n/k; else res=res+n/k+1; // res=res+(long)Math.ceil(n/((double)k)); // sc.println(n+" "+" "+k+Math.ceil(n/((double)k))); sc.println(res); } } // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CODE xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx sc.close(); } } class pair implements Comparable<pair>{ int a; int b; pair(int a,int b) {this.a=a; this.b=b; } public int compareTo(pair p) { return (this.a-p.a); } } class triplet implements Comparable<triplet>{ int first,second,third; triplet(int first,int second,int third) {this.first=first; this.second=second; this.third=third; } public int compareTo(triplet p) { if(this.third-p.third==0) return this.first-p.first; else return -this.third+p.third; } } // class triplet // { // int x1,x2,i; // triplet(int a,int b,int c) // {x1=a;x2=b;i=c;} // } 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++]; } 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 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 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 <= ' '); long 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; } 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 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
102fddaa9e98a6c2f0b8cd2eaf83e61c
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
/** * @author -- Sourav Joshi */ import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.*; import static java.lang.Math.*; public class Solution { /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static FastScanner s = new FastScanner(); static FastWriter out = new FastWriter(); final static int mod = (int)1e9 + 7; final static int INT_MAX = Integer.MAX_VALUE; final static int INT_MIN = Integer.MIN_VALUE; final static long LONG_MAX = Long.MAX_VALUE; final static long LONG_MIN = Long.MIN_VALUE; final static double DOUBLE_MAX = Double.MAX_VALUE; final static double DOUBLE_MIN = Double.MIN_VALUE; final static float FLOAT_MAX = Float.MAX_VALUE; final static float FLOAT_MIN = Float.MIN_VALUE; /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static class FastScanner{BufferedReader br;StringTokenizer st; public FastScanner() {br = new BufferedReader(new InputStreamReader(System.in));} String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();} int nextInt(){return Integer.parseInt(next());} long nextLong(){return Long.parseLong(next());} double nextDouble(){return Double.parseDouble(next());} List<Integer> readIntList(int n){List<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextInt()); return arr;} List<Long> readLongList(int n){List<Long> arr = new ArrayList<>(); for(int i = 0; i < n; i++) arr.add(s.nextLong()); return arr;} int[] readIntArr(int n){int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = s.nextInt(); return arr;} long[] readLongArr(int n){long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = s.nextLong(); return arr;} String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}} static class FastWriter{private final BufferedWriter bw;public FastWriter() {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));} public void print(Object object) throws IOException{bw.append(""+ object);} public void println(Object object) throws IOException{print(object);bw.append("\n");} public void debug(int object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void debug(long object[]) throws IOException{bw.append("["); for(int i = 0; i < object.length; i++){if(i != object.length-1){print(object[i]+", ");}else{print(object[i]);}}bw.append("]\n");} public void close() throws IOException{bw.close();}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(int i = 2; i <= n; i++) {if(arr[i] == 1) {continue;}else {list.add(i);for(int j = i*i; j <= n; j = j + i) {arr[j] = 1;}}}return list;} public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);} public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];} public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;} public static long mod_add(long a, long b){ return (a%mod + b%mod)%mod;} public static long mod_sub(long a, long b){ return (a%mod - b%mod + mod)%mod;} public static long mod_mul(long a, long b){ return (a%mod * b%mod)%mod;} public static long modInv(long a, long b){ return expo(a, b-2)%b;} public static long mod_div(long a, long b){return mod_mul(a, modInv(b, mod));} public static long expo (long a, long n){if(n == 0){return 1;}long recAns = expo(mod_mul(a,a), n/2);if(n % 2 == 0){return recAns;}else{return mod_mul(a, recAns);}} /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Pair class public static class Pair<X extends Comparable<X>,Y extends Comparable<Y>> implements Comparable<Pair<X, Y>>{ X first; Y second; public Pair(X first, Y second){ this.first = first; this.second = second; } public String toString(){ return "( " + first+" , "+second+" )"; } @Override public int compareTo(Pair<X, Y> o) { int t = first.compareTo(o.first); if(t == 0) return -1*second.compareTo(o.second); return t; } } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ // Code begins public static void solve() throws IOException { long n = s.nextLong(); long c = s.nextLong(); long ans = 0; long curr = 1; while(curr < c){ curr *= 2l; ans++; } if(curr < n) ans += (n-curr+c-1)/c; System.out.println(ans); } /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ public static void main(String[] args) throws IOException { int test = s.nextInt(); for(int tt = 1; tt <= test; tt++) { solve(); } 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
2a1b4fad1558f1788ebbec7580d22858
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 static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class D { static int mod=(int)1e9+7; public static void main(String[] args) { var io = new Copied(System.in, System.out); // int k=1; int t = 1; t = io.nextInt(); for (int i = 0; i < t; i++) { // out.println("Case #" + k + ": "); solve(io); // k++; } io.close(); } public static void solve(Copied io) { long n=io.nextLong(),k=io.nextLong(); long hpt=1,ans=0; while(hpt<k){ hpt*=2; ans++; } if(n>hpt){ ans+=((n-hpt+k-1)/k); } io.println(ans); } public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static void printArr(int[] arr) { for (int x : arr) System.out.print(x + " "); System.out.println(); } public static int[] listToInt(ArrayList<Integer> a){ int n=a.size(); int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=a.get(i); } return arr; } static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} } class Pair { int a,b; Pair(int a,int b) { this.a=a; this.b=b; } } class DescendingOrder<T> implements Comparator<T>{ @Override public int compare(Object o1,Object o2){ // -1 if want to swap and (1,0) otherwise. int addingNumber=(Integer) o1,existingNumber=(Integer) o2; if(addingNumber>existingNumber) return -1; else if(addingNumber<existingNumber) return 1; else return 0; } } class Copied extends PrintWriter { public Copied(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Copied(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public String next() { return nextToken(); } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; 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 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
412ebea91cebc6384965d1e916c1abef
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 static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class D { static int mod=(int)1e9+7; public static void main(String[] args) { var io = new Copied(System.in, System.out); // int k=1; int t = 1; t = io.nextInt(); for (int i = 0; i < t; i++) { // out.println("Case #" + k + ": "); solve(io); // k++; } io.close(); } public static void solve(Copied io) { long n=io.nextLong(),k=io.nextLong(); long cur=1,ans=0; while (cur < k) { cur *= 2; ++ans; } if (cur < n) ans += (n - cur + k - 1) / k; io.println(ans); } public static String sortString(String inputString) { char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } static int power(int x, int y, int p) { int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } public static void printArr(int[] arr) { for (int x : arr) System.out.print(x + " "); System.out.println(); } public static int[] listToInt(ArrayList<Integer> a){ int n=a.size(); int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=a.get(i); } return arr; } static int mod_mul(int a, int b){ a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;} static int mod_add(int a, int b){ a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;} static int mod_sub(int a, int b){ a = a % mod; b = b % mod; return (((a - b) % mod) + mod) % mod;} } class Pair { int a,b; Pair(int a,int b) { this.a=a; this.b=b; } } class DescendingOrder<T> implements Comparator<T>{ @Override public int compare(Object o1,Object o2){ // -1 if want to swap and (1,0) otherwise. int addingNumber=(Integer) o1,existingNumber=(Integer) o2; if(addingNumber>existingNumber) return -1; else if(addingNumber<existingNumber) return 1; else return 0; } } class Copied extends PrintWriter { public Copied(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Copied(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int nextInt() { return Integer.parseInt(nextToken()); } public double nextDouble() { return Double.parseDouble(nextToken()); } public long nextLong() { return Long.parseLong(nextToken()); } public String next() { return nextToken(); } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; 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 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
24d3ebf6d8734f49fd327586f18b9051
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.reflect.Array; import java.util.*; import java.lang.*; import java.io.*; public class practice { public static void main(String[] args) throws IOException { Reader.init(System.in); int t = Reader.nextInt(); while(t-->0){ long n = Reader.nextLong(); long k = Reader.nextLong(); if(n==1){ System.out.println(0); continue; } long curr = 1; long ans = 0; n--; while(k>=curr && n>0){ n-=curr; curr*=2; ans++; } if(n>0) ans += (n+k-1)/k; System.out.println(ans); } // double var = (double) 1/2 + (double) 1/3 + (double) 1/4 + (double) 1/6 + (double) 1/12 + 1; // System.out.println(var); // int n = Reader.nextInt(); // int k = Reader.nextInt(); // int x = Reader.nextInt(); // // int[] arr = new int[n]; // // for(int i = 0;i<n;i++){ // arr[i] = Reader.nextInt(); // } // // int i = 0, j = 0; // long sum = 0; // long ans = 0; // while(j<n){ // sum+=arr[j]; // if(j-i+1<k){ // j++; // } // else{ // if(sum>x){ // // ans += sum-x; // sum-=arr[i]; // // i++; // // sum = Math.max(k-1,sum-x); // j++; // // } // else{ // sum-=arr[i]; // i++; // j++; // } // } // } // System.out.println(ans); } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static long nextLong() throws IOException{ return Long.parseLong(next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } }
Java
["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
ce031143b1e0daf79b6175d6bc37ad47
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 UpdateFiles { 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 cur = 1; int temp = 1; long c = 0; while (cur < n && cur <= k) { cur *= 2; c++; } if(cur < n) { c += (n - cur + k - 1) / k; } 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 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
de559cddced11d407d2158287fb21f95
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 { static class pair { long x; long y; pair(long x,long y) { this.x=x; this.y=y; } // public int compareTo(pair st){ // if(x==st.x) // { // return st.y-y; // } // else if(x>st.x) // return 1; // else // return -1; // } } public static ArrayList<Integer> primenogeneration() { ArrayList<Integer> al=new ArrayList<>(); for(int i=2;i<1000000;i++) {boolean flag=true; for(int j=2;j*j<=i;j++) { if(i%j==0){ flag=false; break; } } if(flag)al.add(i); } return al; } public static int kadane_front(int arr[]) { int n=arr.length; int best=0; int curr=0; for(int i=0;i<n;i++) { curr+=arr[i]; best=Math.max(best,curr); } // best=Math.max(best,curr); return best; } public static int kadane_end(int arr[]) { int n=arr.length; int best=0; int curr=0; for(int i=n-1;i>=0;i--) { if(curr<0) { curr=arr[i]; break; }else { curr+=arr[i]; } best=Math.max(best,curr); } best=Math.max(best,curr); return best; } public static long ceil_div(long a, long b) { return (a + b - 1) / b; } public static boolean is_power(long a) { int count=0; while(a!=0) { int x=(int)(a&1); count+=x; a=a>>1; } if(count==1) return true; return false; } public static int getpower(long a) { if(is_power(a)){ int count=0; while(a!=0) { int x=(int)(a&1); if(x==1)return count; count++; a=a>>1; } }else { return -1; } return 0; } public static void swap(int []arr,int i,int j) { int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } public static boolean fun(int n) { int num=n%10; while(n!=0) { if(num!=n%10)return false; n/=10; } return true; } public static long gcd(long a,long b) { while(b!=0) {long rem=a%b; a=b; b=rem; } return a; } public static boolean same(String str) { if(str.charAt(1)!=str.charAt(0))return false; return true; } public static boolean patt(char[]arr,int i) { if(arr[i]=='a') { if(i+1>=arr.length || i+2>=arr.length)return false; else{ if(arr[i+1]=='b'&&arr[i+2]=='c')return true; return false; } }else if(arr[i]=='b') { if(i-1<0 || i+1>=arr.length)return false; else{ if(arr[i-1]=='a'&&arr[i+1]=='c')return true; return false; } }else { if(i-2<0 || i-1<0)return false; else{ if(arr[i-1]=='b'&&arr[i-2]=='a')return true; return false; } } } public static pair max(long a) { long ans=1; long hours=0; while(ans<a) { ans=ans<<1; hours++; } return new pair(ans,hours); } public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long a=sc.nextLong(); long b=sc.nextLong(); pair p=max(b); // System.out.println(p.x+" "+p.y); a=a-p.x; // System.out.println(a); System.out.println(p.y+((a+b-1)/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 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
fe353b606e8aa256a709c0e7d4f44d71
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
/* AUTHOR-> HARSHIT AGGARWAL CODEFORCES HANDLE-> @harshit_agg FROM-> MAHARAJA AGRASEN INSTITUE OF TECHNOLOGY >> YOU CAN DO THIS << */ import java.util.*; import java.io.*; public class updatefilescf { public static void main(String[] args) throws Exception { int t = scn.nextInt(); while (t-- > 0) { solver(); } } public static void solver() { long n = scn.nextLong(); long k = scn.nextLong(); // long currk = 1; long computerdone = 1; long ans = 0; while(computerdone < n){ if(computerdone < k){ computerdone *= 2; ++ans; } else{ ans += (long)(n-computerdone+k-1)/k;break; } } System.out.println(ans); } //-------------------------------- HO JA BHAI ---------------------------------------------------- /* code ends here*/ //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx U T I L I T I E S xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx public static class Debug { public static final boolean LOCAL = System.getProperty("LOCAL")==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)+"}"; }else if(t instanceof long[]) { String s = Arrays.toString((long[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof char[]) { String s = Arrays.toString((char[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof double[]) { String s = Arrays.toString((double[]) t); return "{"+s.substring(1, s.length()-1)+"}"; }else if(t instanceof boolean[]) { String s = Arrays.toString((boolean[]) t); return "{"+s.substring(1, s.length()-1)+"}"; } 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) { if(LOCAL) { 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("]"); } } } static 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()); } float nextFloat() { return Float.parseFloat(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int INF = (int) 1e9 + 7; // static int INF = 998244353; static int MAX = Integer.MAX_VALUE; // static int MAX = 2147483647 static int MIN = Integer.MIN_VALUE; // static int MIN = -2147483647 static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return this.first- o.first; } } static class LongPair { long first; long second; LongPair(long a, long b) { this.first = a; this.second = b; } } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static int LowerBound(long a[], long x) { /* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } public static int LowerBound(int a[], int x) { /* x is the key or target value */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; } static int LowerBoundList(ArrayList<Integer> a, int x) { /* x is the key or target value */int l = -1, r = a.size(); while (l + 1 < r) { int m = (l + r) >>> 1; if (a.get(m) >= x) r = m; else l = m; } return r; } static boolean[] prime; public static void sieveOfEratosthenes(int n) { 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; } } } public static int UpperBound(long a[], long x) {/* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } public static int UpperBound(int a[], int x) {/* x is the key or target value */int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void swap(int[] arr, int i, int j) { if (i != j) { arr[i] ^= arr[j]; arr[j] ^= arr[i]; arr[i] ^= arr[j]; } } public static long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = scn.nextLong(); return a; } public static int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scn.nextInt(); } return a; } public int[][] nextIntMatrix(int n, int m) { int[][] grid = new int[n][m]; for (int i = 0; i < n; i++) { grid[i] = nextIntArray(m); } return grid; } public static int smallest_divisor(int n) { int i; for (i = 2; i <= Math.sqrt(n); ++i) { if (n % i == 0) { return i; } } return n; } public static FastReader scn = new FastReader(); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx }
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
93aa882bbd006503a32a5b59fdffe30d
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
/* Rating: ---- Date: 13/11/21/ Time: 6:18 AM Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void s() { long n = sc.nextLong(), k = sc.nextLong(); long curr = 1; long time = 0; while (n > curr) { if(curr >= k) { long req = n - curr; time += req/k; req = req%k; if(req > 0) time++; break; } else { curr += curr; } time++; } p.writeln(time); } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long[] a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int[] a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { strb.append(str).append(" "); } public void writeln(Object str) { strb.append(str).append("\n"); } public void writeln() { strb.append('\n'); } public void writes(int[] arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long[] arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int[] arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } 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()); } 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; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } 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 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
45ed306dfcb4a57df5aff6e42aaa9b45
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 Solution { long log(long num) { long count=0; while(num>0) { num=num/2; if(num>0) count++; } return count; } long pow(long exp) { if(exp==0) return 1; return 2*pow(exp-1); } long getTime(long N,long K) { if(N==1) return 0; long count=log(N+1); N--; if(pow(count)<=K) { long temp=pow(count); if(temp>N) return count; else return count+1; } count=log(K)+1; N-=(pow(count)-1); if(N>0) if(N%K==0) return count+N/K; else return count+N/K+1; return count; } public static void main(String args[]) { Scanner sc=new Scanner(System.in); Solution ob=new Solution(); int T,k; long N,K; T=sc.nextInt(); for(k=1;k<=T;k++) { N=sc.nextLong(); K=sc.nextLong(); System.out.println(ob.getTime(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 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
2a813b70792264fc9f32856a1bb7c8f5
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.util.Collections.*; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n-->0){ Long a,b; a=sc.nextLong(); b=sc.nextLong(); Long ans=0l,cur=1l; while(a>cur && b>=cur ){ cur*=2; ans+=1; } System.out.println(ans+((a-cur+b-1))/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 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
e131ea8dd52bc2f98ffccddc3a3288a7
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 B { public static void main(String[] args) { Scanner go = new Scanner(System.in); int t = go.nextInt(); while (t>=0 && go.hasNext()){ long n = go.nextLong(); long k = go.nextLong(); long hour = answer(n,k); System.out.println(hour); t--; } } public static long answer(long n, long k){ long hour = 0; long port = 1; long on = 1; while (on < n && port < k){ on += port; port *= 2; hour ++; } if (on < n){ hour += (n-on + k-1)/k; } return hour; } }
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
603df554da8e60644b1cbbceafef1619
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 Practice { // static final long mod=7420738134811L; static int mod=998244353; static final int size=501; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList<Integer> pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream("input.txt")); // System.setOut(new PrintStream("output.txt")); factorial(mod); InverseofNumber(mod); InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { long n=sc.nextLong(); long k=sc.nextLong(); long rem=n-1; if(n==1) { out.println("0"); return; } if(k==1) { out.println(rem); return; } long hrs=0; for(long num=1;num<=k;num=num*2) { rem=rem-num; hrs++; if(rem<=0) break; } if(rem<=0) { out.println(hrs); return; } hrs+=(rem/k)+(rem%k==0?0:1); out.println(hrs); } // { // int n=sc.nextInt(),k=sc.nextInt(); // if(n>k) // { // out.println(power(k, n)%mod); // return; // } // if(n==2) // { // out.println(k); // return; // } // long ans=power(n-1, n); // for(int i=n;i<=k;i+=n) // { // for(int j=1;j<=n-2;j++) // { // if(i-1+n-j-1<=k) // ans=(ans+Binomial(n, j)%mod * power(i-1, j)%mod * power(n-j-1, n-j)%mod)%mod; // } // } // out.println(ans); // } static class Pair implements Cloneable, Comparable<Pair> { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+101*Math.abs(y); } @Override public String toString() { return "("+x+" "+y+")"; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } } static class Tuple implements Cloneable, Comparable<Tuple> { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public String toString() { return "("+x+","+y+","+z+")"; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.x-a.x; if(x!=0) return x; return this.y-a.y; } } static void arraySort(int arr[]) { ArrayList<Integer> a=new ArrayList<Integer>(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList<Long> a=new ArrayList<Long>(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet<Integer> primeFactors(int n) { HashSet<Integer> ans=new HashSet<Integer>(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList<Integer>(); for (int i=2; i<size; ++i) { if (sp[i] == 0) { sp[i] = i; pr.add(i); } for (int j=0; j<(int)pr.size() && pr.get(j)<=sp[i] && i*pr.get(j)<size; ++j) sp[i * pr.get(j)] = pr.get(j); } } public static void InverseofNumber(int p) { naturalNumInverse=new long[size]; naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i < size; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse=new long[size]; factorialNumInverse[0] = factorialNumInverse[1] = 1; // pre-compute inverse of natural numbers for(int i = 2; i < size; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to 200001 public static void factorial(int p) { fact=new long[size]; fact[0] = 1; for(int i = 1; i < size; i++) fact[i] = (fact[i - 1] * (long)i) % p; } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R) { if(R<0) return 1; // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % mod * factorialNumInverse[N - R]) % mod; return ans; } static int findXOR(int x) //from 0 to x { if(x<0) return 0; if(x%4==0) return x; if(x%4==1) return 1; if(x%4==2) return x+1; return 0; } static boolean isPrime(long x) { if(x==1) return false; if(x<=3) return true; if(x%2==0 || x%3==0) return false; for(int i=5;i<=Math.sqrt(x);i+=2) if(x%i==0) return false; return true; } static long gcd(long a,long b) { return (b==0)?a:gcd(b,a%b); } static int gcd(int a,int b) { return (b==0)?a:gcd(b,a%b); } static class Node { int vertex,dis=0; HashSet<Node> adj; Node par; Node(int ver) { vertex=ver; dis=Integer.MAX_VALUE; adj=new HashSet<Node>(); par=null; } @Override public String toString() { return vertex+" "; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return "("+to.vertex+","+cost+") "; } } static long power(long x, long y) { if(x<=0) return 1; long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(n<k) return 0; long res = 1; // if(k>n) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static 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(); } 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; } } 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 void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+" "); System.out.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 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
0560b153a9bbdd8027a0a0ef5502ac15
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 Practice { // static final long mod=7420738134811L; static int mod=1000000007; static final int size=20001; static FastReader sc=new FastReader(System.in); // static Reader sc=new Reader(); static PrintWriter out=new PrintWriter(System.out); static long[] factorialNumInverse; static long[] naturalNumInverse; static int[] sp; static long[] fact; static ArrayList<Integer> pr; public static void main(String[] args) throws IOException { // System.setIn(new FileInputStream("input.txt")); // System.setOut(new PrintStream("output.txt")); // factorial(mod); // InverseofNumber(mod); // InverseofFactorial(mod); // make_seive(); int t=1; t=sc.nextInt(); while(t-->0) solve(); out.close(); out.flush(); } static void solve() throws IOException { long n=sc.nextLong(); long k=sc.nextLong(); long cnt=0; long num=1; if (n==1) { out.println(0); return; } while(num<=k && num<n) { num*=2; cnt++; } if(num<n) cnt+=(n-num+k-1)/k; out.println(cnt); } static class Pair implements Cloneable, Comparable<Pair> { int x,y; Pair(int a,int b) { this.x=a; this.y=b; } @Override public boolean equals(Object obj) { if(obj instanceof Pair) { Pair p=(Pair)obj; return p.x==this.x && p.y==this.y; } return false; } @Override public int hashCode() { return Math.abs(x)+101*Math.abs(y); } @Override public String toString() { return "("+x+" "+y+")"; } @Override protected Pair clone() throws CloneNotSupportedException { return new Pair(this.x,this.y); } @Override public int compareTo(Pair a) { int t= this.x-a.x; if(t!=0) return t; else return this.y-a.y; } } static class Tuple implements Cloneable, Comparable<Tuple> { int x,y,z; Tuple(int a,int b,int c) { this.x=a; this.y=b; this.z=c; } public boolean equals(Object obj) { if(obj instanceof Tuple) { Tuple p=(Tuple)obj; return p.x==this.x && p.y==this.y && p.z==this.z; } return false; } @Override public String toString() { return "("+x+","+y+","+z+")"; } @Override protected Tuple clone() throws CloneNotSupportedException { return new Tuple(this.x,this.y,this.z); } @Override public int compareTo(Tuple a) { int x=this.x-a.x; if(x!=0) return x; return this.y-a.y; } } static void arraySort(int arr[]) { ArrayList<Integer> a=new ArrayList<Integer>(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static void arraySort(long arr[]) { ArrayList<Long> a=new ArrayList<Long>(); for (int i = 0; i < arr.length; i++) { a.add(arr[i]); } Collections.sort(a); for (int i = 0; i < arr.length; i++) { arr[i]=a.get(i); } } static HashSet<Integer> primeFactors(int n) { HashSet<Integer> ans=new HashSet<Integer>(); if(n%2==0) { ans.add(2); while((n&1)==0) n=n>>1; } for(int i=3;i*i<=n;i+=2) { if(n%i==0) { ans.add(i); while(n%i==0) n=n/i; } } if(n!=1) ans.add(n); return ans; } static void make_seive() { sp=new int[size]; pr=new ArrayList<Integer>(); for (int i=2; i<size; ++i) { if (sp[i] == 0) { sp[i] = i; pr.add(i); } for (int j=0; j<(int)pr.size() && pr.get(j)<=sp[i] && i*pr.get(j)<size; ++j) sp[i * pr.get(j)] = pr.get(j); } } public static void InverseofNumber(int p) { naturalNumInverse=new long[size]; naturalNumInverse[0] = naturalNumInverse[1] = 1; for(int i = 2; i < size; i++) naturalNumInverse[i] = naturalNumInverse[p % i] * (long)(p - p / i) % p; } // Function to precompute inverse of factorials public static void InverseofFactorial(int p) { factorialNumInverse=new long[size]; factorialNumInverse[0] = factorialNumInverse[1] = 1; // pre-compute inverse of natural numbers for(int i = 2; i < size; i++) factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; } // Function to calculate factorial of 1 to 200001 public static void factorial(int p) { fact=new long[size]; fact[0] = 1; for(int i = 1; i < size; i++) fact[i] = (fact[i - 1] * (long)i) % p; } // Function to return nCr % p in O(1) time public static long Binomial(int N, int R) { if(R<0) return 1; // n C r = n!*inverse(r!)*inverse((n-r)!) long ans = ((fact[N] * factorialNumInverse[R]) % mod * factorialNumInverse[N - R]) % mod; return ans; } static int findXOR(int x) //from 0 to x { if(x<0) return 0; if(x%4==0) return x; if(x%4==1) return 1; if(x%4==2) return x+1; return 0; } static boolean isPrime(long x) { if(x==1) return false; if(x<=3) return true; if(x%2==0 || x%3==0) return false; for(int i=5;i<=Math.sqrt(x);i+=2) if(x%i==0) return false; return true; } static long gcd(long a,long b) { return (b==0)?a:gcd(b,a%b); } static int gcd(int a,int b) { return (b==0)?a:gcd(b,a%b); } static class Node { int vertex,dis=0; HashSet<Node> adj; Node par; Node(int ver) { vertex=ver; dis=Integer.MAX_VALUE; adj=new HashSet<Node>(); par=null; } @Override public String toString() { return vertex+" "; } } static class Edge { Node to; int cost; Edge(Node t,int c) { this.to=t; this.cost=c; } @Override public String toString() { return "("+to.vertex+","+cost+") "; } } static long power(long x, long y) { long res = 1; x = x % mod; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % mod; y = y >> 1; // y = y/2 x = (x * x) % mod; } return res; } static long binomialCoeff(long n, long k) { if(n<k) return 0; long res = 1; // if(k>n) // return 0; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res *= (n - i); res /= (i + 1); } return res; } static 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(); } 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; } } 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 void printarray(int arr[]) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+" "); System.out.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 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
9eb80383e788a4f47f3aefdbf62d9a70
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.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t>0){ t--; long n = scn.nextLong(); long k = scn.nextLong(); long curr = 1; long hour = 0; while(curr<n && curr<k){ curr += curr; hour++; } if(curr<n){ long temp = (n-curr); if(temp%k==0){ hour += temp/k; } else{ hour += temp/k+1; } } System.out.println(hour); } } }
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
c32c1c4e75fc0763eb709f01c4eda9ed
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 hi { 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 gio = 0; long may = 1; boolean f = true; while (may < k) { may *= 2; gio++; if( may >= n){ f = false; break; } } if(!f){ System.out.println(gio);continue; } if (may >= k) { n = n - may; if (n % k == 0) { gio += n / k; }else{ gio += n / k + 1; } } System.out.println(gio); } } }
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
9a5bec8d8cc1ccc099ad8690a8254c6f
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.*; import java.text.DecimalFormat; public class Main { private static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() throws FileNotFoundException { if (System.getProperty("os.name").equals("Mac OS X")) { // Input is a file br = new BufferedReader(new FileReader("input.txt")); // PrintWriter class prints formatted representations // of objects to a text-output stream. PrintStream pw = new PrintStream(new FileOutputStream("output.txt")); System.setOut(pw); } else { // Input is System.in br = new BufferedReader(new InputStreamReader(System.in), 32768); st = null; } } 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()); } int[] intArray(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) ret[i] = i(); return ret; } long l() { return Long.parseLong(next()); } long[] longArray(int n) { long[] ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = l(); return ret; } double d() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // **********************************Code Begins From // Here*************************************** // DecimalFormat df = new DecimalFormat("#.000000000000"); // map.put(key,map.getOrDefault(key,0)+1); public static void solve() { long n = c.l(), k = c.l(), time = 0; if (n == 1) { pn(0); return; } if (k == 1) { pn(n - 1); return; } n -= 1; long cnt = 1; while (n > 0) { n -= cnt; time++; cnt = 2 * cnt; // pn(n + " " + cnt + " " + time); if (cnt > k) { cnt = k; break; } } pn(time + (n + (k - 1)) / k); } public static void main(String[] args) throws FileNotFoundException { // Scanner sc = new Scanner(System.in); c = new FastScanner(); pw = new PrintWriter(System.out); int tc = c.i(); long start = System.currentTimeMillis(); for (int t = 0; t < tc; t++) { // p("Case #" + (t + 1) + ": "); solve(); } long end = System.currentTimeMillis(); if (System.getProperty("os.name").equals("Mac OS X")) { pn("The Program takes " + (end - start) + "ms"); } for (long i = 0; i < arr.length; i++) { if (arr[(int) i]) { primes.add(i); } } // for(int i=1;i<1000000;i++) // { // sumList.add((long)(i*(i+1)/2)); // } pw.close(); } // ArrayList<Integer> al = new ArrayList<>(); // Set<Integer> set = new TreeSet<>(); // Map<Integer, Integer> map = new HashMap<>(); // for(Map.Entry<Integer,Integer> e:map.entrySet())pn(e.getKey()+" // "+e.getValue()); // LinkedList<Integer> ll = new LinkedList<>(); // Stack<Integer>st = new Stack<>(); private static FastScanner c; private static Pair<Integer, Integer> pair; private static PrintWriter pw; private static int mod = (int) (1e9 + 7); private static final int IBIG = 1000000007; private static final int IMAX = 2147483647; private static final int IMIN = -2147483648; private static ArrayList<String> permute(String str, int l, int r, ArrayList<String> al) { if (l == r) { al.add(str.toString()); return al; } else { for (int i = l; i <= r; i++) { str = swap(str, l, i); permute(str, l + 1, r, al); str = swap(str, l, i); } } return al; } /** * Swap Characters at position * * @param a string value * @param i position 1 * @param j position 2 * @return swapped string */ public static String swap(String a, int i, int j) { char temp; char[] charArray = a.toCharArray(); temp = charArray[i]; charArray[i] = charArray[j]; charArray[j] = temp; return String.valueOf(charArray); } static ArrayList<String> printSubSeqRec(String str, int n, int index, String curr, ArrayList<String> al) { // base case if (index == n) { return al; } if (curr != null && !curr.trim().isEmpty()) { if (isStringSorted(curr)) al.add(curr); } for (int i = index + 1; i < n; i++) { curr += str.charAt(i); printSubSeqRec(str, n, i, curr, al); // backtracking curr = curr.substring(0, curr.length() - 1); } return al; } public static ArrayList<ArrayList<Integer>> printSubsequences(int[] arr, int index, ArrayList<Integer> path, ArrayList<ArrayList<Integer>> ans) { // Print the subsequence when reach // the leaf of recursion tree if (index == arr.length) { // Condition to avoid printing // empty subsequence if (path.size() > 0) ans.add(new ArrayList<>(path)); return ans; } else { // Subsequence without including // the element at current index printSubsequences(arr, index + 1, path, ans); path.add(arr[index]); // Subsequence including the element // at current index printSubsequences(arr, index + 1, path, ans); // Backtrack to remove the recently // inserted element path.remove(path.size() - 1); } return ans; } static int findSmallestDifference(int A[], int B[], int m, int n) { // Sort both arrays // using sort function Arrays.sort(A); Arrays.sort(B); int a = 0, b = 0; // Initialize result as max value int result = Integer.MAX_VALUE; // Scan Both Arrays upto // sizeof of the Arrays while (a < m && b < n) { if (Math.abs(A[a] - B[b]) < result) result = Math.abs(A[a] - B[b]); // Move Smaller Value if (A[a] < B[b]) a++; else b++; } // return final sma result return result; } static long bruteforce(int k, int n, int[] a) { long max = LMIN; int l = -1, r = -1; for (int i = max(n - 500, 0); i >= 0; i--) { for (int j = i - 1; j >= 1; j--) { long x = (i + 1) * (j + 1) - (k * (a[i] | a[j])); if (max < x) { l = i + 1; r = j + 1; max = x; } } } // pn(l + " " + r + " " + max); return max; } static long mycode(int k, int n, long[] a) { long max = LMIN; int l = -1, r = -1; for (int i = 1; i < n; i++) { // for (int j = i + 1; j < n; j++) { // long x = i * (i + 1) - k * (a[i - 1] | a[i]); long x = i * (i + 1) - k * (a[i - 1] | a[i]); if (x >= max) { l = max(l, i); r = max(r, i + 1); max = x; } // } } pn(l + " " + r + " " + max); return max; } private static final long LMAX = 9223372036854775807L; private static final long LMIN = -9223372036854775808L; private static boolean arr[] = sieve(1000001); private static ArrayList<Long> primes = new ArrayList<>(); private static ArrayList<Long> sumList = new ArrayList<>(); private static ArrayList<Integer> divisors = new ArrayList<>(); private static ArrayList<Long> divisorsL = new ArrayList<>(); private static ArrayList<Long> primefactorization = new ArrayList<>(); private static ArrayList<Integer> primedivisors = new ArrayList<>(); private static ArrayList<Integer> perfectSquares = new ArrayList<>(); private static int freq[] = new int[200005]; private static ArrayList<Integer> primefactorsofN = new ArrayList<>();; // Pair<Integer, Integer> pair; private static void pn(Object o) { pw.println(o); } private static void p(Object o) { pw.print(o); } private static Random rand = new Random(); // math util private static int minof(int a, int b, int c) { return min(a, min(b, c)); } private static int countDistinct(int arr[], int k) { int max = 0; // Creates an empty hashMap hM HashMap<Integer, Integer> hM = new HashMap<Integer, Integer>(); // Traverse the first window and store count // of every element in hash map for (int i = 0; i < k; i++) hM.put(arr[i], hM.getOrDefault(arr[i], 0) + 1); // Print count of first window max = max(max, hM.size()); // Traverse through the remaining array for (int i = k; i < arr.length; i++) { // Remove first element of previous window // If there was only one occurrence if (hM.get(arr[i - k]) == 1) { hM.remove(arr[i - k]); } else // reduce count of the removed element hM.put(arr[i - k], hM.get(arr[i - k]) - 1); // Add new element of current window // If this element appears first time, // set its count as 1, hM.put(arr[i], hM.getOrDefault(arr[i], 0) + 1); // Print count of current window max = max(max, hM.size()); } return max; } private static int minof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } private static void permuteHelper(ArrayList<ArrayList<Integer>> list, ArrayList<Integer> resultList, int[] arr) { // Base case if (resultList.size() == arr.length) { list.add(new ArrayList<>(resultList)); } else { for (int i = 0; i < arr.length; i++) { if (resultList.contains(arr[i])) { // If element already exists in the list then skip continue; } // Choose element resultList.add(arr[i]); // Explore permuteHelper(list, resultList, arr); // Unchoose element resultList.remove(resultList.size() - 1); } } } private static String getSmallestAndLargest(String s, int k) { String smallest = ""; String largest = ""; String arr[] = new String[s.length() - k + 1]; for (int i = 0; i < s.length() - k + 1; i++) { arr[i] = s.substring(i, i + k); } for (int j = 0; j < arr.length - 1; j++) { for (int g = 0; g < arr.length - 1; g++) { String p = arr[g]; String q = arr[g + 1]; boolean t = true; String temp = ""; for (int w = 0; w < k; w++) { char pkaCharacter = p.charAt(w); int b = (int) pkaCharacter; char qkaCharacter = q.charAt(w); int c = (int) qkaCharacter; if (b == c) continue; else if (b > c) { t = false; break; } else if (b < c) { t = true; break; } } if (t == false) { temp = arr[g + 1]; arr[g + 1] = arr[g]; arr[g] = temp; } else { continue; } } } smallest += arr[0]; largest += arr[arr.length - 1]; return smallest; // pn(largest); } private static long getClosest(long val1, long val2, long target) { if (target - val1 >= val2 - target) return val2; else return val1; } private static long minof(long a, long b, long c) { return min(a, min(b, c)); } private static long minof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return min(x[0], x[1]); if (x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i]; return min; } private static int maxof(int a, int b, int c) { return max(a, max(b, c)); } private static int maxof(int... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } private static long maxof(long a, long b, long c) { return max(a, max(b, c)); } private static long maxof(long... x) { if (x.length == 1) return x[0]; if (x.length == 2) return max(x[0], x[1]); if (x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i]; return max; } private static int fli(double d) { return (int) d; } private static int cei(double d) { return (int) Math.ceil(d); } private static long fll(double d) { return (long) d; } private static long cel(double d) { return (long) Math.ceil(d); } private static int gcf(int a, int b) { return b == 0 ? a : gcf(b, a % b); } private static long gcf(long a, long b) { return b == 0 ? a : gcf(b, a % b); } private static int lcm(int a, int b) { return a * b / gcf(a, b); } private static long lcm(long a, long b) { return a * b / gcf(a, b); } private static int randInt(int min, int max) { return rand.nextInt(max - min + 1) + min; } private static long mix(long x) { x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31); } // array util private static void reverse(int[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } private static void reverse(int[] a, int n, int k) { if (k > n) { System.out.println("Invalid k"); return; } // One by one reverse first // and last elements of a[0..k-1] for (int i = 0; i < k / 2; i++) { int tempswap = a[i]; a[i] = a[k - i - 1]; a[k - i - 1] = tempswap; } } private static void reverse(long[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } private static void reverse(double[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } private static void reverse(char[] a) { for (int i = 0, n = a.length, half = n / 2; i < half; ++i) { char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap; } } private static void shuffle(int[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } private static void shuffle(long[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } private static void shuffle(double[] a) { int n = a.length - 1; for (int i = 0; i < n; ++i) { int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap; } } private static void sortList(ArrayList<Integer> al) { Collections.sort(al); } static void reverseList(ArrayList<Integer> al) { Collections.reverse(al); } // static void sortList(ArrayList<Pair<Integer,Integer>>al) // {Collections.sort(al);} private static void sort(int[] a) { shuffle(a); Arrays.parallelSort(a); } private static void sort(long[] a) { shuffle(a); Arrays.parallelSort(a); } private static void sort(double[] a) { shuffle(a); Arrays.parallelSort(a); } private static int[] copy(int[] a) { int[] ans = new int[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } private static long[] copy(long[] a) { long[] ans = new long[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } private static double[] copy(double[] a) { double[] ans = new double[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } private static char[] copy(char[] a) { char[] ans = new char[a.length]; for (int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans; } // graph util private static List<List<Integer>> g(int n) { List<List<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g; } private static List<Set<Integer>> sg(int n) { List<Set<Integer>> g = new ArrayList<>(); for (int i = 0; i < n; ++i) g.add(new HashSet<>()); return g; } private static void c(List<? extends Collection<Integer>> g, int u, int v) { g.get(u).add(v); g.get(v).add(u); } private static void cto(List<? extends Collection<Integer>> g, int u, int v) { g.get(u).add(v); } private static void dc(List<? extends Collection<Integer>> g, int u, int v) { g.get(u).remove(v); g.get(v).remove(u); } private static void dcto(List<? extends Collection<Integer>> g, int u, int v) { g.get(u).remove(v); } // output private static void pn(int i) { pw.println(i); } private static void pn(long l) { pw.println(l); } private static void prln(long l) { pw.println(l); } private static void pr(double d) { pw.print(d); } private static void prln(double d) { pw.println(d); } private static void pr(char c) { pw.print(c); } private static void prln(char c) { pw.println(c); } private static void pr(char[] s) { pw.print(new String(s)); } private static void prln(char[] s) { pw.println(new String(s)); } private static void pr(String s) { pw.print(s); } private static void prln(String s) { pw.println(s); } private static void pr(Object o) { pw.print(o); } private static void prln(Object o) { pw.println(o); } private static void prln() { pw.println(); } private static void pryes() { prln("yes"); } private static void pry() { prln("Yes"); } private static void pY() { prln("YES"); } private static void prno() { prln("no"); } private static void prn() { prln("No"); } private static void pN() { prln("NO"); } private static void pryesno(boolean b) { prln(b ? "yes" : "no"); }; private static void pryn(boolean b) { prln(b ? "Yes" : "No"); } private static void prYN(boolean b) { prln(b ? "YES" : "NO"); } private static void prln(int... a) { for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ; if (a.length > 0) prln(a[a.length - 1]); else prln(); } private static void prln(long... a) { for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ; if (a.length > 0) prln(a[a.length - 1]); else prln(); } private static void prln(double... a) { for (int i = 0, len = a.length - 1; i < len; pr(a[i]), pr(' '), ++i) ; if (a.length > 0) prln(a[a.length - 1]); else prln(); } private static <T> void prln(Collection<T> c) { int n = c.size() - 1; Iterator<T> iter = c.iterator(); for (int i = 0; i < n; pr(iter.next()), pr(' '), ++i) ; if (n >= 0) prln(iter.next()); else prln(); } private static void h() { prln("hlfd"); flush(); } private static void flush() { pw.flush(); } private static void close() { pw.close(); } private static int uniquePairs(int a[], int n) { HashSet<Integer> visited1 = new HashSet<Integer>(); // un[i] stores number of unique elements // from un[i + 1] to un[n - 1] int un[] = new int[n]; // Last element will have no unique elements // after it un[n - 1] = 0; // To count unique elements after every a[i] int count = 0; for (int i = n - 1; i > 0; i--) { // If current element has already been used // i.e. not unique if (visited1.contains(a[i])) un[i - 1] = count; else un[i - 1] = ++count; // Set to true if a[i] is visited visited1.add(a[i]); } HashSet<Integer> visited2 = new HashSet<Integer>(); // To know which a[i] is already visited int answer = 0; for (int i = 0; i < n - 1; i++) { // If visited, then the pair would // not be unique if (visited2.contains(a[i])) continue; // Calculating total unqiue pairs answer += un[i]; // Set to true if a[i] is visited visited2.add(a[i]); } return answer; } private static int[] replaceAll(int[] a, int val, int newVal) { for (int i = 0; i < a.length; i++) if (a[i] == val) a[i] = newVal; return a; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } private static long factorial(int n) { if (n <= 0) return 1; else return (long) ((n * factorial(n - 1)) % mod); } private static long factorial(long n) { if (n <= 0) return 1L; else return (long) ((n * factorial(n - 1)) % mod); } private static void watch(int[] a) { for (int e : a) p(e + " "); pn(""); } private static void watch(double[] a) { for (double e : a) p(e + " "); pn(""); } private static void watch(long[] a) { for (long e : a) p(e + " "); pn(""); } private static void watchList(ArrayList<Integer> al) { for (int e : al) p(e + " "); pn(""); } private static void watchListString(ArrayList<String> al) { for (String e : al) p(e + " "); pn(""); } private static void watchListD(ArrayList<Double> al) { for (double e : al) p(e + " "); pn(""); } private static void watchListOfArrays(ArrayList<int[]> al) { for (int[] e : al) watch(e); } private static void watchLongList(ArrayList<Long> al) { for (long e : al) p(e + " "); pn(""); } private static void watchSet(Set<Integer> set) { for (int e : set) p(e + " "); pn(""); } private static void watchSetOfArrays(Set<int[]> set) { for (int[] e : set) watch(e); } private static Set<Integer> putSet(int[] a) { Set<Integer> set = new TreeSet<>(); for (int e : a) set.add(e); return set; } private static Set<Long> putSet(long[] a) { Set<Long> set = new TreeSet<>(); for (long e : a) set.add(e); return set; } private static int bs(int[] a, int x) { int start = 0, end = a.length - 1; while (start <= end) { int mid = start + ((end - start) / 2); if (a[mid] == x) return mid; else if (a[mid] < x) start = mid + 1; else end = mid - 1; } return -1; } private static String newString(String s, int k) { // new string String X = ""; // Remove characters until // the string is empty while (s.length() > 0) { char temp = s.charAt(0); // Traverse to find the smallest character in the // first k characters for (int i = 1; i < k && i < s.length(); i++) { if (s.charAt(i) < temp) { temp = s.charAt(i); } } // append the smallest character X = X + temp; // removing the lexicographically smallest // character from the string for (int i = 0; i < k; i++) { if (s.charAt(i) == temp) { s = s.substring(0, i) + s.substring(i + 1); // s.erase(s.begin() + i); break; } } } return X; } private static boolean exist(int[] a, int x) { for (int e : a) { if (e == x) return true; } return false; } private static int digitsum(int n) { int sum = 0; while (n > 0) { int digit = n % 10; n /= 10; sum += digit; } return sum; } private static long digitsum(long n) { long sum = 0; while (n > 0) { long digit = n % 10; n /= 10; sum += digit; } return sum; } private static int countPalindromicSubsequence(String str) { int N = str.length(); // create a 2D array to store the count // of palindromic subsequence int[][] cps = new int[N][N]; // palindromic subsequence of length 1 for (int i = 0; i < N; i++) cps[i][i] = 1; // check subsequence of length L is // palindrome or not for (int L = 2; L <= N; L++) { for (int i = 0; i <= N - L; i++) { int k = L + i - 1; if (str.charAt(i) == str.charAt(k)) { cps[i][k] = cps[i][k - 1] + cps[i + 1][k] + 1; } else { cps[i][k] = cps[i][k - 1] + cps[i + 1][k] - cps[i + 1][k - 1]; } } } // return total palindromic subsequence return cps[0][N - 1]; } private static int LCSubStr(char X[], char Y[], int m, int n) { // Create a table to store // lengths of longest common // suffixes of substrings. // Note that LCSuff[i][j] // contains length of longest // common suffix of // X[0..i-1] and Y[0..j-1]. // The first row and first // column entries have no // logical meaning, they are // used only for simplicity of program int LCStuff[][] = new int[m + 1][n + 1]; // To store length of the longest // common substring int result = 0; // Following steps build // LCSuff[m+1][n+1] in bottom up fashion for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) LCStuff[i][j] = 0; else if (X[i - 1] == Y[j - 1]) { LCStuff[i][j] = LCStuff[i - 1][j - 1] + 1; result = Integer.max(result, LCStuff[i][j]); } else LCStuff[i][j] = 0; } } return result; } private static List<String> subStrings(String s) { ArrayList<String> al = new ArrayList<>(); for (int i = 0; i < s.length(); i++) { for (int j = i + 1; j <= s.length(); j++) { al.add(s.substring(i, j)); } } return al; } private static boolean isSubSequence(String str1, String str2, int m, int n) { // Base Cases if (m == 0) return true; if (n == 0) return false; // If last characters of two strings are matching if (str1.charAt(m - 1) == str2.charAt(n - 1)) return isSubSequence(str1, str2, m - 1, n - 1); // If last characters are not matching return isSubSequence(str1, str2, m, n - 1); } private static boolean number_Is_Divisible_By_Its_Digits(long n) { long temp = n; while (temp > 0) { long digit = temp % 10; temp /= 10; if (digit != 0 && n % digit != 0) return false; } return true; } private static int countDivisors(int n) { int cnt = 0; for (int i = 1; i * i <= n; i++) { if (n % i == 0) cnt++; divisors.add(i); } return cnt; } private static ArrayList<Integer> divisorsList(int n) { for (int i = 1; i * i <= n; i++) { if (n % i == 0) { if (!divisors.contains(i)) divisors.add(i); if (!divisors.contains(n / i)) divisors.add(n / i); } } return divisors; } private static ArrayList<Long> divisorsList(long n) { for (long i = 1; i * i <= n; i++) { if (n % i == 0) { if (!divisorsL.contains(i)) divisorsL.add(i); if (!divisorsL.contains(n / i)) divisorsL.add(n / i); } } return divisorsL; } private static ArrayList<Integer> primeFactorList(int n) { for (int i = 2; i <= n; i++) { if ((n % i) == 0 && primedivisors.contains(i) == false) primedivisors.add(i); } return primedivisors; } private static boolean isStringSorted(String s) { for (int i = 0; i < s.length() - 1; i++) { if (s.charAt(i) > s.charAt(i + 1)) return false; } return true; } private static boolean isPalindromeString(String s) { String temp = ""; for (int i = s.length() - 1; i >= 0; i--) { temp += s.charAt(i) + ""; } return ((s.equals(temp)) ? true : false); } private static boolean isPalindrome(int[] a) { for (int i = 0; i < a.length / 2; i++) { if (a[i] != a[a.length - 1 - i]) return false; } return true; } private static boolean isPalindrome(ArrayList<Integer> al) { for (int i = 0; i < al.size() / 2; i++) { if (al.get(i) != al.get(al.size() - 1 - i)) return false; } return true; } private static boolean isSorted(int[] a) { int n = a.length; for (int i = 1; i < n; i++) { if (a[i - 1] > a[i]) return false; } return true; } private static boolean isSortedStrictly(int[] a) { int n = a.length; for (int i = 1; i < n; i++) { if (a[i - 1] >= a[i]) return false; } return true; } private static boolean isSorted(long[] a) { int n = a.length; for (int i = 1; i < n; i++) { if (a[i - 1] > a[i]) return false; } return true; } private static boolean isSortedStrictly(long[] a) { int n = a.length; for (int i = 1; i < n; i++) { if (a[i - 1] >= a[i]) return false; } return true; } private static boolean solution(int n, int x) { int sum = 0; while (n > 0) { int digit = n % 10; n /= 10; sum += digit; } return (sum == x) ? true : false; } private static ArrayList<Integer> perfectSquares(int n) { ArrayList<Integer> al = new ArrayList<Integer>(); for (int i = 1; i <= n; i++) { al.add(i * i); } return al; } private static boolean checkDuplicateAll(String s) { for (int i = 1; i < s.length(); i++) { if (s.charAt(i) != s.charAt(i - 1)) return false; } return true; } private static String sortString(String inputString) { // convert input string to Character array Character tempArray[] = new Character[inputString.length()]; for (int i = 0; i < inputString.length(); i++) { tempArray[i] = inputString.charAt(i); } // Sort, ignoring case during sorting Arrays.sort(tempArray, new Comparator<Character>() { @Override public int compare(Character c1, Character c2) { // ignoring case return Character.compare(Character.toLowerCase(c1), Character.toLowerCase(c2)); } }); // using StringBuilder to convert Character array to String StringBuilder sb = new StringBuilder(tempArray.length); for (Character c : tempArray) sb.append(c.charValue()); return sb.toString(); } private static String reverseString(String s, int x) { String ans = "", temp = s.substring(0, x); for (int i = x; i < s.length(); i++) { ans = s.charAt(i) + ans; } return temp + ans; } private static boolean number_Is_Not_Divisible_By_Its_Digits(int num) { String s = num + ""; if (s.contains("0")) return false; int temp = num; while (num > 0) { int digit = num % 10; num /= 10; if (temp % digit == 0) return false; } return true; } private static boolean palindrome(int n) { int temp = n, rev = 0; while (n > 0) { int digit = n % 10; n /= 10; rev = rev * 10 + digit; } return (temp == rev) ? true : false; } private static boolean checkparanthesis(String s) { Stack<Character> st = new Stack<>(); int n = s.length(); for (int i = 0; i < n; i++) { if (s.charAt(i) == '(') st.push('('); else { if (st.size() == 0) return false; else st.pop(); } } return (st.size() == 0) ? true : false; } private static boolean[] sieve(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 = i * i; j <= n; j += i) { isPrime[j] = false; } } return isPrime; } private static int[][] graph(int from[], int to[], int n) { int g[][] = new int[n][]; int cnt[] = new int[n]; for (int i = 0; i < from.length; i++) { cnt[from[i]]++; cnt[to[i]]++; } for (int i = 0; i < n; i++) { g[i] = new int[cnt[i]]; } Arrays.fill(cnt, 0); for (int i = 0; i < from.length; i++) { g[from[i]][cnt[from[i]]++] = to[i]; g[to[i]][cnt[to[i]]++] = from[i]; } return g; } private static String rev(String s) { StringBuilder sb = new StringBuilder(s); sb.reverse(); return sb.toString(); } private static long gcd(long x, long y) { if (y == 0) { return x; } else { return gcd(y, x % y); } } private static int gcd(int x, int y) { if (y == 0) { return x; } else { return gcd(y, x % y); } } private static int abs(int a, int b) { return (int) Math.abs(a - b); } private static int abs(int a) { return (int) Math.abs(a); } private static long abs(long a) { return (long) Math.abs(a); } private static long abs(long a, long b) { return (long) Math.abs(a - b); } private static void swap(int a, int b) { int c = b; b = a; a = c; } private static void swap(long a, long b) { long c = b; b = a; a = c; } private static int max(int a, int b) { if (a > b) { return a; } else { return b; } } private static int min(int a, int b) { if (a > b) { return b; } else { return a; } } private static long max(long a, long b) { if (a > b) { return a; } else { return b; } } private static long min(long a, long b) { if (a > b) { return b; } else { return a; } } private static long pow(long n, long p, long m) { long result = 1; if (p == 0) { return 1; } while (p != 0) { if (p % 2 == 1) { result *= n; } if (result >= m) { result %= m; } p >>= 1; n *= n; if (n >= m) { n %= m; } } return result; } private static int pow(int base, int exp) { int result = 1; while (exp != 0) { if ((exp & 1) == 1) result *= base; exp >>= 1; base *= base; } return result; } private static long pow(long n, long m) { long mod = 1000000007; if (m == 0) return 1; if (m == 1) return n; if (m % 2 == 0) { long ans = pow(n, m / 2); return (ans * ans) % mod; } else { long ans = pow(n, ((m - 1) / 2)); return ((n * ans) % mod * ans) % mod; } } private static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } private static class Pair<U, V> implements Comparable<Pair<U, V>> { public final U first; public V second; public <U, V> Pair<U, V> makePair(U first, V second) { return new Pair<U, V>(first, second); } public Pair(U first, V second) { this.first = first; this.second = second; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Pair pair = (Pair) o; return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null); } @Override public int hashCode() { int result = first != null ? first.hashCode() : 0; result = 31 * result + (second != null ? second.hashCode() : 0); return result; } public Pair<V, U> swap() { return makePair(second, first); } @Override public String toString() { return "(" + first + "," + second + ")"; } @SuppressWarnings({ "unchecked" }) public int compareTo(Pair<U, V> o) { int value = ((Comparable<U>) first).compareTo(o.first); if (value != 0) { return value; } return ((Comparable<V>) second).compareTo(o.second); } } }
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
233f7966b5c2868a75df105e0ee30898
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 { static FastScanner sc = new FastScanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static long mod = (long) 1e9 + 7; public static void main(String[] args) throws Exception { int n = sc.nextInt(); for(int i = 0; i < n; i++) solve(); pw.flush(); } public static void solve() { long n = sc.nextLong()-1L; long k = sc.nextLong(); long ans = 0; long now = 1L; while(n > 0){ if(now >= k){ ans += (n+k-1)/k; n = 0; }else{ ans++; n -= now; now *= 2L; } } pw.println(ans); } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } public static void save_sort(long[] array) { shuffle(array); Arrays.sort(array); } public static long[] shuffle(long[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); long randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public FastScanner(FileReader in) { reader = new BufferedReader(in); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String[] nextArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(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 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
660eaa8cfb9ce1ac2ddbd21e2cc6aa55
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_Update_Files { public static void main(String[] args)throws Exception { new Solver().solve(); } } //* Success is not final, failure is not fatal: it is the courage to continue that counts. class Solver { void solve() throws Exception { int t = sc.nextInt(); while(t-->0){ long n =sc.nextLong(); long k = sc.nextLong(); long val = 1L; // System.out.println(x+" "+val); long ans =0 ; while(val<k){ val = 2*val; ans++; } if(n>val){ // then we need to ans+=(n-val+k-1)/k; } System.out.println(ans); // if(n<=val){ // System.out.println("isni"); // System.out.println((Math.log((double)n)/Math.log((double)2))); // long y = (long)(Math.log((double)n)/Math.log((double)2)); // ans+=y; // ans += Math.ceil(()); // System.out.println(ans); // }else{ // ans += x+1; // long y = n-val; // System.out.println(y/k); // long p = y%k; // if(p==0){ // ans += y/k; // }else{ // ans += y/k+1; // } // System.out.println(ans); // } } sc.flush(); } final Helper sc; final int MAXN = 1000_006; final long MOD = (long) 1e9 + 7; Solver() { sc = new Helper(MOD, MAXN); sc.initIO(System.in, System.out); } } class Helper { final long MOD; final int MAXN; final Random rnd; public Helper(long mod, int maxn) { MOD = mod; MAXN = maxn; rnd = new Random(); } public static int[] sieve; public static ArrayList<Integer> primes; public void setSieve() { primes = new ArrayList<>(); sieve = new int[MAXN]; int i, j; for (i = 2; i < MAXN; ++i) if (sieve[i] == 0) { primes.add(i); for (j = i; j < MAXN; j += i) { sieve[j] = i; } } } public static long[] factorial; public void setFactorial() { factorial = new long[MAXN]; factorial[0] = 1; for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD; } public long getFactorial(int n) { if (factorial == null) setFactorial(); return factorial[n]; } public long ncr(int n, int r) { if (r > n) return 0; if (factorial == null) setFactorial(); long numerator = factorial[n]; long denominator = factorial[r] * factorial[n - r] % MOD; return numerator * pow(denominator, MOD - 2, MOD) % MOD; } public long[] getLongArray(int size) throws Exception { long[] ar = new long[size]; for (int i = 0; i < size; ++i) ar[i] = nextLong(); return ar; } public int[] getIntArray(int size) throws Exception { int[] ar = new int[size]; for (int i = 0; i < size; ++i) ar[i] = nextInt(); return ar; } public long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public long max(long[] ar) { long ret = ar[0]; for (long itr : ar) ret = Math.max(ret, itr); return ret; } public int max(int[] ar) { int ret = ar[0]; for (int itr : ar) ret = Math.max(ret, itr); return ret; } public long min(long[] ar) { long ret = ar[0]; for (long itr : ar) ret = Math.min(ret, itr); return ret; } public int min(int[] ar) { int ret = ar[0]; for (int itr : ar) ret = Math.min(ret, itr); return ret; } public long sum(long[] ar) { long sum = 0; for (long itr : ar) sum += itr; return sum; } public long sum(int[] ar) { long sum = 0; for (int itr : ar) sum += itr; return sum; } public void shuffle(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void shuffle(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public long pow(long base, long exp, long MOD) { base %= MOD; long ret = 1; while (exp > 0) { if ((exp & 1) == 1) ret = ret * base % MOD; base = base * base % MOD; exp >>= 1; } return ret; } static byte[] buf = new byte[1000_006]; static int index, total; static InputStream in; static BufferedWriter bw; public void initIO(InputStream is, OutputStream os) { try { in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); } catch (Exception e) { } } public void initIO(String inputFile, String outputFile) { try { in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputFile))); } catch (Exception e) { } } private int scan() throws Exception { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public String nextLine() throws Exception { 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(); } public String next() throws Exception { 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(); } public int nextInt() throws Exception { 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; } public long nextLong() throws Exception { 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; } public void print(Object a) throws Exception { bw.write(a.toString()); } public void printsp(Object a) throws Exception { print(a); print(" "); } public void println() throws Exception { bw.write("\n"); } public void printArray(int[] arr) throws Exception{ for(int i = 0;i<arr.length;i++){ print(arr[i]+ " "); } println(); } public void println(Object a) throws Exception { print(a); println(); } public void flush() throws Exception { bw.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 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
862b46e1219c6035e94ff5b421300253
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.io.PrintWriter; import java.util.StringTokenizer; import java.util.Arrays; import java.util.HashMap; import java.util.TreeSet; // public class Solution{ class Solution{ public static void main(String[] args){ FS sc = new FS(); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); // int t = 1; while(t-->0){ long n = sc.nextLong(); long k = sc.nextLong(); if (k==1) { pw.println(n-1); continue; } else if (n==2) { pw.println(1); continue; } long stage = (long)(Math.log(k)/Math.log(2) + 1e-10); long pow = (long)(Math.pow(2, stage)); // pw.println(stage + " " + pow); if(k<pow) stage--; if(k!=pow) stage++; long fin = (long)(Math.pow(2, stage)); // pw.println("fin "+fin +" "+ (fin>=n)); if (fin>=n) pw.println(stage); else { long rem = (n-fin)/k + ((n-fin)%k==0 ? 0 : 1); pw.println(stage + rem); } } pw.flush(); pw.close(); } static class FS{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next(){ while(!st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); } catch(Exception ignored){ } } return st.nextToken(); } int[] nextArray(int n){ int[] a = new int[n]; for(int i = 0; i < n; i++){ a[i] = nextInt(); } return a; } long[] nextLongArray(int n){ long[] a = new long[n]; for(int i = 0; i < n; i++){ a[i] = nextLong(); } return a; } int nextInt(){ return Integer.parseInt(next()); } 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 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
7d73b07e27e7a46c9623683d1a29d22a
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 MyPackage; import java.util.*; import java.io.*; public class codec{ static class Pair implements Comparable<Pair> { int wt; int idx; int x; Pair(int wt, int idx, int x) { this.wt = wt; this.idx = idx; this.x = x; } public int compareTo(Pair o) { return this.wt - o.wt; } } static class Items implements Comparable<Items> { int x; int id; Items(int id, int x) { this.id = id; this.x = x; } public int compareTo(Items o) { return this.x - o.x; } } static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } private static boolean isPal(String s) { int l = 0, r = s.length() - 1; while(l < r) { if(s.charAt(l++) != s.charAt(r--)) return false; } return true; } public static void swap(int[][] arr, int i, int j, int a, int b) { // arr[i] = (arr[i] + arr[j]) - (arr[j] = arr[i]); int t = arr[i][j]; arr[i][j] = arr[a][b]; arr[a][b] = t; } static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } static int lb(ArrayList<Integer>ar, int k) { int s = 0; int e = ar.size(); while(s != e) { int mid = s + e >> 1; if(ar.get(mid) < k) s = mid + 1; else e = mid; } if(s == ar.size()) return -1; return ar.get(s); } static int ub(ArrayList<Integer>ar, int k) { int s = 0; int e = ar.size(); while(s != e) { int mid = s+e>>1; if(ar.get(mid) <= k) s = mid + 1; else e = mid; } if(s == ar.size()) return -1; return s; } private static int func(int i, String s, int a, int b, int ak, int bk) { if(a > b + bk || b > a + ak) return i; if(i == s.length()) { return s.length(); } char c = s.charAt(i); int u = Integer.MAX_VALUE, v = Integer.MAX_VALUE, f = Integer.MAX_VALUE, se = Integer.MAX_VALUE; if(i % 2 == 0) { if(c == '1') u = func(i + 1, s, a + 1, b, ak - 1, bk); else if(c == '0') v = func(i + 1, s, a, b, ak - 1, bk); else { f = func(i + 1, s, a + 1, b, ak - 1, bk); se = func(i + 1, s, a, b, ak - 1, bk); } } else { if(c == '1') u = func(i + 1, s, a, b + 1, ak, bk - 1); else if(c == '0') v = func(i + 1, s, a, b, ak, bk - 1); else { f = func(i + 1, s, a, b + 1, ak, bk - 1); se = func(i + 1, s, a, b, ak, bk - 1); } } return Math.min(u, Math.min(v, Math.min(f, se))); } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); StringBuilder sb = new StringBuilder(); int t = in.nextInt(); while(t-- > 0) { long n = in.nextLong(); long k = in.nextLong(); if(n == 1 || n == 2) { sb.append((n - 1) + "\n"); continue; } long h = 0; long con = 1; while(con < k) { con *= 2; h++; } n -= con; if(n > 0) { if(n % k == 0) h += n / k; else h += n / k + 1; } sb.append(h + "\n"); } out.println(sb); out.close(); } catch (Exception e) { return; } } }
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
5dec8bb9295c6e63f6cf6b0ab2fc84a1
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
/** * B_Update_Files */ import java.util.*; import java.io.*; public class B_Update_Files { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader fr = new FastReader(); int t = fr.nextInt(); while (t-->0) { long n = fr.nextLong(); long k = fr.nextLong(); long i = 1l; long h = 0l; while (i<n && i<=k) { i*=2l; h = h + 1l; } if(i>=n) { System.out.println(h); }else { long rem = n-i; long e = (rem+k-1)/k; h+=e; 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 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
8726df625e5d645fb9b4f12dc41ac192
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 ComdeFormces { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub FastReader sc=new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); int t=sc.nextInt(); while(t--!=0) { long n=sc.nextLong(); long k=sc.nextLong(); long ans=0; long c=1; while(c<=n) { if(c==n)break; if(c<=k)c*=2; else if(n-c>=0) { long val=(n-c)%k==0?(n-c)/k:((n-c)/k)+1; ans+=val; break; } else break; ans++; } log.write(ans+"\n"); log.flush(); } } static boolean bsch(long k,long hc,long dc,long hm,long dm,long w,long a) { long s=0; long e=k; while(s<=e) { long b=k-s; long nhc=hc+s*a; long ndc=dc+b*w; long moves=hm%ndc==0?hm/ndc:(hm/ndc)+1; long moves2=nhc%dm==0?nhc/dm:(nhc/dm)+1; if(moves2>=moves)return true; s++; } return false; } //static ArrayList<Integer> pr(int n){ // boolean vis[]=new boolean[n+1]; // vis[0]=false; // vis[1]=false; // for(int i=2;i<=n;i++) { // if(vis[i]) { // for(int j=2*i;j<=n;j+=i) { // vis[j]=false; // } // } // } //} static long slv(int a[],int b[],long dp[][],int end,int k,int i) { if(i<1 ) { if(k==0) { return (end-a[0])*b[0]; } else return Integer.MAX_VALUE; } if(k<0)return Integer.MAX_VALUE; if(k==0) { return (end-a[0])*b[0]; } if(dp[i][k]!=0)return dp[i][k]; long ans1=slv(a,b,dp,a[i],k-1,i-1); long ans2=slv(a,b,dp,end,k,i-1); long val=(end-a[i])*b[i]; return dp[i][k]=Math.min(val+ans1,ans2); } static int bss(int[] a, int k) { int s=0; int e=a.length-1; int max=-1; while(s<=e) { int m=s+(e-s)/2; int val=solv(a,m); if(val==k) { max=Math.max(max, m); s=m+1; } else if(val<k)s=m+1; else e=m-1; } return max; } static int solv(int[] a,int len) { if(len%2==0) { int ans=0; for(int i=0;i<a.length;i++){ if(a[i]>0){ if(a[i]%2==0) { ans+=a[i]; } else if(a[i]%2!=0) { ans+=(a[i]/2)*2; } } } int cnt=ans/len; return cnt; } else { int ans=0,one=0; for(int i=0;i<a.length;i++){ if(a[i]>0){ if(a[i]%2==0) { ans+=a[i]; } else { ans+=(a[i]/2)*2; one++; } } } int n=len-1; int cnt=ans/n; int mod=cnt%n+one; if(cnt>=mod)return cnt; return mod; } } //debug static pair bss(ArrayList<pair> a,int el,int ind) { int s=0; int e=a.size()-1; pair ans=new pair(-1,-1); while(s<=e) { int m=s+(e-s)/2; if(a.get(m).a==el) { ans=a.get(m); e=m-1; } if(a.get(m).a>el)e=m-1; else s=m+1; } return ans; } public static <E> void p(E[][] a,String s) { System.out.println(s); for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } public static void p(int[] a,String s) { System.out.print(s+"="); for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } public static <E> void p(E a,String s){ System.out.println(s+"="+a); } public static <E> void p(ArrayList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(LinkedList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(HashSet<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Stack<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Queue<E> a,String s){ System.out.println(s+"="+a); } //utils static ArrayList<Integer> divisors(int n){ ArrayList<Integer> ar=new ArrayList<>(); for (int i=2; i<=Math.sqrt(n); i++){ if (n%i == 0){ if (n/i == i) { ar.add(i); } else { ar.add(i); ar.add(n/i); } } } return ar; } static int primeDivisor(int n){ ArrayList<Integer> ar=new ArrayList<>(); int cnt=0; boolean pr=false; while(n%2==0) { pr=true; n/=2; } if(pr)ar.add(2); for(int i=3;i*i<=n;i+=2) { pr=false; while(n%i==0) { n/=i; pr=true; } if(pr)ar.add(i); } if(n>2) ar.add(n); return ar.size(); } static String rev(String s) { char temp[]=s.toCharArray(); for(int i=0;i<temp.length/2;i++) { char tp=temp[i]; temp[i]=temp[temp.length-1-i]; temp[temp.length-1-i]=tp; } return String.valueOf(temp); } static int bs(ArrayList<pair> arr,int el) { int start=0; int end=arr.size()-1; while(start<=end) { int mid=start+(end-start)/2; if(arr.get(mid).a==el)return mid; else if(arr.get(mid).a<el)start=mid+1; else end=mid-1; } if(start>arr.size()-1)return -2; return -1; } static long find(int s,long a[]) { if(s>=a.length)return -1; long num=a[s]; for(int i=s;i<a.length;i+=2) { num=gcd(num,a[i]); if(num==1 || num==0)return -1; } return num; } static long gcd(long a,long b) { if(b==0)return a; else return gcd(b,a%b); } static int gcd(int a,int b) { if(b==0)return a; else return gcd(b,a%b); } static long factmod(long n,long mod,long img) { if(n==0)return 1; long ans=1; long temp=1; while(n--!=0) { if(temp!=img) { ans=((ans%mod)*((temp)%mod))%mod; } temp++; } return ans%mod; } static int bs(long a[] ,long num) { int start=0; int end=a.length-1; while(start<=end) { int mid=start+(end-start)/2; if(a[mid]==num) { return mid; } else if(a[mid]<num)start=mid+1; else end=mid-1; } return start; } static int ncr(int n, int r){ if(r>n-r)r=n-r; int ans=1; for(int i=0;i<r;i++){ ans*=(n-i); ans/=(i+1); } return ans; } public static class trip{ int a,b,c; public trip(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } public int compareTo(trip q) { return this.c-q.c; } } static void mergesort(int[] a,int start,int end) { if(start>=end)return ; int mid=start+(end-start)/2; mergesort(a,start,mid); mergesort(a,mid+1,end); merge(a,start,mid,end); } static void merge(int[] a, int start,int mid,int end) { int ptr1=start; int ptr2=mid+1; int b[]=new int[end-start+1]; int i=0; while(ptr1<=mid && ptr2<=end) { if(a[ptr1]<=a[ptr2]) { b[i]=a[ptr1]; ptr1++; i++; } else { b[i]=a[ptr2]; ptr2++; i++; } } while(ptr1<=mid) { b[i]=a[ptr1]; ptr1++; i++; } while(ptr2<=end) { b[i]=a[ptr2]; ptr2++; i++; } for(int j=start;j<=end;j++) { a[j]=b[j-start]; } } 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 class pair{ int a; int b; public pair(int a,int b) { this.a=a; this.b=b; } public int compareTo(pair b) { if(this.b!=b.b) return this.b-b.b; else return this.a-b.a; } public int compareToo(pair b) { return this.b-b.b; } @Override public String toString() { return "{"+this.a+" "+this.b+"}"; } } static long pow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } static int pow(int a, int pw) { int temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } }
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
9630ee7649fc695547ce5dccc91c9c4d
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 Experiment { static Scanner in=new Scanner(System.in); // static BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); static class Pair implements Comparable<Pair>{ int first; int second; int diff; Pair(int first,int second,int diff){ this.first=first; this.second=second; this.diff =diff; } public int compareTo(Pair o){ //diff=second-first; return this.diff-o.diff; // Sort return this.first-o.first; pair on the basis of first parameter in ascending order // return o.first-this.first to sort on basis of first parameter in descending order // return this.second -o.second to Sort pair on the basis of second parameter in ascending order //return o.second-this.second to sort on basis of second parameter in descending order } } public static void sort(int ar[],int l,int r) { if(l<r) { int m=l+(r-l)/2; sort(ar,l,m); sort(ar,m+1,r); merge(ar,l,m,r); } } public static int hcf(int x,int y) { if(y==0) return x; return hcf(y,x%y); } public static void merge(int ar[],int l,int m,int r) { int n1=m-l+1;int n2=r-m; int L[]=new int[n1]; int R[]=new int[n2]; for(int i=0;i<n1;i++) L[i]=ar[l+i]; for(int i=0;i<n2;i++) R[i]=ar[m+i+1]; int i=0;int j=0;int k=l; while(i<n1 && j<n2) { if(L[i]<=R[j]) { ar[k++]=L[i++]; }else { ar[k++]=R[j++]; } } while(i<n1) ar[k++]=L[i++]; while(j<n2) ar[k++]=R[j++]; } public static int[] sort(int ar[]) { sort(ar,0,ar.length-1); //Array.sort uses O(n^2) in its worst case ,so better use merge sort return ar; } public static void func() { long n=in.nextLong();long k=in.nextLong(); n=n-1; //System.out.println(n); long count=0;long temp=-1; while(n>0) { ++temp; if((long)Math.pow(2, temp)<k) { // System.out.println(-1); n=n-(long)Math.pow((double)2, temp);count++; }else { count=count+n/k; if(n%k!=0) count++; break; } } System.out.println(count); } public static void main(String[] args) { int t=in.nextInt(); while(t-->0) func(); } }
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
6992bf94dac644e2c50bba8b95aba086
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 Codeforces.PractiseR1100; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class UpdateFiles { public static void main(String[] args) throws Exception {new UpdateFiles().run();} long mod = 1000000000 + 7; int ans=0; // int[][] ar; void solve() throws Exception { int t=ni(); while(t-->0){ long n = nl(); long k = nl(); if(n==k && n==1){ out.println(0); continue; } if(k==1){ out.println(n-1); continue; } long cnt=1; long res= 2; while(res< n && res<=k){ res+=res; cnt++; } long tmp = n-res; long gg = (tmp+k-1)/k; out.println(gg+cnt); } } boolean helper(char[] a,int i){ if(a[i]=='a' && a[i+1]=='b' && a[i+2]=='c'){ return true; } return false; } // void buildMatrix(){ // // for(int i=1;i<=1000;i++){ // // ar[i][1] = (i*(i+1))/2; // // for(int j=2;j<=1000;j++){ // ar[i][j] = ar[i][j-1]+(j-1)+i-1; // } // } // } /* FAST INPUT OUTPUT & METHODS BELOW */ private byte[] buf = new byte[1024]; private int index; private InputStream in; private int total; private SpaceCharFilter filter; PrintWriter out; int min(int... ar) { int min = Integer.MAX_VALUE; for (int i : ar) min = Math.min(min, i); return min; } long min(long... ar) { long min = Long.MAX_VALUE; for (long i : ar) min = Math.min(min, i); return min; } int max(int... ar) { int max = Integer.MIN_VALUE; for (int i : ar) max = Math.max(max, i); return max; } long max(long... ar) { long max = Long.MIN_VALUE; for (long i : ar) max = Math.max(max, i); return max; } void shuffle(int a[]) { ArrayList<Integer> al = new ArrayList<>(); for (int i = 0; i < a.length; i++) al.add(a[i]); Collections.sort(al); for (int i = 0; i < a.length; i++) a[i] = al.get(i); } long lcm(long a, long b) { return (a * b) / (gcd(a, b)); } int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } /* * for (1/a)%mod = ( a^(mod-2) )%mod ----> use expo to calc -->(a^(mod-2)) */ long expo(long p, long q) /* (p^q)%mod */ { long z = 1; while (q > 0) { if (q % 2 == 1) { z = (z * p) % mod; } p = (p * p) % mod; q >>= 1; } return z; } void run() throws Exception { in = System.in; out = new PrintWriter(System.out); solve(); out.flush(); } private int scan() throws IOException { if (total < 0) throw new InputMismatchException(); if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } private int ni() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); int sgn = 1; if (c == '-') { sgn = -1; c = scan(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = scan(); } while (!isSpaceChar(c)); return res * sgn; } private long nl() throws IOException { long num = 0; int b; boolean minus = false; while ((b = scan()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = scan(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = scan(); } } private double nd() throws IOException { return Double.parseDouble(ns()); } private String ns() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = scan(); } while (!isSpaceChar(c)); return res.toString(); } private String nss() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); return br.readLine(); } private char nc() throws IOException { int c = scan(); while (isSpaceChar(c)) c = scan(); return (char) c; } private boolean isWhiteSpace(int n) { if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true; return false; } private boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhiteSpace(c); } private interface SpaceCharFilter { public boolean isSpaceChar(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 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