CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » August 2009 (Contest VI) » Magic sequence

Magic sequence

Problem code: F5

  • All Submissions

All submissions for this problem are available.

Johnny has invented a magic sequence. Each element of the sequence is defined by the same recursive definition - take some linear combination of previous elements (whose coefficients are fixed) and add to them the n-th powers of some integers. Formally: Xn = Xn-1*a1 + ... + Xn-i*ai + b1*d1n + ... + bj*djn, for some integer constants p,q,a1,...,ap,b1,..., bq,d1,..., dq. Of course, as the values can quickly grow, he computed them modulo a fixed value: 106. He wrote many consecutive values of the sequence, but then he lost most of his work. All he has now, is 10 consecutive values taken from somewhere in the sequence (he doesn't know at what n they begin), and the recursive rule. And he would like to recover the sequence, or at the very least, to be able to write the next 10 values taken from the sequence.

Input

First, two integers, 0 p 4, 0 q 4. Then come the descriptions of the coefficients, -100 a1,...,ap,b1,..., bq,d1,..., dq 100. Then, the following 10 integers are Xn,Xn+1,...,Xn+9 for some unknown n.

Output

Output 10 integers - Xn+10,Xn+11,...,Xn+19

Example

Input:
1 1
1
1
1
11 12 13 14 15 16 17 18 19 20

Output:

21 22 23 24 25 26 27 28 29 30

Explanation:

xn=xn-1+1

Input:

1 1
1
1
2
1 3 7 15 31 63 127 255 511 1023
Output:
2047 4095 8191 16383 32767 65535 131071 262143 524287 48575
Explanation:
xn=xn-1+2n=...=2n+2n-1+...+1=2n+1-1

Input:

2 0
1 1
1 1 2 3 5 8 13 21 34 55
Output:
89 144 233 377 610 987 1597 2584 4181 6765
Explanation:

xn=Fib(n) is the n-th Fibonacci number

Input:

2 1
2 -1
2
1
0 1 4 9 16 25 36 49 64 81
Output:
100 121 144 169 196 225 256 289 324 361
Explanation:
xn=n2

Author: admin
Date Added: 10-07-2009
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

suh_ash2008 @ 2 Aug 2009 01:17 AM

Hi ppl!! I am gettin WA for this problem. I think the algo is right . Can someone verify o/p for this test case:
Input:
2 1
2 -1
2
1
20001 40004 60009 80016 100025 120036 140049 160064 180081 200100
My Output:
220121 240144 260169 280196 300225 320256 340289 360324 380361 400400

jdmetz @ 2 Aug 2009 02:10 AM

You aren't supposed to ask for output verification during the contest: http://blog.codechef.com/2009/07/29/rule-change-for-august-contest-guide...

suh_ash2008 @ 2 Aug 2009 02:17 AM

oh!!i m very sorry!! I did'nt know!!!

bairathirahul @ 2 Aug 2009 02:14 PM

In the Problem.. Does this "ap" represents a subscript p

admin 2 @ 2 Aug 2009 06:47 PM

@rahul Yes

white_king @ 3 Aug 2009 04:34 AM

the recursive definition is applicable for n>?. and is i=p and j=q?

admin 2 @ 3 Aug 2009 05:16 AM

Applicable for all n. Your second question doesn't make much sense.

triplem @ 3 Aug 2009 12:50 PM

It does make sense actually; and yes, i should be replaced by p and j by q in the problem statement. (The ... shows the indices go from 1 to p, you don't need the extra variable i).

ashutoshmehra @ 4 Aug 2009 12:16 AM

I had the same doubt as dot-dot-dot's second question (whether i and j could really be less than p and q, and were some independent unknowns), but I was reluctant to ask lest it should be taken as a violation of the rules. Thanks to Stephen Merriman for the clarification.

susam @ 4 Aug 2009 07:27 AM

What is the result of a negative number modulo 10^6 in this problem? For example, what is the result of -(10^6 1) modulo 10^6? 999999 or -1?

admin 2 @ 4 Aug 2009 06:52 PM

@susam By definition of modular arithmetic, there is only one correct answer to your question.

suvendu @ 6 Aug 2009 11:22 AM

Input is included 10 integers are Xn,Xn 1,...,Xn 9 for some unknown n.
What is the value of n. In example there is no input of n.
2nd example is wrong! It misguides.

skywalker @ 7 Aug 2009 12:48 AM

@admin
i) Can p=q=0, in any test case. In that case sequence is not defined, do we have entries for the 10 elements of the sequence?
ii) are values of a, b, d on "different lines" for non null entries?
I am getting NZEC when trying to read input, when i catch number-format-exception, there is no NZEC.

admin 2 @ 7 Aug 2009 01:02 AM

No p and q both won't equal 0 in a test case. The entries for 'a' will be space separated integers on one line. Same for the entries related to 'b', 'd' and the 10 numbers.

izulin @ 7 Aug 2009 05:24 AM

@Suvendu Samanta

You're wrong. sentence X_n = 2^n should be quantified:
forall_n X_n = 2^n

It's typicall that all free variables in mathematicall sentence are closed by universall quantifier. So this *n* is different *n* that appears in problem statement. Learn about variables range...

skywalker @ 7 Aug 2009 05:53 PM

@admin
There seems conclusive evidence to suggest that the input is not the type you have mentioned.
In particular if i catch number format exception , there is no NZEC
while if i dont catch any exceptions wile reading input that, there is NZEC (runtime error)

Note that my processing logic are all in try catch blocks hence a NZEC cant arise out of that.
the only place which i can possibly get NZEC is while reading input, and which will happen when the input is not the right format as suggested

paingo @ 7 Aug 2009 06:10 PM

By definition of modular arithmetic, all answer have to be positive, correct? and Xn,Xn 1,...,Xn 9 (given) are guaranteed to be positive?

admin 2 @ 7 Aug 2009 06:52 PM

@piyush Try now.

skywalker @ 7 Aug 2009 07:14 PM

@admin
Thanks, it worked now!
I tried 73 submissions, may be I should have contacted you admins earlier :-) . Besides i was wondering why this should be a java specific error, cause correct submissions in C/C and other languages kept on coming.

izulin @ 7 Aug 2009 10:09 PM

@Eric

quick checking inputs... yep, they are guaranteed

abhijit_pande @ 8 Aug 2009 01:07 AM

in the final example, ai is given as 2-1, could some one please explain?

sharad_kumar @ 8 Aug 2009 09:40 AM

@admin : Are there test cases where the 10 input values are also written modulo 10...................as they were larger than 1000000

admin 2 @ 8 Aug 2009 05:59 PM

@sharad All input values are less than 10^6

sharad_kumar @ 8 Aug 2009 08:07 PM

@admin: No I mean, is it possible that according to the recursive definition some of the input values might be having more than 6 digits but after computing modulo only last 6 digits are written........
Like, one of the input values according to actual definition is 12345678 but it is given 345678 in input....
Is it possible ??

admin 2 @ 8 Aug 2009 09:35 PM

Yes.

agarwalankitin @ 9 Aug 2009 12:38 AM

how can same program submission result in "Wrong Answer" which ran for 0.01 seconds and next submission gives "Time Limit Exceeded" ?

admin 2 @ 9 Aug 2009 08:14 PM

If something of that sort has happened, mail us the submission ids.

anoopsabir @ 9 Aug 2009 10:32 PM

How is the first term calculated? What will be Xn-1 in that case? What will be the first term if q=0?

agarwalankitin @ 10 Aug 2009 12:57 AM

@Admin: My submission ids which are 67097 and 67099

admin 2 @ 10 Aug 2009 06:51 PM

You don't need to calculate the 0th term. You will be given 10 numbers and you have to calculate the 'next' 10 integers in the sequence.

admin 2 @ 10 Aug 2009 06:57 PM

@ankit your submissions are not the same. Check line 318. In one submission you are printing one value and in the other submission you are printing some other value.

anoopsabir @ 10 Aug 2009 07:08 PM

@Admin: what's wrong with my submission id 67774? It worked well in my system.

admin 2 @ 10 Aug 2009 07:19 PM

@anoop Sorry, we cannot look at individual submissions and tell you what is wrong while the contest is going on.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com