Hi,
Problem 451 asks for the sum of the largest coprime number (lets say A) of N for which (A*A)%N=1, looping N between 3 and 20 million.
Also, A has to be smaller than N-1 otherwise it would be trivial.
My initial approach has been:
- get an optimized function f1 to compute (i*i)%N
- get an optimized function f2 to check whether A and B are coprime
- for every N between 3 and 20M, loop down starting at i=N-2 and if f1 and f2 (by this order), exit the loop
A believe that each individual function is fairly optimized, but I still can't get beyond 1M in 10 minutes, so 20M will not be feasible.
Also, I tried to check in other places (mostly stack overflow) whether I could get some information at all about N+1 given the result on N, and the answers were negative.
So, can anyone help steer me in the right direction please?
Thanks
Edit:
New here, just to be sure: does this count as "posting code fragment"? If yes then sorry, I'll remove it
Problem 451
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 451
The problem builds on several lower numbered problems.
If you want to be steered into the right direction: solve some relevant lower numbered problems first.
Project Euler problems often tend to be built upon lower numbered ones.
If you want to be steered into the right direction: solve some relevant lower numbered problems first.
Project Euler problems often tend to be built upon lower numbered ones.

War ruins the life and health of untold numbers of innocent children.
-
Bobail
- Posts: 9
- Joined: Sat Mar 01, 2014 7:20 am
Re: Problem 451
My algorithm does not give me the good answer on 2.10^7
Could someone give me some data in order to check my program (without waiting 40 min each time)
I have the following result:
* 3 -> 100: 1932
* 3 -> 1000: 272840
* 3 -> 10000: 31829433
Could someone give me some data in order to check my program (without waiting 40 min each time)
I have the following result:
* 3 -> 100: 1932
* 3 -> 1000: 272840
* 3 -> 10000: 31829433

-
TripleM
- Posts: 384
- Joined: Fri Sep 12, 2008 3:31 am
-
Bobail
- Posts: 9
- Joined: Sat Mar 01, 2014 7:20 am
Re: Problem 451
Well if you have the data, could you provide it please.TripleM wrote:This is too low.Bobail wrote:* 3 -> 100: 1932

- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 451
Come on Bobail.
It shouldn't be too difficult to write a bruteforcer that gives you the correct answer for 3[le]n[le]100.
It shouldn't be too difficult to write a bruteforcer that gives you the correct answer for 3[le]n[le]100.

War ruins the life and health of untold numbers of innocent children.
-
Bobail
- Posts: 9
- Joined: Sat Mar 01, 2014 7:20 am
Re: Problem 451
Sorry, you are totally right.hk wrote:Come on Bobail.
It shouldn't be too difficult to write a bruteforcer that gives you the correct answer for 3[le]n[le]100.
I figured out my problem.
