This discussion board is a place to discuss our Daily Challenges and the math and science
related to those challenges. Explanations are more than just a solution — they should
explain the steps and thinking strategies that you used to obtain the solution. Comments
should further the discussion of math and science.
When posting on Brilliant:
Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.
Stay on topic — we're all here to learn more about math and science, not to hear about your favorite get-rich-quick scheme or current world events.
Markdown
Appears as
*italics* or _italics_
italics
**bold** or __bold__
bold
- bulleted - list
bulleted
list
1. numbered 2. list
numbered
list
Note: you must add a full line of space before and after lists for them to show up correctly
So basically we can pair up the divisors for any given n. So, l will have the smaller one and h will store the larger one ( such that l×h=n ) and we are incrementing l by one each time and correspondingly decreasing h. So h will decrease much faster and we would be skipping lot of numbers which anyway we need not check.
PS: I forgot to include the line to check whether l=h that is if n is a perfect square.
Big numbers cannot be stored in long. Therefore we need something which is even bigger, like float or double. The problem with using "%" function with float/double is that it will not work. "%" is meant to work only with integers(int or long or short), It will not work with float and double as they are decimal values. Does 100%2.3 make sense?
Hence we use a workaround to find the true factors of n by using floor.
@Raghav Vaidyanathan
–
Ouch. I didn't notice that you used double. But then why not use long long? long long has a higher range than a double for the same memory, since a double can only hold 15 significant digits whereas long long can hold upto 18.
Note I don't use C++ so I have no idea if long long is used commonly.
Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i-1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
You can firstly improve by running the loop till i≤2n. Or you can try this:
Log in to reply
Yes, I noticed 2n thing. Can you explain algorithm you used? Thanks.
Log in to reply
So basically we can pair up the divisors for any given n. So, l will have the smaller one and h will store the larger one ( such that l×h=n ) and we are incrementing l by one each time and correspondingly decreasing h. So h will decrease much faster and we would be skipping lot of numbers which anyway we need not check.
PS: I forgot to include the line to check whether l=h that is if n is a perfect square.
Log in to reply
2n to ⌊n⌋. I still can't understand how will it help while dealing with higher numbers. Let me compile.
We can bring downTry this out
Log in to reply
Why are you taking
to check if i is a factor of n instead of
Log in to reply
Big numbers cannot be stored in long. Therefore we need something which is even bigger, like float or double. The problem with using "%" function with float/double is that it will not work. "%" is meant to work only with integers(int or long or short), It will not work with float and double as they are decimal values. Does 100%2.3 make sense?
Hence we use a workaround to find the true factors of n by using floor.
Log in to reply
Note I don't use C++ so I have no idea if long long is used commonly.
Log in to reply
Try Java Codes,They are always better than C++
Log in to reply
For that, I'll have to learn java properly.
Maybe you could try using long variable or long long . But that won't be really necessary if you are writing this for boards
Log in to reply
I program for fun. -_- I hate boards
Log in to reply
Oh ! So have you studied any algorithm books like CLRS ? Or are you active on websites like topcoder , spoj ?
Log in to reply
Try long double it has the max and min values 104932and10−4932 respectively and has a memory of 10 bytes. Its the biggest as far as I know.
Log in to reply
Modulus doesn't work with floating data types.
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
Log in to reply
@Pranjal Jain @Sudeep Salgia
Thanks. Sorry for not noticing. I am quite inactive now a days on B'ant. (Turned off all email notifications as well)