← Back to topics
Topic

delioci

D
Dgleich
How to speed up my code on this task, Am I doing the idea from forum in the right way or ?
Code Removed* :D
m
mario93
I didn't read your code, but the fastest idea is using Highly Composite Numbers!
D
Dgleich
Well I was thinking of that, so I just find first highly composite number with most divisors till N and just find number of it's divisors?
N
Nikola94
there are different ideas but mario93 is right, using HCN is the fastest one. google highly composite numbers and find a table with those numbers. about 70 of them are smaller than 2^32. this is the fastest idea by executing, but it will take you about 15 minutes to write the code :)
D
Dgleich
I just wrote the code, and there are exactly 70 of them :D , just added them and linear search through them , cuz it's fast enough :D , my fingers now hurt :D thanks for help , can't wait for grader to get back up :)
m
mario93
Well, if you want to make it faster, do the Binary search, but assuming that there is only 70 numbers, it really doesn't meter!!! :)
D
Dgleich
Well I was bored so I've done it :D
M
MilosRadic
in which other way can this task be solved?
M
MilosRadic
can u give me a link please?
d
demjan0001
of course you can do it on another way,
this is not idea for solving this task !!!
you don't have to know such things as solution for first 70 numbers, or something like that ...
there is no point solving tasks on that way ...
look at my code: http://www.z-trening.com/submit.php?submit=7100059098&subm_code=1
a
aleksa92
http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=primeNumbers

You should look at "The number of divisors"
M
MilosRadic
well my algorithm was to check for n div 2 to n then nubmer with the biggest number of divisors.but it only works on half tests cause the othere half exceedes the time of 1 sec.could someone email his code please.my email is radic_milos@hotmail.com
a
aleksa92
Every number can be factorized to primitive factors. Since n<2^31 we can assume that the number we are looking for has less than 32 factors, becouse if it has more than 31 factors, it would be grater than 2^31

So we need only first 31 prime numbers. We generate them in some array... Then all we have to do is to check all possible combinations with of these 31 primes, where in each combination can be more than one same prime. We can do this via backtracking, starting from smallest prime, and on each step calculating number of divisors and product of combination. When product goes over N we stop expanding this combination and search for some other. Hope it's clear now...
M
MilosRadic
ok i understand it.thanks