408 - Uniform Generator
Moderator: Board moderators
-
- New poster
- Posts: 36
- Joined: Tue Dec 04, 2007 10:20 am
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)..
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.
After each output test set, your program should print exactly one blank line.
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.AcmNightivy wrote:why
gcd (step, mod) == 1 is a Good Choice(found in other thread)..
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.
-
- New poster
- Posts: 36
- Joined: Tue Dec 04, 2007 10:20 am