
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to print maximum number of characters by copy pasting in n steps in Python?
Suppose we have a number n; we have to find the maximum number of characters we can enter using n operations where each operation is like
Inserting the character "x".
Copy all characters.
Paste
So, if the input is like n = 12, then the output will be 81.
To solve this, we will follow these steps
if n <= 4, then
return n
v := 6, x := 3, i := 5, j := 0
while i is not same as n, do
v := v + x
i := i + 1, j := j + 1
if j is divisible by 3, then
x := integer of (x * 1.5)
otherwise when j is not divisible by 3, then
do nothing
otherwise,
x := x * 2
return v
Let us see the following implementation to get better understanding
Example
class Solution: def solve(self, n): if n <= 4: return n v = 6 x = 3 i = 5 j = 0 while i != n: v += x i += 1 j += 1 if j % 3 == 0: x = int(x * 1.5) elif j % 3 == 1: pass else: x *= 2 return v ob = Solution() n = 12 print(ob.solve(n))
Input
12
Output
81
- Related Articles
- Program to find number of optimal steps needed to reach destination by baby and giant steps in Python
- Python Program to print a specific number of rows with Maximum Sum
- Print steps to make a number in form of 2^X – 1 in C Program.
- Program to find number of steps to solve 8-puzzle in python
- Program to make a copy of a n-ary tree in Python
- Python Program to Print the Pascal's triangle for n number of rows given by the user
- Program to count number of ways ball can drop to lowest level by avoiding blacklisted steps in Python
- Python program to print Possible Words using given characters
- Program to find number of minimum steps to reach last index in Python
- Ways to print escape characters in python
- Python program to print sorted number formed by merging all elements in array
- Program to count number of on lights flipped by n people in Python
- Program to find modulus of a number by concatenating n times in Python
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Python program to Sort a List of Strings by the Number of Unique Characters

Advertisements