Problem 123

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
jotd
Posts: 4
Joined: Wed Feb 16, 2011 5:26 pm

Problem 123

Post by jotd »

Hi,

This seems pretty straightforward, and I can verify the value given by the problem for 10**9 (7037) in less than a second.

However, my answer to the question for 10**10 (obtained in a second too) is wrong, whereas I use exactly the same computation. Anyone confirms this? Is there a problem in the value of the expected solution?

thanks
User avatar
hk
Administrator
Posts: 12831
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 123

Post by hk »

No.
Image
War ruins the life and health of untold numbers of innocent children.
dgriff
Posts: 1
Joined: Thu Feb 24, 2011 4:35 am
Location: College Station, Texas

Re: Problem 123

Post by dgriff »

In the problem, Pn is the nth prime, so P1 = 2
Your program probably says that P0 = 2

At least that's what my problem was. The problem isn't worded in the most programmer-friendly way.
Image
jotd
Posts: 4
Joined: Wed Feb 16, 2011 5:26 pm

Re: Problem 123

Post by jotd »

you are right! but with 10**9 I get the 7037 something result. So the problem wording is wrong BTW
And adding 1 to my result still is not accepted

Adding 2 works :)

thanks
User avatar
GenePeer
Posts: 112
Joined: Sat Apr 03, 2010 1:14 pm
Contact:

Re: Problem 123

Post by GenePeer »

jotd wrote:you are right! but with 10**9 I get the 7037 something result. So the problem wording is wrong BTW
And adding 1 to my result still is not accepted

Adding 2 works :)

thanks
I think the problem is your program. Maybe it's exiting the loop before updating the value of n. Since n is always odd, the "margin of error" is 2 instead of the usual 1. My program gave the right answer without modifications.
Image
rblackadar
Posts: 4
Joined: Wed May 29, 2013 5:09 pm

Re: Problem 123

Post by rblackadar »

GenePeer wrote:
jotd wrote:you are right! but with 10**9 I get the 7037 something result. So the problem wording is wrong BTW
And adding 1 to my result still is not accepted

Adding 2 works :)

thanks
I think the problem is your program. Maybe it's exiting the loop before updating the value of n. Since n is always odd, the "margin of error" is 2 instead of the usual 1. My program gave the right answer without modifications.
The more likely explanation is that, because of the off-by-one index, he used the correct exponent n but the incorrect prime pn+1 in the equation. That mixed equation happens to give a "good" result for 10**9, but only by accident. By the way, a careful reading of the problem makes the indexing unambiguous.
User avatar
Oliver1978
Posts: 166
Joined: Sat Nov 22, 2014 9:13 pm
Location: Erfurt, Germany

Re: Problem 123

Post by Oliver1978 »

So, to straighten things out... if n=1 then p_n=2, if n=2 then p_n=3 et cetera and finally if n=7037 then p_n=71059.
Right?
49.157.5694.1125
User avatar
dawghaus4
Posts: 56
Joined: Fri Nov 29, 2013 2:22 am

Re: Problem 123

Post by dawghaus4 »

leghorn wrote:So, to straighten things out... if n=1 then p_n=2, if n=2 then p_n=3 et cetera and finally if n=7037 then p_n=71059.
Right?
Since p_n is your own notation, it might be of help, if you define its meaning.

It appears that p_n means the nth prime and the 1st prime is 2, the 2nd prime is 3 and the 7037th prime is 71059.

Tom
User avatar
Oliver1978
Posts: 166
Joined: Sat Nov 22, 2014 9:13 pm
Location: Erfurt, Germany

Re: Problem 123

Post by Oliver1978 »

Thanks, dawg. That's what I meant, like in the problem's description: p_n denotes the nth prime.

[edit]

Could anybody check out n = 6544 (pn = 65539)? Using the formula ((pn-1)^n + (pn+1)^n) mod pn^2 gives a remainder of 3,780,539,272. Using the test case I never get to 7037 :(

[another edit]

Could it be that this is overflowing on 64 bit already?
49.157.5694.1125
User avatar
Oliver1978
Posts: 166
Joined: Sat Nov 22, 2014 9:13 pm
Location: Erfurt, Germany

Re: Problem 123

Post by Oliver1978 »

It does overflow. Solved anyway.
49.157.5694.1125
kkm000
Posts: 3
Joined: Mon Oct 18, 2021 12:16 am

Re: Problem 123

Post by kkm000 »

original message
Expand
Just out of curiosity, what is the first prime? 1? This convention has been extremely rarely used in 20-21cc.
Sorry. The first prime is 2. It's just me. I'm an idiot tonight. 🤪
Post Reply