mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2012-02-25, 17:10   #12
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by lavalamp View Post
I did not see anyone using such a method, and I'm also not sure how that method would work. The sum to sqrt(100)-sqrt(99) for example is 4.6324, but R(0,100) is given to be 3019.
the code I made above gave me 5247 for the method it used. but:

Code:
b=0;for(x=1,100,for(y=1,100,if(floor((y^2)/(x^2))%2==1,b=b+1)));b
give 3019.

Last fiddled with by science_man_88 on 2012-02-25 at 17:17
science_man_88 is offline   Reply With Quote
Old 2012-02-25, 17:11   #13
voidme
 
Feb 2012

67 Posts
Default

I think this is possible to do in log-time, just a matter of finding the differences and how long those blocks will be
voidme is offline   Reply With Quote
Old 2012-02-25, 17:35   #14
voidme
 
Feb 2012

67 Posts
Default

That's the "naive" brute force approach
voidme is offline   Reply With Quote
Old 2012-02-25, 17:52   #15
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

20C016 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
the code I made above gave me 5247 for the method it used. but:

Code:
b=0;for(x=1,100,for(y=1,100,if(floor((y^2)/(x^2))%2==1,b=b+1)));b
give 3019.
I think I have 3 changes to this to make it correctly done and faster.

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.
science_man_88 is offline   Reply With Quote
Old 2012-02-28, 14:00   #16
ATH
Einyen
 
ATH's Avatar
 
Dec 2003
Denmark

35×13 Posts
Default

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.
ATH is offline   Reply With Quote
Old 2012-02-28, 14:11   #17
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by ATH View Post
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.
I found another optimization to my program that I could make ( I have to remake the others because I had to copy it from here again).

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
science_man_88 is offline   Reply With Quote
Old 2012-02-28, 17:52   #18
voidme
 
Feb 2012

67 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
I found another optimization to my program that I could make ( I have to remake the others because I had to copy it from here again).

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
That approach will still take more time than is reasonable to run
voidme is offline   Reply With Quote
Old 2012-02-28, 17:58   #19
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

203008 Posts
Default

Quote:
Originally Posted by voidme View Post
That approach will still take more time than is reasonable to run
I'll admit this alone doesn't because it only cuts the amount of possibilities by around half.

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.
both got above what the page can "verify"

Last fiddled with by science_man_88 on 2012-02-28 at 18:29
science_man_88 is offline   Reply With Quote
Old 2012-02-28, 21:41   #20
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

5·271 Posts
Default

I'll just leave this here.

You don't need to loop through each individual value of y.
lavalamp is offline   Reply With Quote
Old 2012-02-28, 21:44   #21
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

26·131 Posts
Default

Quote:
Originally Posted by lavalamp View Post
I'll just leave this here.

You don't need to loop through each individual value of y.
unless I'm counting something twice that shouldn't affect the resulting number, also I know that like I said the first code cuts the amount of checks by half.
science_man_88 is offline   Reply With Quote
Old 2012-02-28, 22:01   #22
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

5·271 Posts
Default

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
lavalamp is offline   Reply With Quote
Reply



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

All times are UTC. The time now is 03:07.


Sat Jul 17 03:07:01 UTC 2021 up 50 days, 54 mins, 1 user, load averages: 1.34, 1.29, 1.30

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.