408 - Uniform Generator

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Use existing thread.
AcmNightivy
New poster
Posts: 36
Joined: Tue Dec 04, 2007 10:20 am

Post by AcmNightivy »

Could someone help to find my mistake..i get puzzled..Thanks..And why
gcd (step, mod) == 1 is a Good Choice(found in other thread)..

Code: Select all

Remove After Getting AC
Last edited by AcmNightivy on Sun Feb 10, 2008 8:41 am, edited 1 time in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

After each output test set, your program should print exactly one blank line.
AcmNightivy wrote:why
gcd (step, mod) == 1 is a Good Choice(found in other thread)..
That's elementary number theory. Let s=STEP, m=MOD, g=gcd(s,m), the starting seed be x[0], the k-th number of the generated sequence be x[k]: x[k] = (x[0] + s*k) mod m.
Period length is the smallest k>0, such that x[0] = x[k]. Now let's plug formula for x[k] into this equation: x[0] = (x[0] + s*k) mod m. For this equation to hold, m must exactly divide s*k (i.e s*k = 0 mod m).
m divides s*k => (m/g) divides (s/g)*k => k is a multiple of m/g (since m/g and s/g are relatively prime). So the cycle length is m/g, and only when g=1 you get the full cycle.
AcmNightivy
New poster
Posts: 36
Joined: Tue Dec 04, 2007 10:20 am

Post by AcmNightivy »

mf~Thank you very much``Though i can't understand the theory clearly..And i know how poor my math is..Thanks``keep hard working~
Post Reply

Return to “Volume 4 (400-499)”