Problem 258

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.
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Problem 258

Post by zwuupeape »

Hey. Can anyone please confirm my result?

I use the same parameters (modulo 20092010, find gk for k = 10 ^ 18), except:

gk = 1 if 0 <= k <= 10

gk = g(k-10) + g(k-9) for k > 10

I get 11649166.

For modulo 260, find gk for k = 10 ^ 16, gk = 1 if 0 <= k <= 30 else gk = g(k-30) + g(k-29), I get 145.

Correct ??
bladewang
Posts: 1
Joined: Sun Oct 04, 2009 7:50 pm

Re: Problem 258 confirmation

Post by bladewang »

I found g(k) == 2(k/2000), if k is a multiple of 2000
and
g(1018) == 2(5*10^14)
so, the answer is same to
2(5*10^14) mod 20092010


It's my code in Python:

Code: Select all

n = 20092010
print (((2**10000%n)**100000%n)**100000%n)**5%n
the result is 8340206

it's wrong ……
WHY ???

:(
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 258 confirmation

Post by zwuupeape »

This is incorrect. It is only true for k < 2000*2000.

Also, you might consider using Python's built-in modular exponentiation, you don't have to raise the number to the power and then take the modulo.
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 258 confirmation

Post by quilan »

zwuupeape wrote:Also, you might consider using Python's built-in modular exponentiation, you don't have to raise the number to the power and then take the modulo.
Yupyup... pow(a,b,m) is awesome. Learn it, live it, love it.
ex ~100%'er... until the gf came along.
Image
User avatar
Jochen_P
Posts: 55
Joined: Mon Oct 05, 2009 10:47 am
Location: Stuttgart, Germany

Re: Problem 258 confirmation

Post by Jochen_P »

Yeah, this will print the wrong result in no time :?

Code: Select all

n = 20092010
print pow(pow(pow(pow(2,10000,n),100000,n),100000,n),5,n)
this one too:

Code: Select all

print  pow(2,10**18/2000, 20092010)
Can Anyone confirm 22189656 for k = 1010 ?
Last edited by Jochen_P on Thu Oct 08, 2009 3:14 pm, edited 1 time in total.
Image
harryh
Posts: 2091
Joined: Tue Aug 22, 2006 9:33 pm
Location: Thessaloniki, Greece

Re: Problem 258 confirmation

Post by harryh »

No, that's not correct (for k=1010).
User avatar
Jochen_P
Posts: 55
Joined: Mon Oct 05, 2009 10:47 am
Location: Stuttgart, Germany

Re: Problem 258 confirmation

Post by Jochen_P »

dang!

thanx :(

[edit] removed other result as it was implausible ?
Last edited by Jochen_P on Thu Oct 08, 2009 3:48 pm, edited 1 time in total.
Image
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 258 confirmation

Post by zwuupeape »

No, this is not true.
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 258 confirmation

Post by quilan »

Jochen_P wrote:Can Anyone confirm 22189656 for k = 1010 ?
You've got some wrong approaches here, but it strikes me as somewhat silly such that 22189656 > 20092010. Your end result is greater than your modulus?
ex ~100%'er... until the gf came along.
Image
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 258 confirmation

Post by quilan »

So, I solved the problem and I don't want to pollute the board for it by asking for help, but could some kindly soul PM me about how in the heck the method the majority of people used works? I must have completely missed that entire section in my lin-alg classes.

Edit: Got the idea behind the main idea thanks to zwuupeape but still confused about the identity named in the first post.

Edit2: Got it now. Thanks guys, you rock!
Last edited by quilan on Fri Oct 09, 2009 1:53 pm, edited 1 time in total.
ex ~100%'er... until the gf came along.
Image
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 258 confirmation

Post by daniel.is.fischer »

quilan wrote:Edit: Got the idea behind the main idea thanks to zwuupeape but still confused about the identity named in the first post.
Explanation sent, hope that clarifies it.
Il faut respecter la montagne -- c'est pourquoi les gypa&egrave;tes sont l&agrave;.
User avatar
Jochen_P
Posts: 55
Joined: Mon Oct 05, 2009 10:47 am
Location: Stuttgart, Germany

Re: Problem 258 confirmation

Post by Jochen_P »

quilan wrote:
Jochen_P wrote:Can Anyone confirm 22189656 for k = 1010 ?
You've got some wrong approaches here, but it strikes me as somewhat silly such that 22189656 > 20092010. Your end result is greater than your modulus?
Um, yeah, that was a silly mistake in the generator, which impelemented the modulus calc in each step but returned twice the modulus ... didn't even realize the result was greater than the modulus :lol:

I stopped working on this problem completely and deleted my efforts so far. Will return to it when I am less silly :D
Image
viv_ban
Posts: 23
Joined: Mon May 26, 2008 3:09 pm

Re: Problem 258

Post by viv_ban »

Can somebody please confirm my result. For
gk = 1 for k = 0 to 14
gk = (gk-14+ gk-15) mod 10^6 for k>= 15

I got g10^18 = 336460
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 258

Post by zwuupeape »

You mean gk = 1 for 0 <= k <= 15, then this is correct.
viv_ban
Posts: 23
Joined: Mon May 26, 2008 3:09 pm

Re: Problem 258

Post by viv_ban »

Thanks zwuupeape.
Is it possible to solve this question in less than 1 min?
I need to perform around 70*20003 operations and I don't think python can perform this many operations with in 1 min. Even after optimization I can reduce total operations to 70*20002.8 which again is not enough to solve the problem in1 min.
Is there exist a better algorithm? If so what kind of order should I be looking for?
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 258

Post by hk »

There exists an O(n2) method.
Image
War ruins the life and health of untold numbers of innocent children.
ThomasH
Posts: 117
Joined: Sun Mar 26, 2006 8:41 am
Location: Berlin, Germany

Re: Problem 258

Post by ThomasH »

I do have the same problem that quilan had: I solved the problem (in very LONG runtime) and gained access to the forum, but I have no idea, why the method i.e. of the first post is working. Could some kindly soul PM me some hints for further reading?
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 258

Post by quilan »

ThomasH wrote:I do have the same problem that quilan had: I solved the problem (in very LONG runtime) and gained access to the forum, but I have no idea, why the method i.e. of the first post is working. Could some kindly soul PM me some hints for further reading?
I'll send some info once I get into work this morning...
ex ~100%'er... until the gf came along.
Image
ThomasH
Posts: 117
Joined: Sun Mar 26, 2006 8:41 am
Location: Berlin, Germany

Re: Problem 258

Post by ThomasH »

quilan, thank you very much for your quick response - and a warm thank you, too, to daniel.is.fischer und zwuupeape, who were quoted by quilan.
OskarS
Posts: 6
Joined: Tue Nov 01, 2011 11:17 pm

Re: Problem 258

Post by OskarS »

Can I just ask a quick question:

In order to solve this problem, do you at any point need to deal with complex numbers? Because the way I'm doing it, you have to, but I'm starting to think that I've might have gone down the wrong alley here.

If anyone could either reply or PM me with the answer, I'd be mighty grateful. Just a yes or no needed (though I wouldn't turn down more help, obviously :). Thanks!
Post Reply