- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# 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 Questions & Answers
- 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
- Program to find number of steps to solve 8-puzzle in python
- 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
- 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
- Print steps to make a number in form of 2^X – 1 in C Program.
- Python program to Sort a List of Strings by the Number of Unique Characters
- Program to count number of ways ball can drop to lowest level by avoiding blacklisted steps in Python
- Program to find number of minimum steps to reach last index in Python
- Program to find remainder after dividing n number of 1s by m in Python
- Python program to print a checkboard pattern of n*n using numpy.
- Python program to print check board pattern of n*n using numpy
- C++ Program to Print Number Entered by User

Advertisements