Help me in solving MAKEDIV3 problem

getting Runtime error, don’t know why

My code

#---!@#$%^&*()_+---
# This code belong to ravi Dholariya!
#---!@#$%^&*()_+---
import math
for _ in range(int(input())):
    n = int(input())
    start = 10**(n-1)
    end = 10**n
    for i in range(start,end-1):
        if i%2!=0 and i % 3 ==0 and i % 9 !=0 :
            print(i)
            break
    

Learning course: Jump from 2* to 3*
Problem Link: Make it Divisible Practice Problem in Jump from 2* to 3* - CodeChef

@ravi_dholariya
plzz refer my c++ code for better understanding of the logic

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    for(int i=0;i<n-1;i++)
	    cout<<9;
	    cout<<3;
	    cout<<endl;
	}
	return 0;
}
1 Like

In fact this is a valid approach given the limits of 10**4 for n. If you read the error message (and in fact you should :wink: ) it most likely tells you about limits for int-to-str conversion and how to change it:


import sys
sys.set_int_max_str_digits(20_000)

1 Like

wow that really surprises me,
but it did not give error while running on my compiler(vscode - python3.5)!!

well thanks,
for your response :innocent:!!!