Can anyone help me out in improving the following program to find factors of number \(n\) as it doesn't work for higher numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 

Can anyone help me out in improving the following program to find factors of number \(n\) as it doesn't work for higher numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 

Problem Loading...
Note Loading...
Set Loading...
Comments
Sort by:
Top NewestYou can firstly improve by running the loop till \( i \leq \frac{n}{2} \). Or you can try this:
Log in to reply
– Pranjal Jain · 1 year, 10 months ago
Yes, I noticed \(\frac{n}{2}\) thing. Can you explain algorithm you used? Thanks.Log in to reply
PS: I forgot to include the line to check whether \( l= h\) that is if n is a perfect square. – Sudeep Salgia · 1 year, 10 months ago
Log in to reply
– Pranjal Jain · 1 year, 10 months ago
It showed many errors. Which compiler are you using? And I believe the condition should be if (n%h==0)Log in to reply
– Pranjal Jain · 1 year, 10 months ago
We can bring down \(\frac{n}{2}\) to \(\lfloor\sqrt{n}\rfloor\). I still can't understand how will it help while dealing with higher numbers. Let me compile.Log in to reply
How many times should i try to help before someone notices Pranjal Jain . I have included a few ideas in the following from Sudeep Salgia as well:
Here are the factors of \(10000000099\)
And here are the factors of \(7296872389761\)
– Raghav Vaidyanathan · 1 year, 10 months agoLog in to reply
– Pranjal Jain · 1 year, 10 months ago
Thanks. Sorry for not noticing. I am quite inactive now a days on B'ant. (Turned off all email notifications as well)Log in to reply
@Pranjal Jain @Sudeep Salgia – Raghav Vaidyanathan · 1 year, 10 months ago
Log in to reply
Try long double it has the max and min values \(10^{4932}\quad and \quad 10^{4932}\) respectively and has a memory of 10 bytes. Its the biggest as far as I know. – Harshvardhan Mehta · 1 year, 10 months ago
Log in to reply
– Pranjal Jain · 1 year, 10 months ago
Modulus doesn't work with floating data types.Log in to reply
Maybe you could try using long variable or long long . But that won't be really necessary if you are writing this for boards – Rohit Shah · 1 year, 10 months ago
Log in to reply
– Pranjal Jain · 1 year, 10 months ago
I program for fun. _ I hate boardsLog in to reply
– Rohit Shah · 1 year, 10 months ago
Oh ! So have you studied any algorithm books like CLRS ? Or are you active on websites like topcoder , spoj ?Log in to reply
– Pranjal Jain · 1 year, 10 months ago
Currently I am inactive due to JEE. But I will be active after 23 months on Project Euler.Log in to reply
Try Java Codes,They are always better than C++ – Vraj Mehta · 1 year, 10 months ago
Log in to reply
– Pranjal Jain · 1 year, 10 months ago
For that, I'll have to learn java properly.Log in to reply
Try this out
Log in to reply
to check if \( i \) is a factor of \( n \) instead of
Log in to reply
Hence we use a workaround to find the true factors of n by using floor. – Raghav Vaidyanathan · 1 year, 10 months ago
Log in to reply
Note I don't use C++ so I have no idea if long long is used commonly. – Siddhartha Srivastava · 1 year, 10 months ago
Log in to reply
– Raghav Vaidyanathan · 1 year, 10 months ago
Nope, long long doesn't work in c++. That's the biggest problem here.Log in to reply