Copying code
Practice
3.9 (15 votes)
Basic math
Algorithms
Mathamatics
Math
Problem
95% Success 2795 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Y has \(n\) lines of code and want to move the \(n\)th line of code to the \(i\)th line of code.
Y can use two methods for this work:
- First, Y can press Ctr + x (two keys) and cut the \(n\)th line of code, then move the cursor to the \(i\)th line pressing up key \(n-i\) times and then paste the \(n\)th line using Ctr + v (two keys).
- Second, Y can press Ctr + up (two keys) \(n-i\) times.
What is the minimum number of keys that Y has to press?
Input
The only line of input is \(n\) and \(i\) separated by space.
\(1 \leq i \leq n \leq 10^9\)
Output
A single line, the minimum number of keys that Y has to press to do the job.
Explanation
Y can do both methods and press \(8\) keys.
- Press Ctr + x and then press up \(4\) times and at the end press Ctr + v (two times Ctr, one time x, v and \(4\) time up that sums up to \(8\)).
- Press Ctr + up \(4\) times (both Ctr and up pressed \(4\) times that sums up to \(8\)).
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
11 votes
Tags:
Very-Easy
2.OddEve
Points:10
1 votes
Tags:
Very-Easy
Points:10
Tags:
Basic MathMathC++
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output