![]() |
|
|
#12 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
Code:
b=0;for(x=1,100,for(y=1,100,if(floor((y^2)/(x^2))%2==1,b=b+1)));b Last fiddled with by science_man_88 on 2012-02-25 at 17:17 |
|
|
|
|
|
|
#13 |
|
Feb 2012
67 Posts |
I think this is possible to do in log-time, just a matter of finding the differences and how long those blocks will be
|
|
|
|
|
|
#14 |
|
Feb 2012
67 Posts |
That's the "naive" brute force approach
|
|
|
|
|
|
#15 | |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
Quote:
1) set the smallest at M+1 and the limit at N 2) note that floor(y^2/x^2) == floor((y/x)^2) 3) note that if (x,y) works so are all (zx,zy) such that zx and zy are multiples of (x,y) such that they both stay under N+1. |
|
|
|
|
|
|
#16 |
|
Einyen
Dec 2003
Denmark
35×13 Posts |
Finally got my brute force program to give the correct result, runtime is 70min.
Someone in the forum made a smart program that gets the result in 1sec, but I don't understand his method. |
|
|
|
|
|
#17 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
my new optimization is to not be 0 y>=x because if not y<x (y^2/x^2)<1 and hence floor(y^2/x^2)==0 |
|
|
|
|
|
|
#18 |
|
Feb 2012
67 Posts |
That approach will still take more time than is reasonable to run
|
|
|
|
|
|
#19 | |
|
"Forget I exist"
Jul 2009
Dumbassville
203008 Posts |
Quote:
PS: Code:
(14:11)>b=0;for(x=100,10000,for(y=x,10000,if(floor((y/x)^2)%2==1,b=b+1)));b %44 = 29755324 (14:25)>## *** last result computed in 55,396 ms. (14:25)>b=0;for(x=100,10000,for(y=1,10000,if(floor((y/x)^2)%2==1,b=b+1)));b %45 = 29755324 (14:27)>## *** last result computed in 1mn, 31,775 ms. Last fiddled with by science_man_88 on 2012-02-28 at 18:29 |
|
|
|
|
|
|
#20 |
|
Oct 2007
Manchester, UK
5·271 Posts |
I'll just leave this here.
You don't need to loop through each individual value of y. |
|
|
|
|
|
#21 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
|
|
|
|
|
|
#22 |
|
Oct 2007
Manchester, UK
5·271 Posts |
It doesn't affect the answer, but it sure as hell affects the run time.
By a factor of millions. Edit: Or at least it does for the much larger range required by the problem. Edit 2: Just noticed that you get the wrong answer because you're running the loop from 100 instead of 101. The problem specifies M < x <= N. Last fiddled with by lavalamp on 2012-02-28 at 22:08 |
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Project Euler | jhs | Puzzles | 32 | 2021-01-19 04:05 |
| Project Euler 486 | lavalamp | Puzzles | 8 | 2015-02-04 14:28 |
| Euler (6,2,5) details. | Death | Math | 10 | 2011-08-03 13:49 |
| Project Euler | Mini-Geek | Lounge | 2 | 2009-10-23 17:19 |
| Bernoulli and Euler numbers (Sam Wagstaff project) | fivemack | Factoring | 4 | 2008-02-24 00:39 |