How can I fix my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I fix my code?

When I enter a number with more than 5 digits, the program terminates. Why does this happen? Is there any way I can fix it? Thank you https://code.sololearn.com/cBV88i20xI70/?ref=app

26th Dec 2020, 7:15 PM
SHIVANSH
SHIVANSH - avatar
3 Answers
+ 1
In this case there might be two reasons i could think of, 1. input integer size (must be less then 2^32 as int is in use) 2. computation time (verifying each number from 2 to input number is a huge process) You can reduce your algorithms computation by half by checking only 2,3,5,7,.. odd numbers alone and data type accordingly maybe long or biginteger
26th Dec 2020, 7:37 PM
Sathish Kanna
Sathish Kanna - avatar
+ 3
you have to minimize the time complexity of your code
26th Dec 2020, 10:58 PM
Samima Hassan
Samima Hassan - avatar
0
Sathish Kanna and Samima Hassan Thank you 😊
27th Dec 2020, 4:20 AM
SHIVANSH
SHIVANSH - avatar