Problem 451

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
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.

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


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
Post Reply
francisco_lolo12
Posts: 1
Joined: Mon Dec 23, 2013 5:50 pm

Problem 451

Post by francisco_lolo12 »

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
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 451

Post by hk »

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.
Image
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

Post by Bobail »

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
Image
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 451

Post by TripleM »

Bobail wrote:* 3 -> 100: 1932
This is too low.
Bobail
Posts: 9
Joined: Sat Mar 01, 2014 7:20 am

Re: Problem 451

Post by Bobail »

TripleM wrote:
Bobail wrote:* 3 -> 100: 1932
This is too low.
Well if you have the data, could you provide it please.
Image
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 451

Post by hk »

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.
Image
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

Post by Bobail »

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.
Sorry, you are totally right.
I figured out my problem.
Image
Post Reply