My issue
What is wrong with my code?
My code
for _ in range(int(input())):
n= int(input())
if n==1: print(3)
else: print(10**(n-1) +5)
Learning course: Jump from 2* to 3*
Problem Link: Make it Divisible Practice Problem in Jump from 2* to 3* - CodeChef
@amarendarpunna
The logic is print n-1 times 9 and one time 3.
You can not print such a huge number in Python.
By default, Python can only print numbers up to 4300 digits (and this problem will ask you to print a 10000 digit number), so it throws a Runtime Error.
You have 3 options.
- Increase Python’s default limit
- Use Decimal library
- Work with strings
Increasing limit:
import sys
sys.set_int_max_str_digits(0)
for _ in range(int(input())):
n= int(input())
if n==1: print(3)
else: print(10**(n-1) +5)
Using decimal
from decimal import Decimal
for _ in range(int(input())):
n= int(input())
if n==1: print(3)
else:
var = Decimal(10**(n-1)+5)
print(var)
Using strings
for _ in range(int(input())):
n= int(input())
if n==1: print(3)
else:
print(1,end="")
print("0"*(n-2),end="")
print(5)